mps.lua 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551
  1. #!/usr/bin/env lua
  2. -- mps lua kodlaması
  3. -- IMPORT --
  4. local milispath=os.getenv("MILIS_PATH")
  5. if not milispath then milispath="/usr/milis" end
  6. local talimatname=os.getenv("TALIMATNAME")
  7. if not talimatname then talimatname=milispath.."/".."talimatname" end
  8. local mps_path=os.getenv("MPS_PATH")
  9. if not mps_path then mps_path=milispath.."/".."mps" end
  10. package.cpath = package.cpath .. ";"..mps_path.."/lua/?.so"
  11. package.path = package.path .. ";"..mps_path.."/lua/?.lua"
  12. package.cpath = package.cpath .. ";"..mps_path.."/lua/ext/?.so"
  13. package.path = package.path .. ";"..mps_path.."/lua/ext/?.lua"
  14. package.path = package.path .. ";"..mps_path.."/lang/?.lua"
  15. package.path = package.path .. ";"..mps_path.."/conf/?.lua"
  16. -- local socket = require("socket")
  17. local argparse = require ("argparse")
  18. local lip= require("LIP")
  19. local lfs = require("lfs")
  20. local http = require("socket.http")
  21. -- local tparser= require("tparser")
  22. -- mpsd talimat modülüne aktarılacak todo!!!
  23. local t=require ("talimat")
  24. local util=require ("mps_helper")
  25. local yaz=util.yaz
  26. local _assert=util._assert
  27. local has_value=util.has_value
  28. local find=util.find
  29. local path_exists=util.path_exists
  30. local shell=util.shell
  31. local get_abspath=util.get_abspath
  32. local get_basename=util.get_basename
  33. local get_dirname=util.get_dirname
  34. local get_size=util.get_size
  35. local get_content=util.get_content
  36. local get_dirs=util.get_dirs
  37. local has_line=util.has_line
  38. local tprint=util.tprint
  39. local hash_check=util.hash_check
  40. -- dil tespiti / sonra mps-helper den çağrılabilir.
  41. local _langenv=os.getenv("LANG")
  42. if not _langenv then _langenv="tr_TR" end
  43. local _langvar,_=_langenv:match("(.*)_(.*)")
  44. local messages = require ("lang_".. _langvar)
  45. --------------------------------------------------
  46. -- mps ile ilgili ayarların conf/conf.lua dan yüklenmesi
  47. if not path_exists(mps_path.."/conf/conf.lua") then
  48. shell("cp "..mps_path.."/conf/conf.lua.sablon "..mps_path.."/conf/conf.lua")
  49. messages.default_configs_loaded:yaz(2)
  50. messages.relaunch_mps:yaz(2)
  51. os.exit()
  52. end
  53. local ayar= require ("conf")
  54. -------------------------------------------------------
  55. -- DIZIN OLUŞTURMA - KONTROL --
  56. -- Paketleme dizini, yürürlük dosyasının oluşturulduğu konum
  57. local paketleme_dizin=os.getenv("PAKETLEME_DIZIN")
  58. if not paketleme_dizin then paketleme_dizin=lfs.currentdir() end
  59. -- GLOBAL VARIABLES --
  60. local arsivci="bsdtar"
  61. local params={}
  62. local islem={}
  63. islem.api={}
  64. -- local talimatname="/usr/milis/talimatname"
  65. local kokdizin=""
  66. local sil_onay=false
  67. local paket_arsiv_pattern="([%a%d-_+]+)#([%d%a.]+)-([%d]+)-([%a%d_]+)" -- paket_isim#surum-devir-mimari : abc#1.2.3-1-x86_64
  68. -- paket arşiv format -paket_isim#surum-devir-mimari.mps.lz
  69. local paf="%s#%s-%s-%s.mps.lz"
  70. -- paket gösterim formatı
  71. local pgf="%s#%s-%s"
  72. -- paket depo link formatı - depo_adres/paket_isim#surum-devir-mimari.mps.lz / paf kullan
  73. local plf="%s/%s"
  74. -- GLOBAL İŞLEVLER
  75. -- genel parametre inceleme ve düzenlenmesi
  76. function args_handler()
  77. -- parametrelere dönük özel işler yapılır.
  78. color_check()
  79. rootfs_check()
  80. --mps init kontrolü
  81. if args.ilk then mps_init() end
  82. if args.ilkds then mps_initfs() end
  83. komut_islev={["in"]="indir",der="derle",kur="kur",
  84. sil="sil",gun="guncelle",ara="ara",
  85. sor="sorgu",bil="bilgi",kos="kos"}
  86. if args.command then
  87. islev=komut_islev[args.command]
  88. if islev then
  89. if islem[islev] then
  90. islem[islev]["handler"](args)
  91. else
  92. print("not implemented yet")
  93. end
  94. --islem[args.command]["handler"](args)
  95. else
  96. print("not implemented yet")
  97. end
  98. end
  99. end
  100. -- root yetkili kontrolü
  101. function authorised_check()
  102. if not os.getenv("MPS_NOROOT") then
  103. local me=os.getenv("USER")
  104. if me ~= "root" then
  105. messages.need_root:yaz(0)
  106. end
  107. end
  108. end
  109. -- parametre analiz/ color option check
  110. function color_check()
  111. if args.renk == "0" then util.renkli=false end
  112. if args.renk == "1" then util.renkli=true end
  113. end
  114. -- parametre analiz/ package management root check
  115. function rootfs_check()
  116. if args.kok:sub(-1) ~= "/" then args.kok=args.kok.."/" end
  117. kokdizin=args.kok
  118. -- kok dizin kontrolü yapıldıktan sonra alt dizin kontrolleri
  119. --[[
  120. -- milis dizini yoksa oluşturuyoruz.
  121. if path_exists(milispath) == false then
  122. shell("mkdir -p "..kokdizin..milispath)
  123. end
  124. -- talimat dizini yoksa oluşturuyoruz.
  125. if path_exists(talimatname) == false then
  126. shell("mkdir -p "..kokdizin..talimatname)
  127. end
  128. ]]--
  129. end
  130. function mps_init()
  131. -- mps için gerekli dizinlerin oluşturulması
  132. -- /var/lib/mps/db
  133. local create_tmp=("mkdir -p %s"):format(kokdizin.."tmp")
  134. local create_db=("mkdir -p %s"):format(kokdizin..islem.paket.vt)
  135. local create_logs=("mkdir -p %s%s"):format(kokdizin,islem.paket.logdir)
  136. local create_log_k=("mkdir -p %s%s"):format(kokdizin,islem.kur.logdir)
  137. local create_log_s=("mkdir -p %s%s"):format(kokdizin,islem.sil.logdir)
  138. local create_cache=("mkdir -p %s%s"):format(kokdizin,islem.paket.cachedir)
  139. shell(create_tmp)
  140. shell(create_db)
  141. shell(create_logs)
  142. shell(create_log_k)
  143. shell(create_log_s);
  144. shell(create_cache);
  145. (messages.init_is_ok..kokdizin):yaz()
  146. end
  147. -- mps dosya sistemi ilkleme
  148. function mps_initfs()
  149. -- Milis için gerekli dizinlerin oluşturulması
  150. local initfs_komut=("bash %s/conf/init_rootfs.sh %s"):format(mps_path,kokdizin)
  151. shell(initfs_komut);
  152. --print(initfs_komut);
  153. (messages.initfs_is_ok..kokdizin):yaz()
  154. end
  155. function sleep(n)
  156. -- waits for the passed time, letting the coroutine world spin
  157. local t0 = os.clock()
  158. while os.clock() - t0 <= n do
  159. coroutine.yield()
  160. end
  161. end
  162. -- Diyalog İşlemleri
  163. islem.diyalog={}
  164. function islem.diyalog.onay(mesaj)
  165. local answer="-"
  166. if mesaj == nil then mesaj="?(y/n)" end
  167. repeat
  168. io.write(mesaj)
  169. io.flush()
  170. answer=io.read()
  171. until answer=="y" or answer=="n" or answer=="e" or answer=="h"
  172. if answer=="y" or answer=="e" then return true
  173. else return false end
  174. end
  175. -- MPS İŞLEMLER
  176. -- talimat bul
  177. islem.talimat_bul={
  178. retkey="talimat_bul:",
  179. }
  180. function islem.talimat_bul.job(paket,hepsi)
  181. -- alfanumerik arama yapılır.
  182. -- 2.parametere tip=hepsi gönderilirse bütün arama sonuçları çevirilir.
  183. local komut=('find %s -name "%s#*" | sort -n | head -1'):format(talimatname,paket)
  184. if hepsi=="1" then
  185. komut=('find %s -name "*%s*" -type d | sort -n'):format(talimatname,paket)
  186. end
  187. --print(komut)
  188. ret=shell(komut)
  189. if ret == "" then
  190. return false
  191. else
  192. return ret
  193. end
  194. end
  195. islem.ara={usage="",}
  196. -- talimat bulma işlevi (mps bul talimat_isim)
  197. function islem.ara.handler(input)
  198. local hepsi = input.hepsi
  199. local arlist={}
  200. -- konsoldan girilen paket girdi analiz
  201. if input.arama then
  202. for _,pk in ipairs(input.arama) do table.insert(arlist,pk) end
  203. end
  204. -- arama test işlevi
  205. if input.test then
  206. for _,pk in ipairs(arlist) do print("ar",pk) end
  207. end
  208. for _,arama in ipairs(arlist) do
  209. -- talimat araması ise
  210. if input.talimat then
  211. local ret=islem.talimat_bul.job(arama,hepsi)
  212. if ret then print(ret)
  213. else messages.talimat_not_found:yaz(0)
  214. end
  215. end
  216. -- paket araması ise
  217. if input.dpaket then
  218. print("paket araması hazır değil")
  219. end
  220. -- tanım araması ise
  221. if input.tanim then
  222. print("tanim araması hazır değil")
  223. end
  224. end
  225. end
  226. --
  227. -- Kaynak işlemleri
  228. islem.kaynak={
  229. usage="mps kaynak talimat_ismi",
  230. kontrol=false,
  231. }
  232. -- kaynak talimatın içerdiği kaynakları gösterecek
  233. -- todo!!! bil altına alınacak paketle ilgili kaynakların varlık bilgileri
  234. function islem.kaynak.handler(input)
  235. local liste={}
  236. if #input > 1 then
  237. -- 1 is talimat_bul işlemi
  238. local _islem=input[1]
  239. local girdi=input[2]
  240. local param=input[3]
  241. local dosya = girdi:match("^-%-dosya=(.*)$")
  242. if param and param:match("--kontrol") then islem.kaynak.kontrol=true end
  243. if dosya then
  244. if path_exists(dosya) then
  245. islem.kaynak.liste_dosyadan(dosya)
  246. else
  247. messages.file_not_found:format(dosya):yaz(0)
  248. end
  249. else
  250. -- girdi parametresi talimat olarak değerlendirelecek.
  251. local ret=islem.talimat_bul.job(girdi)
  252. if ret then
  253. -- kaynaklar kontrol edilecekse
  254. if islem.kaynak.kontrol then
  255. islem.kaynak.url_kontrol(islem.kaynak.liste(ret))
  256. -- kontrol yoksa sadece listeleme
  257. else
  258. tprint(islem.kaynak.liste(ret))
  259. end
  260. else
  261. messages.talimat_not_found:yaz(0)
  262. end
  263. end
  264. else
  265. (messages.usage..islem[_islem]["usage"]):yaz();
  266. end
  267. end
  268. -- talimata ait kaynakların listelenme işlevi
  269. function islem.kaynak.liste(talimatd)
  270. assert(path_exists(talimatd),"talimat dizin not found!")
  271. local talimatf=talimatd.."/talimat"
  272. assert(path_exists(talimatf),talimatf.." file not found!")
  273. -- talimat dosyasından alınan kaynaklar bash ile yorumlanıp
  274. -- açık değerlerine çevirlecektir.
  275. local kliste={}
  276. local talimat=t.get(talimatd)
  277. local komut='url=%s && isim=%s && surum=%s && devir=%s && echo '
  278. komut=komut:format(talimat.paket.url,talimat.isim,talimat.surum,talimat.devir)
  279. for _,val in ipairs (t.kaynaklar(talimat)) do
  280. table.insert(kliste,shell(komut..val))
  281. end
  282. return kliste
  283. end
  284. -- dosyadaki talimata ait kaynakların listelenme işlevi
  285. function islem.kaynak.liste_dosyadan(dosya)
  286. local ret=nil
  287. for pk in (get_content(dosya)):gmatch("[^\r\n]+") do
  288. ret=islem.talimat_bul.job(pk)
  289. if ret then
  290. -- kaynaklar kontrol edilecekse
  291. if islem.kaynak.kontrol then
  292. islem.kaynak.url_kontrol(islem.kaynak.liste(ret))
  293. -- kontrol yoksa sadece listeleme
  294. else
  295. tprint(islem.kaynak.liste(ret))
  296. end
  297. else
  298. messages.talimat_not_found:yaz(0)
  299. end
  300. end
  301. end
  302. -- talimata ait kaynakların url aktif kontrolü
  303. function islem.kaynak.url_kontrol(kaynaklar)
  304. local komut="wget -q --spider %s && echo $?"
  305. local ret=""
  306. for _,kaynak in ipairs(kaynaklar) do
  307. if kaynak:match("http") or kaynak:match("https") then
  308. ret=shell(komut:format(kaynak))
  309. if ret == "0" then
  310. print(kaynak, "OK")
  311. else
  312. print(kaynak, "NOT")
  313. end
  314. else
  315. print(kaynak, "PASS")
  316. end
  317. end
  318. end
  319. -------
  320. ---------- Gerekler İşlemler ----------
  321. islem.gerek={
  322. retkey="gerek:",
  323. usage="mps gerek paket_ismi tip",
  324. -- aktif gerek listesi
  325. liste={},
  326. -- aktif gereklerin eklenme kontrol listesi
  327. list={},
  328. }
  329. function islem.gerek.job(talimatd,tip)
  330. assert(talimatd,"talimatd is nil!")
  331. local talimat=t.get(talimatd)
  332. --todo!!! sonsuz gerek döngüsü engellenecek.
  333. -- gereklerin toplanan listeye eklenmesi
  334. local function ekle(talimatd)
  335. if islem.gerek.list[talimatd] == nil then
  336. islem.gerek.list[talimatd]=talimatd
  337. --print("e",talimatd)
  338. table.insert(islem.gerek.liste,talimatd)
  339. end
  340. end
  341. -- talimatın libgerekler dosyasının analiz edilmesi
  342. local function oto_rdeps(talimatd)
  343. if path_exists(talimatd.."/"..islem.shlib.dosya) then
  344. local sh_tal=""
  345. local shlibs=get_content(talimatd.."/"..islem.shlib.dosya)
  346. for sh in shlibs:gmatch("[^\r\n]+") do
  347. sh_tal=islem.shlib.bul(sh,"-t","ilk")
  348. if sh_tal and sh_tal ~= talimatd then
  349. --print("3",sh_tal)
  350. islem.gerek.job(sh_tal,"c")
  351. end
  352. end
  353. end
  354. end
  355. -- alt gereklerin dolaşılması
  356. local function gerek_dolas(dep,talimatd)
  357. local _td=islem.talimat_bul.job(dep)
  358. -- bir önceki paketin kurulabilir değeri iptal ediliyor
  359. local kurulabilir=false
  360. if _td then
  361. -- bir paketin depodaki bulunma durumuna göre
  362. -- derleme ve çalışma gereklerinin araştırılması yapılmaktadır.
  363. -- çalışma gerek araşırılmasında da aynı durum kontrol edilmektedir.
  364. -- todo!!! alt işleve alınacak alttaki operasyon
  365. tsd=get_basename(_td)
  366. for _,b in ipairs(islem.paket.pkvt_bilgi(dep)) do
  367. pksd=pgf:format(b.isim,b.surum,b.devir)
  368. if tsd == pksd then
  369. kurulabilir=b
  370. break
  371. end
  372. end
  373. if kurulabilir then
  374. tip="c"
  375. else
  376. tip="d"
  377. end
  378. islem.gerek.job(_td,tip)
  379. else
  380. (messages.talimat_not_found..talimatd..":"..dep):yaz(0)
  381. end
  382. end
  383. -- ikincil dolasma engelleme
  384. if islem.gerek.list[talimatd] == nil then
  385. -- talimatdaki gerek kısmının analiz edilmesi - ana iskelet
  386. if talimat["gerek"] then
  387. local rdeps=talimat["gerek"]["calisma"]
  388. local bdeps=talimat["gerek"]["derleme"]
  389. local kurulabilir=false
  390. if tip == "d" and bdeps then
  391. for dep in bdeps:gmatch('([^%s]+)') do
  392. gerek_dolas(dep,talimatd)
  393. end
  394. elseif rdeps then
  395. for dep in rdeps:gmatch('([^%s]+)') do
  396. gerek_dolas(dep,talimatd)
  397. end
  398. end
  399. oto_rdeps(talimatd)
  400. ekle(talimatd)
  401. else
  402. oto_rdeps(talimatd)
  403. ekle(talimatd)
  404. end
  405. end
  406. end
  407. islem.tgerek={comment=messages.comment_mps_rev_dep,}
  408. function islem.tgerek.job(paket, tip)
  409. print("Ters gerekler:");
  410. print("-------------------")
  411. local local_paketler={}
  412. if tip == "d" then
  413. -- derleme
  414. local komut="grep -r ' *derleme *= *' %s | grep ' %s$\\| %s \\|=%s$\\|=%s ' | cut -d':' -f1 | xargs -I {} dirname {} | xargs -I {} basename {} | cut -d'#' -f1"
  415. ret=shell(komut:format(talimatname,paket,paket,paket,paket))
  416. for line in ret:gmatch("[^\r\n]+") do
  417. table.insert(local_paketler, line)
  418. end
  419. else
  420. -- calistirma
  421. -- talimat dosyasindan
  422. local komut="grep -r ' *calisma *= *' %s | grep ' %s$\\| %s \\|=%s$\\|=%s ' | cut -d':' -f1 | xargs -I {} dirname {} | xargs -I {} basename {} | cut -d'#' -f1"
  423. ret=shell(komut:format(talimatname,paket,paket,paket,paket))
  424. for line in ret:gmatch("[^\r\n]+") do
  425. table.insert(local_paketler, line)
  426. end
  427. -- libgerek dosyasindan
  428. local talimatd=islem.talimat_bul.job(paket)
  429. if path_exists(talimatd.."/".."pktlibler") then
  430. local sh_tal=""
  431. local shlibs=get_content(talimatd.."/".."pktlibler")
  432. for sh in shlibs:gmatch("[^\r\n]+") do
  433. local komut=("grep -ril --include=libgerekler '%s$' %s | xargs -I {} dirname {} | xargs -I {} basename {} | cut -d'#' -f1"):format(sh,talimatname)
  434. sh_tal=shell(komut)
  435. for line in sh_tal:gmatch("[^\r\n]+") do
  436. if not has_value(local_paketler, line) then
  437. table.insert(local_paketler, line)
  438. end
  439. end
  440. end
  441. end
  442. end
  443. tprint(local_paketler)
  444. print("-------------------")
  445. end
  446. ------------------------------------------
  447. -- Derle işlemi
  448. islem.derle={
  449. retkey="derle:",
  450. usage="mps derle paket_ismi",
  451. }
  452. function islem.derle.handler(input)
  453. local derlist={}
  454. local hedefkur=false
  455. if input.kur then
  456. hedefkur=true
  457. end
  458. local function pk_analiz(talimat)
  459. local _durum=islem.talimat_bul.job(talimat)
  460. if _durum then
  461. table.insert(derlist,talimat)
  462. else
  463. (messages.talimat_not_found..talimat):yaz(0)
  464. end
  465. end
  466. -- konsoldan girilen paket girdi analiz
  467. if input.paket then
  468. for _,pk in ipairs(input.paket) do pk_analiz(pk) end
  469. end
  470. -- dosya parametresi içerik girdi analiz
  471. if input.dosya then
  472. if path_exists(input.dosya) then
  473. for pk in (get_content(input.dosya)):gmatch("[^\r\n]+") do
  474. pk_analiz(pk)
  475. end
  476. else
  477. messages.file_not_found:format(dosya):yaz(0)
  478. end
  479. end
  480. -- derle test işlevi
  481. if input.test then
  482. for _,pk in ipairs(derlist) do print("d",pk) end
  483. else
  484. -- test yoksa derle işlemi yapacak
  485. for _,dpaket in ipairs(derlist) do
  486. if input.tek then
  487. islem.derle.tek(dpaket)
  488. else
  489. islem.derle.job(dpaket,hedefkur)
  490. end
  491. end
  492. end
  493. end
  494. function islem.derle.job(paket,hedefkur)
  495. --talimatın konumu bulunarak gelecek handler den
  496. local ret=islem.talimat_bul.job(paket)
  497. local retq=nil
  498. -- pk = paket isim
  499. -- pksd = ağdaki paket sürüm-devir
  500. -- tsd = talimat sürüm-devir
  501. -- ksd = kurulu sürüm-devir
  502. local pk,pksd,tsd,ksd=""
  503. local derlet=false
  504. local kurulabilir=false
  505. local eski_sil=false
  506. -- derleme işlemi
  507. -- todo!!! mpsd.lua lib olarak çağrılacak sonra, şu an shell
  508. -- 1. Derleme gerekleri bul.
  509. islem.gerek.job(ret,"d")
  510. --tprint(islem.gerek.liste)
  511. -- 2. Döngüde gerekler incelenir.
  512. for _,talimatd in ipairs(islem.gerek.liste) do
  513. -- her gerekte derletme ve kurulma durumları sıfırlanacak.
  514. derlet=false
  515. kurulabilir=false
  516. -- 2.1 kurulu kontrol
  517. tsd=get_basename(talimatd)
  518. pk,_=tsd:match("([%a%d-_+]+)#+")
  519. -- kurulu kontrol , link dizin dönüşü ile
  520. ksd=islem.paket.kurulu_kontrol(pk)
  521. -- 2.1.1 paket kurulu ise sürüm-devir uyum kontrolü yapılır.
  522. if ksd then
  523. -- ksd kurulu yol, sadece talimat isim formatı
  524. ksd=get_basename(ksd)
  525. if tsd ~= ksd then
  526. print("kurulu sürümd ile derlenmesi gereken sürümd farklı-derlenecek!")
  527. -- paket kurulu sd uyumsuzluğu var
  528. -- paketi sildir(onaylı?) ve derlet
  529. -- önemli !!!-eski paketi derleme başarılı olursa sildir.
  530. derlet=true
  531. eski_sil=true
  532. else
  533. messages.package_already_installed_and_uptodate:format(pk):yaz(2)
  534. goto continue
  535. end
  536. -- 2.1.2 paket kurulu değilse ağdan indirilip kurulacak
  537. end
  538. -- ağdaki paketin surumdeviri incelenecek
  539. -- tsd ile pksd karşılaştır
  540. -- paket.vt lerdeki paket sürüm-devir bilgileri taranacak.
  541. -- tsd e eşleşen bulunursa eşleşen! indirilecek yoksa derletilecek.
  542. -- pakete ait depolarda bulduğu pkvt bilgisini getirecek.
  543. for _,b in ipairs(islem.paket.pkvt_bilgi(pk)) do
  544. pksd=pgf:format(b.isim,b.surum,b.devir)
  545. if tsd == pksd then
  546. print(pk,b.depo,"bulundu.")
  547. kurulabilir=b
  548. break
  549. end
  550. end
  551. -- kurulabilir nesnesine ağdaki paket bilgisi atılacak.
  552. if kurulabilir then
  553. -- paket önbellekte varsa
  554. -- shasum kontrolü yapılıp yerelden kurulma yapılacak.
  555. -- ağdan indirmeden önce önbellekte kontrol edecek
  556. local _pkt=paf:format(pk,kurulabilir.surum,kurulabilir.devir,kurulabilir.mimari)
  557. local kur_onay=false
  558. local _indir=false
  559. local _pktyol=kokdizin..islem.paket.cachedir.."/".._pkt
  560. if path_exists(_pktyol) then
  561. print("hash kontrol")
  562. if hash_check(_pktyol,kurulabilir.shasum) == false then
  563. --delete file
  564. shell("rm -f ".._pktyol)
  565. end
  566. _indir=true
  567. else
  568. -- önbellekte yoksa veya hash uyumsuzsa indirilecek
  569. _indir=true
  570. end
  571. if _indir then
  572. print(_pkt,"indirilecek")
  573. islem.indir.handler({paket={pk}})
  574. end
  575. -- indirilememe veya herhangi bir nedenden paketin önbellekte hazır olmaması durumu
  576. if not path_exists(_pktyol) then
  577. messages.package_not_found:format(_pktyol):yaz(0)
  578. else
  579. -- ağdan inen veya önbellekteki paket kurulabilir
  580. -- ayrıca eski paket kurulu ise kaldırılacak.
  581. if eski_sil then
  582. print("eski sürüm paket tespit edildi, kaldırılacak")
  583. islem.sil.handler({paket={pk}})
  584. end
  585. print(_pktyol,"kurulacak")
  586. islem.kur.yerelden(_pktyol)
  587. -- paket kurulduysa eğer eski sürümden dolayı onay verilen derletme
  588. -- işlemi iptal edilecektir.
  589. derlet=false
  590. end
  591. else
  592. derlet=true
  593. end
  594. -- 2.2 derleme
  595. if derlet then
  596. -- aktif oluşan paket arşiv
  597. local mimari=shell("uname -m")
  598. local pkarsiv=tsd.."-"..mimari..".mps.lz"
  599. -- hedef paket isimleri
  600. local hpksd=get_basename(ret)
  601. local hdarsiv=hpksd.."-"..mimari..".mps.lz"
  602. -- 2.2.1 talimat derle
  603. print(talimatd,"tl derlenecek")
  604. -- print(ret.." derlenecek")
  605. retq=shell("mpsd.lua "..talimatd)
  606. -- paketleme dizinine geçilir.
  607. lfs.chdir(paketleme_dizin)
  608. assert(path_exists(pk..".yur"),"islem.derle.job : "..pk..".yur not found")
  609. os.execute(("bash ./%s.yur"):format(pk))
  610. -- 2.2.2 üretilen paketi kur
  611. -- hedef üretilmek istenen pakete gelindiğinde
  612. -- bu noktada derleme başarılı olup paket üretildiği
  613. -- kontrol edilerek eski sürüm paket kaldırılır.
  614. if pk == paket then
  615. -- mps derle paket --kur seçeneğine bakılacak.
  616. if hedefkur == true then
  617. -- hedef paket arşivi
  618. if path_exists(paketleme_dizin.."/"..hdarsiv) then
  619. if eski_sil then islem.sil.handler({paket={pk}}) end
  620. print(paket.." hedef paket de kurulacak.")
  621. islem.kur.yerelden(paketleme_dizin.."/"..hdarsiv)
  622. else
  623. messages.package_not_found:format(hdarsiv):yaz(0)
  624. end
  625. end
  626. else
  627. -- altgereklerin oluşan paketleri zorunlu kurulacak
  628. if path_exists(paketleme_dizin.."/"..pkarsiv) then
  629. if eski_sil then islem.sil.handler({paket={pk}}) end
  630. islem.kur.yerelden(paketleme_dizin.."/"..pkarsiv)
  631. else
  632. messages.package_not_found:format(pkarsiv):yaz(0)
  633. end
  634. end
  635. end
  636. ::continue::
  637. -- for bitiş
  638. end
  639. --print(paket.." derleme bitti")
  640. end
  641. function islem.derle.tek(paket)
  642. --talimat konum bul
  643. ret=islem.talimat_bul.job(paket)
  644. if ret then
  645. print(ret.." derlenecek")
  646. retq=shell("mpsd.lua "..ret)
  647. --print (retq)
  648. -- paketleme dizinine geçilir.
  649. lfs.chdir(paketleme_dizin)
  650. -- os.exit()
  651. assert(path_exists(paket..".yur"),"islem.derle.job : talimat.yur not found")
  652. os.execute(("bash ./%s.yur"):format(paket))
  653. else
  654. (messages.talimat_not_found..paket):yaz(0)
  655. end
  656. end
  657. ------------------------------
  658. -- Paket Arşiv işlemleri
  659. islem.arsiv={
  660. retkey="arşiv:",
  661. }
  662. -- Milis paketi ön kontrolleri
  663. function islem.arsiv.kontrol(paket)
  664. -- kullanıcı hedefli de çıktı verilebilinir.
  665. assert(path_exists(paket),"islem.arsiv.kontrol : paket is not found")
  666. assert(paket:match("mps.lz"),"islem.arsiv.kontrol : paket suffix is not mps.lz")
  667. assert(get_size(paket) ~=0,"islem.arsiv.kontrol : paket size equals zero")
  668. local isd = get_basename(paket)
  669. local isim,surum,devir,mimari=isd:match(paket_arsiv_pattern)
  670. if not (isim and surum and devir and mimari) then
  671. print(messages.valid_format..paf:format(isim,surum,devir,mimari));
  672. (messages.package_name_format_not_valid..isd):yaz(0)
  673. end
  674. -- bir kontrol de tar ile içeriden paket bilgi dosyası çekilebilir
  675. -- bu kontrol extract den sonra yapılabilir, aynı işlemi tekrarlamamak için
  676. --("arşiv_kontrol:\tOK"):yaz();
  677. islem.debug.yaz(messages.package_archive_check_ok)
  678. return isim,surum,devir
  679. end
  680. function islem.arsiv.tempdir(paket)
  681. -- paket arşivinin açılacağı temp dizin ayarlanması
  682. assert(paket,"islem.arsiv.cikar : paket is nil")
  683. local tempdir=kokdizin.."tmp/"..(get_basename(paket))..".tmpdir"
  684. assert(tempdir ~= "/tmp","islem.arsiv.cikar : tempdir must not be /tmp")
  685. assert(tempdir ~= "/","islem.arsiv.cikar : tempdir must not be /")
  686. -- paketin açılacağı tempdir oluşturma
  687. local tempdir_komut=("rm -rf %s && mkdir -p %s"):format(tempdir,tempdir)
  688. shell(tempdir_komut)
  689. return tempdir.."/"
  690. end
  691. -- Milis paketi dışarı çıkarma/extract
  692. function islem.arsiv.cikar(paket)
  693. -- ön kontrollerin yapıldığı varsayılıyor/handler func ile ?
  694. -- extract komutu
  695. local tempdir=islem.arsiv.tempdir(paket)
  696. assert(tempdir,"islem.arsiv.cikar : tempdir is nil")
  697. -- paketin açılması
  698. local komut=("%s xf %s -C %s"):format(arsivci,paket,tempdir)
  699. ret=shell(komut);
  700. -- arşiv çıkarılması test edilecek!!!
  701. local log=messages.package_archive_extract_ok;
  702. islem.debug.yaz(log);
  703. islem.kur.logger:write(log.."\n")
  704. return tempdir
  705. end
  706. ------------------------------
  707. -- Shared Libs(Paylaşılan kütüphaneler) işlemleri
  708. islem.shlib={
  709. retkey="shlib:",
  710. dosya="libgerekler",
  711. }
  712. -- -libbul
  713. islem.api.libbul={
  714. usage="",
  715. comment="Bir .so dosyasını içeren paket veya talimatı bulur."
  716. }
  717. islem.api.libbul.job=function (params)
  718. local shlib=nil
  719. local param=params[2]
  720. if param == "-t" then
  721. shlib=params[3]
  722. else
  723. shlib=param
  724. end
  725. if shlib then
  726. print(islem.shlib.bul(shlib,param,"hepsi"))
  727. else
  728. messages.args_at_least_one:yaz(0)
  729. end
  730. end
  731. function islem.shlib.kontrol(tempdir)
  732. -- shlib kontrolü / altına kurulumlarda yapılabilir
  733. -- farklı bir kök altına kurulumlar için
  734. -- shlib dosya arama yoluyla olabilir.
  735. local log=""
  736. local ldconfig_bin="/usr/bin/ldconfig"
  737. if kokdizin == "/" and path_exists(ldconfig_bin) then
  738. assert(tempdir,"islem.shlib.kontrol : tempdir is nil")
  739. local shlibdos=tempdir..islem.paket.metadir..islem.shlib.dosya
  740. local pklibdos=tempdir..islem.paket.metadir..islem.paket.pktlib_dosya
  741. local iclib_kontrol=false
  742. if path_exists(pklibdos) then iclib_kontrol=true end
  743. if path_exists(shlibdos) and get_size(shlibdos) > 0 then
  744. local shlibs=get_content(shlibdos)
  745. for sh in shlibs:gmatch("[^\r\n]+") do
  746. if iclib_kontrol and has_line(pklibdos,sh) then
  747. log="shlib.kontrol\tOK";
  748. elseif not islem.shlib.exist(sh) then
  749. (messages.shlib_not_exits..sh):yaz(3)
  750. end
  751. end
  752. end
  753. log="shlib.kontrol\tOK";
  754. islem.debug.yaz(log);
  755. islem.kur.logger:write(log.."\n")
  756. else
  757. log="shlib.kontrol\tPASS";
  758. islem.debug.yaz(log);
  759. islem.kur.logger:write(log.."\n")
  760. end
  761. end
  762. function islem.shlib.exist(shlib)
  763. assert(shlib,"islem.shlib.exist : shlib is nil")
  764. local komut="ldconfig -p | grep "..shlib.." > /dev/null;echo $?"
  765. --local komut='ldconfig -p | grep '..shlib..' | awk \'{split($0,a,"=> "); print a[2]}\' | xargs -r ls > /dev/null 2>&1;echo $?'
  766. ret=shell(komut)
  767. assert(ret~="","islem.shlib.exist : ret is empty")
  768. --print (ret,komut)
  769. if ret == "0" then return true end
  770. return false
  771. end
  772. function islem.shlib.bul(shlib,param,show_opt)
  773. assert(shlib,"islem.shlib.bul : shlib is nil")
  774. local opt=" | head -n1"
  775. if show_opt=="hepsi" then
  776. opt=""
  777. end
  778. if param=="-t" then
  779. local komut=("grep -r -i -l --include=\\%s '%s$' %s | xargs -I {} dirname {} %s "):format(islem.paket.pktlib_dosya,shlib,talimatname,opt)
  780. ret=shell(komut)
  781. if ret ~= "" then
  782. return ret
  783. end
  784. else
  785. -- todo!!! kurulu paketler için yapılacak
  786. return nil
  787. end
  788. end
  789. ------------------------------
  790. -- İçbilgi(mtree) işlemleri
  791. -- içbilgi içindeki dosyaları yazdırmak
  792. islem.api.ib={
  793. usage="",
  794. comment="",
  795. }
  796. islem.api.ib.job=function (params)
  797. local paket=params[2]
  798. local ibdos=islem.icbilgi.dosyalar(kokdizin..islem.paket.vt..paket.."/")
  799. if ibdos then
  800. for _,dos in ipairs(ibdos) do
  801. print(dos)
  802. end
  803. end
  804. end
  805. islem.icbilgi={
  806. retkey="icbilgi:",
  807. dosya=".icbilgi",
  808. }
  809. function islem.icbilgi.dosyalar(tempdir)
  810. assert(tempdir,"islem.icbilgi.dosyalar : tempdir is nil")
  811. -- bu hata kullanıcı tanımlı olabilir.
  812. local icdosya=tempdir..islem.icbilgi.dosya
  813. assert(path_exists(icdosya),"islem.kur.dosya_kontrol : icbilgi is not found")
  814. assert(get_size(icdosya) > 0,"islem.kur.dosya_kontrol : icbilgi size equals zero")
  815. local tmpdos=shell("mktemp")
  816. local komut="zgrep -i './' "..icdosya.."| grep -v 'type=dir' | cut -d' ' -f1 > "..tmpdos
  817. shell(komut)
  818. local pdoslar=get_content(tmpdos)
  819. local dosyalar={}
  820. -- .icbilgi içindeki dosyalar döngüde tabloya eklenir.
  821. -- diğer dosyalar elenerek.
  822. for dos in pdoslar:gmatch("[^\r\n]+") do
  823. if dos:match(".ustbilgi") then
  824. elseif dos:match("libgerekler") then
  825. elseif dos:match("pktlibler") then
  826. elseif dos:match(".meta") then
  827. else
  828. --print(dos:sub(3))
  829. table.insert(dosyalar,dos:sub(3))
  830. end
  831. end
  832. shell("rm "..tmpdos)
  833. return dosyalar
  834. end
  835. -- sha256digest eşitliğinden match edip değer karşılaştırma
  836. function islem.icbilgi.hash_kontrol(dir,dosya)
  837. assert(dir,"islem.icbilgi.hash_kontrol : dir is nil")
  838. local icdosya=dir..islem.icbilgi.dosya
  839. local komut=("zgrep -i '%s ' %s | grep -v 'type=dir' | grep -v 'type=link'"):format(dosya,icdosya)
  840. local ret=shell(komut)
  841. local hash_pattern="sha256digest=(.*)"
  842. local ic_hash=ret:match(hash_pattern)
  843. local komut2=("sha256sum %s"):format(kokdizin..dosya)
  844. local ret2=shell(komut2)
  845. local d_hash=ret2:match("%S+")
  846. if ic_hash == d_hash then
  847. --print(dosya)
  848. --print(ic_hash,d_hash)
  849. return true
  850. end
  851. return false
  852. end
  853. ------------------Paket ve Veritabanı İşlemleri-----------------------
  854. islem.paket={
  855. retkey="paket:",
  856. vt="var/lib/mps/db/",
  857. logdir="var/log/mps/",
  858. --cachedir="tmp",
  859. cachedir="var/cache/mps/depo",
  860. pktlib_dosya="pktlibler",
  861. ustbildos=".ustbilgi",
  862. metadir=".meta/",
  863. }
  864. ------------------Bilgi İşlemleri-----------------------
  865. islem.bilgi={retkey="bilgi:",}
  866. function islem.bilgi.job(talimat)
  867. -- todo!!! bu işlev yeniden değerlendirelecek
  868. -- kurulu paket ve talimatnamedeki talimat özbilgileri ayrılacak
  869. -- parametrelerle ayrılacak...
  870. --talimatnameden bilgileri al.
  871. print(("ADI : %s"):format(talimat.isim))
  872. print(("TANIM : %s"):format(talimat.paket.tanim))
  873. print(("GRUP : %s"):format(talimat.paket.grup))
  874. print(("URL : %s"):format(talimat.paket.url))
  875. print(("PAKETÇİ : %s"):format(talimat.paket.paketci))
  876. -- gecici
  877. --paket.vt'den bilgileri al
  878. local pbs = islem.paket.pkvt_bilgi(talimat.isim)
  879. -- todo!!! nil değer gelmeme kontrol edilecek
  880. --paket.vt dosyasindaki gerekli girdileri al
  881. local pb = pbs[1]
  882. ---[[
  883. if pb == nil then
  884. print(("SÜRÜM : %s"):format(talimat.surum))
  885. print(("DEVİR : %s"):format(talimat.devir))
  886. else
  887. print(("SÜRÜM : %s"):format(pb.surum))
  888. print(("DEVİR : %s"):format(pb.devir))
  889. print(("MİMARİ : %s"):format(pb.mimari))
  890. print(("ARŞİV BOYUT : %s"):format(pb.aboyut))
  891. print(("KURULUM BOYUT : %s"):format(pb.kboyut))
  892. end
  893. print("-----------------------------------------")
  894. end
  895. function islem.bilgi.handler(input)
  896. local blist={}
  897. -- todo!!! farklı bilgi parametreleri olacak
  898. local function pk_analiz(_paket)
  899. local path = islem.talimat_bul.job(_paket)
  900. if path then
  901. --table.insert(blist,path)
  902. blist[_paket]=path
  903. else
  904. messages.package_not_found:format(_paket):yaz(0)
  905. end
  906. end
  907. -- konsoldan girilen paket girdi analiz
  908. if input.paket then
  909. for _,pk in ipairs(input.paket) do pk_analiz(pk) end
  910. end
  911. -- bilgi test işlevi
  912. if input.test then
  913. for pk,td in pairs(blist) do print(pk,td) end
  914. end
  915. for paket,talimatd in pairs(blist) do
  916. if input.gerek == "d" or input.gerek == "c" then
  917. print("-------")
  918. islem.gerek.job(talimatd,input.gerek)
  919. for _,pk in ipairs(islem.gerek.liste) do print(get_basename(pk)) end
  920. elseif input.gerek == "td" or input.gerek == "tc" then
  921. islem.tgerek.job(paket,input.gerek:sub(2))
  922. -- bu api erişimleri tablodan sağlanacak
  923. elseif input.kk then
  924. islem.api.kk.job(paket)
  925. elseif input.kdl then
  926. print(islem.paket.kurulu_icerik(paket))
  927. elseif input.pl then
  928. print(islem.paket.pktlibler(paket,"-t"))
  929. elseif input.lg then
  930. print(islem.paket.libgerekler(paket,"-t"))
  931. elseif input.pkd then
  932. print(islem.paket.kurulum_dogrula(paket))
  933. else
  934. local talimat = t.get(talimatd)
  935. islem.bilgi.job(talimat)
  936. end
  937. end
  938. end
  939. -- -kk kurulu kontrol
  940. islem.api.kk={
  941. usage="",
  942. comment="bir paketin kurulu olma durumunu verir.",
  943. }
  944. islem.api.kk.job=function (pk)
  945. --- todo!!!! değerlere çıktı verilecek.
  946. -- nil : tanımsız
  947. -- true : kurulu
  948. -- false : kurulu değil
  949. if islem.paket.kurulu_kontrol(pk) then
  950. messages.installed:yaz(1)
  951. else
  952. messages.not_installed:yaz(3)
  953. end
  954. end
  955. -- -pkd paket kurulum doğrula
  956. islem.api.pkd={
  957. usage="",
  958. comment="",
  959. }
  960. -----
  961. function islem.paket.pktlibler(paket)
  962. -- kurulu olan bir paketin pktliblerini gösterir.(shlibs)
  963. -- önce kurulu kontrol edilir
  964. assert(paket,"paket param is nil")
  965. local icerik=""
  966. -- talimatnameden bakılması istenirse
  967. local _talimatd=islem.talimat_bul.job(paket)
  968. if _talimatd then
  969. if path_exists(_talimatd.."/"..islem.paket.pktlib_dosya) then
  970. icerik=get_content(_talimatd.."/"..islem.paket.pktlib_dosya)
  971. end
  972. print(icerik)
  973. print("-----------------------------")
  974. else
  975. (messages.talimat_not_found..paket):yaz(0)
  976. end
  977. -- paket kurulu ise onun da pl bilgisi gösterilecek
  978. if islem.paket.kurulu_kontrol(paket) then
  979. local _file=kokdizin..islem.paket.vt..paket.."/"..islem.paket.metadir..islem.paket.pktlib_dosya
  980. assert(path_exists(_file),"file not found "..islem.paket.pktlib_dosya)
  981. icerik=get_content(_file)
  982. print(icerik)
  983. end
  984. end
  985. function islem.paket.libgerekler(paket,param)
  986. -- kurulu olan bir paketin gerek duyduğu libleri gösterir.(needed shlibs)
  987. -- önce kurulu kontrol edilir
  988. assert(paket,"paket param is nil")
  989. local icerik=""
  990. -- talimatnameden bakılması istenirse
  991. local _talimatd=islem.talimat_bul.job(paket)
  992. if _talimatd then
  993. if path_exists(_talimatd.."/"..islem.shlib.dosya) then
  994. icerik=get_content(_talimatd.."/"..islem.shlib.dosya)
  995. end
  996. print(icerik)
  997. print("-----------------------------")
  998. else
  999. (messages.talimat_not_found..paket):yaz(0)
  1000. end
  1001. -- paket kurulu ise onun da lg bilgisi gösterilecek
  1002. if islem.paket.kurulu_kontrol(paket) then
  1003. local _file=kokdizin..islem.paket.vt..paket.."/"..islem.paket.metadir..islem.shlib.dosya
  1004. assert(path_exists(_file),"file not found "..islem.shlib.dosya)
  1005. icerik=get_content(_file)
  1006. print(icerik)
  1007. end
  1008. end
  1009. function islem.paket.pkvt_bilgi(paket)
  1010. -- bir paket hakkında pkvt leri tarayarak bilgi toplar.
  1011. local paketler={}
  1012. local i=0
  1013. -- isim,surum,devir,mimari,aboyut,kboyut,shasum içeriği olacak.
  1014. local fields={"isim","surum","devir","mimari","aboyut","kboyut","shasum","depo"}
  1015. local ret=""
  1016. local komut='find %s -name "paket.vt#%s" -exec grep -i "^%s " {} \\; | sort -n'
  1017. -- islem.paket.cachedir altında paketleri arayacak.
  1018. -- {} /dev/null \; olursa eşleşen dosya ismi de gelir.
  1019. -- en azından paket.vt#1 dosyası bulunmalıdır ki tarama yapılabilsin
  1020. --if path_exists(islem.paket.cachedir.."/paket.vt#1") then
  1021. for sira=1,#ayar.sunucu do
  1022. if path_exists(kokdizin..islem.paket.cachedir.."/paket.vt#"..sira) then
  1023. ret=shell(komut:format(kokdizin..islem.paket.cachedir,sira,paket))
  1024. for satir in ret:gmatch("[^\r\n]+") do
  1025. local _paket={}
  1026. for bilgi in satir:gmatch("%S+") do
  1027. i = i + 1
  1028. _paket[fields[i]]=bilgi
  1029. end
  1030. -- depo bilgisi conf.lua dan alınıp eklenecek.
  1031. _paket.depo=ayar.sunucu[sira]
  1032. table.insert(paketler,_paket)
  1033. i=0
  1034. end
  1035. else
  1036. (sira..". "..messages.paketvt_not_found):yaz(0)
  1037. end
  1038. end
  1039. if #ayar.sunucu == 0 then
  1040. messages.package_server_not_defined:yaz(3)
  1041. end
  1042. return paketler
  1043. end
  1044. function islem.paket.kurulu_kontrol(paket)
  1045. -- bir paketin kurulu olup olmadığını vt e bakarak kontrol eder
  1046. -- /var/lib/mps/DB/paket_ismi dizin kontrol eder
  1047. -- dönüş olarak kurulu değilse nil kurulu ise link dizini döndürür.
  1048. assert(paket,"islem.paket.kurulu_kontrol : paket is nil")
  1049. local ret=""
  1050. local komut='find %s -name "%s#*" -type l'
  1051. if path_exists(kokdizin..islem.paket.vt..paket.."/"..islem.kur.kurulandos) then
  1052. ret=shell(komut:format(kokdizin..islem.paket.vt,paket))
  1053. assert(ret,paket.." link dizini yok!")
  1054. return ret
  1055. end
  1056. return nil
  1057. end
  1058. function islem.paket.kurulu_icerik(paket)
  1059. -- kurulu olan bir paketin kurulum içeriğini gösterir
  1060. -- önce kontrol edilir
  1061. assert(paket,"islem.paket.kurulu_kontrol : paket is nil")
  1062. if islem.paket.kurulu_kontrol(paket) then
  1063. local _kurulan=kokdizin..islem.paket.vt..paket.."/"..islem.kur.kurulandos
  1064. assert(path_exists(_kurulan),"islem.paket.kurulu_icerik : kurulan file not found")
  1065. local icerik=get_content(_kurulan)
  1066. print(icerik)
  1067. -- clear screen
  1068. --io.write("\27[2J")
  1069. else
  1070. messages.package_not_installed:format(paket):yaz(0)
  1071. end
  1072. end
  1073. function islem.paket.kurulum_dogrula(paket)
  1074. -- kurulu olan bir paketin dosyaları incelenerek kurulum doğrulaması yapılır
  1075. -- mevcutluk ve hash kontrolü + izinler ! todo!!!
  1076. assert(paket,"islem.paket.kurulum_dogrula : paket is nil")
  1077. if islem.paket.kurulu_kontrol(paket) then
  1078. -- paket dizin kaydı
  1079. local pdk=kokdizin..islem.paket.vt..paket.."/"
  1080. local dosyalar=islem.icbilgi.dosyalar(pdk)
  1081. for _,dosya in ipairs(dosyalar) do
  1082. -- 1. dosya mevcut kontrolü
  1083. if not path_exists(kokdizin..dosya) then
  1084. messages.file_not_found:format(kokdizin..dosya):yaz(3)
  1085. end
  1086. -- 2. hash kontrolü
  1087. if lfs.symlinkattributes(kokdizin..dosya, "mode") ~= "directory" and
  1088. lfs.symlinkattributes(kokdizin..dosya, "mode") ~= "link" then
  1089. if not islem.icbilgi.hash_kontrol(pdk,dosya) then
  1090. messages.hash_not_match:format(kokdizin..dosya):yaz(3)
  1091. end
  1092. end
  1093. end
  1094. else
  1095. messages.package_not_installed:format(paket):yaz(0)
  1096. end
  1097. end
  1098. ------------------------------
  1099. ------------------Sorgu İşlemleri-----------------------
  1100. islem.sorgu={retkey="sorgu:",}
  1101. function islem.sorgu.handler(input)
  1102. -- todo!!! farklı sorgu parametreleri olacak
  1103. -- sorgu test işlevi
  1104. if input.test then
  1105. print("sorgu işlevi testleri...")
  1106. end
  1107. -- kurulu paketlerin listesi
  1108. if input.kpl then
  1109. local komut="find %s -mindepth 1 -maxdepth 1 ! -type l -exec basename {} \\;"
  1110. pvt=kokdizin..islem.paket.vt
  1111. print(shell(komut:format(pvt)))
  1112. end
  1113. -- arama girdisinin hangi pakette geçtiğini bulur
  1114. if input.hp then
  1115. local aranan=input.hp
  1116. local komut="grep -rli %s %s*#*/kurulan | cut -d '/' -f6"
  1117. pvt=kokdizin..islem.paket.vt
  1118. print(shell(komut:format(aranan,pvt)))
  1119. end
  1120. end
  1121. ------------------İndirme İşlemleri-----------------------
  1122. -- handler parametre analiz ve linki hazırlayacak
  1123. -- job direk linki hash kontrollü indirecek
  1124. islem.indir={
  1125. retkey="indir",
  1126. usage="mps indir paket_ismi",
  1127. comment=messages.comment_mps_download
  1128. }
  1129. function islem.indir.handler(input)
  1130. -- paket bilgileri yer alacak
  1131. local inlist={}
  1132. -- öntanımlı 1.depodan çekmektedir.
  1133. local sira=1
  1134. -- girdi olarak varsa depo sırası güncellenecek
  1135. if input.sira then sira=tonumber(input.sira) end
  1136. local function pk_analiz(pkt)
  1137. local ret=islem.paket.pkvt_bilgi(pkt)
  1138. if ret then
  1139. -- indir işlemi paket bilgi tablosunu kullanacak.
  1140. if ret[sira] then
  1141. table.insert(inlist,ret[sira])
  1142. else
  1143. messages.package_not_found_inrepo:format(pkt):yaz(0)
  1144. end
  1145. else
  1146. print(pak,"depolarda bulunamadı")
  1147. end
  1148. end
  1149. -- konsoldan girilen paket girdi analiz
  1150. if input.paket then
  1151. for _,pk in ipairs(input.paket) do pk_analiz(pk) end
  1152. end
  1153. -- dosya parametresi içerik girdi analiz
  1154. if input.dosya then
  1155. if path_exists(input.dosya) then
  1156. for pk in (get_content(input.dosya)):gmatch("[^\r\n]+") do
  1157. pk_analiz(pk)
  1158. end
  1159. else
  1160. messages.file_not_found:format(dosya):yaz(0)
  1161. end
  1162. end
  1163. -- indirme test işlevi
  1164. if input.test then
  1165. for _,pk in ipairs(inlist) do print("s",pk) end
  1166. else
  1167. -- test yoksa indire işlemi yapacak
  1168. for _,pb in ipairs(inlist) do
  1169. islem.indir.job(pb)
  1170. end
  1171. end
  1172. end
  1173. function islem.indir.job(pb)
  1174. -- girdi olarak paket bilgi tablosu alır.
  1175. -- Link ve paket arşiv formatlarına ayrıştırır.
  1176. assert(pb,"paket bilgi tablosu nil")
  1177. -- indirilecek link ve kayıt yolu+dosya ismiyle
  1178. function _indir(link,kayit)
  1179. local body, code = http.request(link)
  1180. code=tostring(code)
  1181. if code:match("connection refused") then
  1182. messages.server_connection_refused:format(link):yaz(3)
  1183. elseif code=="404" then
  1184. messages.paketvt_not_found:yaz(3)
  1185. elseif code == "200" then
  1186. local f = assert(io.open(kayit, 'wb'))
  1187. f:write(body)
  1188. f:close();
  1189. if path_exists(kayit) then
  1190. (link):yaz(1);
  1191. else
  1192. messages.redownloading:format(kayit):yaz(2)
  1193. _indir(link,kayit);
  1194. end
  1195. elseif not body then
  1196. (link):yaz(3);
  1197. else
  1198. messages.unknown_error:format(link):yaz(0)
  1199. end
  1200. end
  1201. -- arşiv formatında # , web için %23 olauyor.
  1202. -- Bu nedenle global arşiv formatını kullanmıyoruz.
  1203. local larsiv=("%s%%23%s-%s-%s.mps.lz"):format(pb.isim,pb.surum,pb.devir,pb.mimari)
  1204. local arsiv=paf:format(pb.isim,pb.surum,pb.devir,pb.mimari)
  1205. local indirilecek=true
  1206. -- link oluşturulur
  1207. local link=plf:format(pb.depo,larsiv)
  1208. local kayit=kokdizin..islem.paket.cachedir.."/"..arsiv
  1209. -- print(link,"indirilecek")
  1210. -- indirme işlemi; indirme yöneticisine link ve kayıt yeri belirtilir.
  1211. if path_exists(kayit) then
  1212. -- eğer paket önbellekte var ise hash kontrolü yapılıp
  1213. -- hatalı ise silinip tekrar indirilir.
  1214. if hash_check(kayit,pb.shasum) then
  1215. indirilecek=false;
  1216. messages.package_incache:format(pb.isim):yaz(2)
  1217. -- paketin zaten indirilmiş olduğu-doğrulanması, dönüş kayit yol.
  1218. return kayit
  1219. else
  1220. messages.package_shasum_error:format(pb.isim):yaz(3)
  1221. messages.package_redownloading:format(pb.isim):yaz(2)
  1222. shell("rm -f "..kayit)
  1223. end
  1224. end
  1225. if indirilecek then
  1226. _indir(link,kayit)
  1227. -- shasum kontrol; indirilen dosya mevcut ve hash kontrolü yapılır.
  1228. if path_exists(kayit) then
  1229. if hash_check(kayit,pb.shasum) then
  1230. messages.package_downloaded:format(pb.isim):yaz(1)
  1231. -- paketin indirilmesi-doğrulanması, dönüş kayit yol.
  1232. return kayit
  1233. else
  1234. messages.package_shasum_error:format(pb.isim):yaz(0)
  1235. end
  1236. else
  1237. messages.package_download_error:format(pb.isim):yaz(0)
  1238. end
  1239. end
  1240. -- diğer durumlar için nil değerin döndürülmesi
  1241. return nil
  1242. end
  1243. ------------------------------------------------------------
  1244. -- Koşuk işlemleri - kurkos,koskur,silkos, kossil
  1245. islem.kosuk={
  1246. retkey="kosuk:",
  1247. predos=".koskur",
  1248. postdos=".kurkos",
  1249. postrm=".silkos",
  1250. prerm=".kossil",
  1251. }
  1252. -- kurmadan önce çalıştırılacak kod
  1253. function islem.kosuk.koskur(tempdir)
  1254. local log=""
  1255. if islem.kur.koskur then
  1256. assert(path_exists(tempdir),"islem.kosuk.koskur : tempdir is nil")
  1257. local kos=tempdir..islem.paket.metadir..islem.kosuk.predos
  1258. if path_exists(kos) then
  1259. -- koskur u çalıştıma sonuçları logla
  1260. -- koşuklara çalıştırma izni verme
  1261. shell("chmod +x "..kos)
  1262. os.execute(kos)
  1263. log="kosuk.koskur:\tOK"
  1264. else
  1265. log="kosuk.koskur:\tPASS"
  1266. end
  1267. else
  1268. log="kosuk.koskur:\tDISABLE"
  1269. end
  1270. islem.debug.yaz(log);
  1271. islem.kur.logger:write(log.."\n")
  1272. end
  1273. -- kurmadan sonra çalıştırılacak kod
  1274. function islem.kosuk.kurkos(tempdir)
  1275. local log=""
  1276. if islem.kur.kurkos then
  1277. assert(path_exists(tempdir),"islem.kosuk.kurkos : tempdir is nil")
  1278. local kos=tempdir..islem.paket.metadir..islem.kosuk.postdos
  1279. if path_exists(kos) then
  1280. -- kurkos u çalıştıma sonuçları logla
  1281. -- koşuklara çalıştırma izni verme
  1282. shell("chmod +x "..kos)
  1283. os.execute(kos)
  1284. log="kosuk.kurkos:\tOK"
  1285. else
  1286. log="kosuk.kurkos:\tPASS"
  1287. end
  1288. else
  1289. log="kosuk.kurkos:\tDISABLE"
  1290. end
  1291. islem.debug.yaz(log);
  1292. islem.kur.logger:write(log.."\n")
  1293. end
  1294. -- kurulumda dosya-dizin tetiklemeli otomatik çalıştırılacak kod
  1295. function islem.kosuk.otokos_kur(tempdir)
  1296. local log=""
  1297. if islem.kur.otokos then
  1298. assert(path_exists(tempdir),"islem.kosuk.otokos : tempdir is nil")
  1299. local curdir=lfs.currentdir()
  1300. lfs.chdir(tempdir)
  1301. -- todo!!! değişkene atılacak
  1302. kos=mps_path.."/conf/otokos.sh"
  1303. if path_exists(kos) then
  1304. -- kurkos u çalıştıma sonuçları logla
  1305. -- koşuklara çalıştırma izni verme
  1306. shell("chmod +x "..kos)
  1307. shell(kos.." kur")
  1308. log="kosuk.otokos_kur:\tOK"
  1309. else
  1310. log="kosuk.otokos_kur:\tPASS"
  1311. end
  1312. lfs.chdir(curdir)
  1313. else
  1314. log="kosuk.otokos_kur:\tDISABLE"
  1315. end
  1316. islem.debug.yaz(log);
  1317. islem.kur.logger:write(log.."\n")
  1318. end
  1319. -- silmeden önce çalıştırılacak kod
  1320. function islem.kosuk.kossil(paket)
  1321. assert(path_exists(kokdizin..islem.paket.vt..paket),"islem.kosuk.kossil : paketdir is nil")
  1322. local _betik=kokdizin..islem.paket.vt..paket.."/"..islem.kosuk.prerm
  1323. local log=""
  1324. if path_exists(_betik) then
  1325. -- kossil u çalıştıma sonuçları logla
  1326. -- koşuklara çalıştırma izni verme
  1327. shell("chmod +x ".._betik)
  1328. os.execute(_betik)
  1329. log="kosuk.kossil:\tOK"
  1330. else
  1331. log="kosuk.kossil:\tPASS"
  1332. end
  1333. islem.debug.yaz(log)
  1334. islem.sil.logger:write(log.."\n")
  1335. end
  1336. -- sildikten sonra çalıştırılacak kod
  1337. function islem.kosuk.silkos(paket)
  1338. assert(path_exists(kokdizin..islem.paket.vt..paket),"islem.kosuk.kossil : paketdir is nil")
  1339. local _betik=kokdizin..islem.paket.vt..paket.."/"..islem.kosuk.postrm
  1340. local log=""
  1341. if path_exists(_betik) then
  1342. -- silkos u çalıştıma sonuçları logla
  1343. -- koşuklara çalıştırma izni verme
  1344. shell("chmod +x ".._betik)
  1345. os.execute(_betik)
  1346. log="kosuk.silkos:\tOK"
  1347. else
  1348. log="kosuk.silkos:\tPASS"
  1349. end
  1350. islem.debug.yaz(log)
  1351. islem.sil.logger:write(log.."\n")
  1352. end
  1353. ------------------------------
  1354. -- Sil işlemleri
  1355. islem.sil={
  1356. retkey="sil:",
  1357. usage="mps sil paket_ismi",
  1358. dlistfile="%stmp/%s.del.list",
  1359. keeplist=".silme",
  1360. logdir=islem.paket.logdir.."sil/",
  1361. logger=nil,
  1362. silkos=true,
  1363. kossil=true,
  1364. }
  1365. function islem.sil.handler(input)
  1366. local remlist={}
  1367. --for k,pk in pairs(input) do print(k,pk) end
  1368. --print(input.paket)
  1369. if input.silkos == "0" then islem.sil.silkos=false end
  1370. if input.kossil == "0" then islem.sil.kossil=false end
  1371. local function pk_analiz(_paket)
  1372. local _durum=""
  1373. -- paketin kurulu kontrolünün atlanması için
  1374. if input.kksiz then
  1375. _durum=true
  1376. else
  1377. _durum=islem.paket.kurulu_kontrol(_paket)
  1378. end
  1379. if _durum then
  1380. if input.ona then
  1381. table.insert(remlist,_paket)
  1382. else
  1383. if islem.diyalog.onay(messages.confirm_package_uninstallation:format(_paket)) then
  1384. table.insert(remlist,_paket)
  1385. end
  1386. end
  1387. else
  1388. messages.package_not_installed:format(_paket):yaz(0)
  1389. end
  1390. end
  1391. -- konsoldan girilen paket girdi analiz
  1392. if input.paket then
  1393. for _,pk in ipairs(input.paket) do pk_analiz(pk) end
  1394. end
  1395. -- dosya parametresi içerik girdi analiz
  1396. if input.dosya then
  1397. if path_exists(input.dosya) then
  1398. for pk in (get_content(input.dosya)):gmatch("[^\r\n]+") do
  1399. pk_analiz(pk)
  1400. end
  1401. else
  1402. messages.file_not_found:format(dosya):yaz(0)
  1403. end
  1404. end
  1405. -- silme test işlevi
  1406. if input.test then
  1407. for _,pk in ipairs(remlist) do print("s",pk) end
  1408. else
  1409. -- test yoksa bu işlem yapılacak
  1410. for _,rpaket in ipairs(remlist) do
  1411. -- todo!!! ters gereklerini kontrol et / silinecek pakete bağlı olan paketler
  1412. islem.sil.job(rpaket)
  1413. end
  1414. end
  1415. end
  1416. function islem.sil.job(paket)
  1417. -- tek bir paketi siler
  1418. assert(paket,"islem.sil.paket : paket is nil")
  1419. -- sed "s/^'/\/mnt/" kurulan.s | sed "s/'//"
  1420. -- sil adımları
  1421. -- 0. logger set
  1422. islem.sil.set_logger(paket)
  1423. -- 1. silinecek dosya listesi hazırla
  1424. islem.sil.prepare_list(paket)
  1425. -- 2. silinecekleri filtrele(keeplist)
  1426. islem.sil.filter_list(paket)
  1427. -- 3. kos-sil betiğini kontrol et / çalıştır
  1428. islem.kosuk.kossil(paket)
  1429. -- 4. Dosyaları güvenli! sil ve logla
  1430. islem.sil.uygula(paket)
  1431. -- 5. sil-kos betiğini kontrol et / çalıştır
  1432. islem.kosuk.silkos(paket)
  1433. -- 6. paket veritabanı güncelle sil
  1434. islem.sil.paket_vt(paket)
  1435. -- silmeden sonra ld.so.cache güncellemesi için
  1436. islem.kur.ld_update("sil");
  1437. -- log dosyası kapatılır.
  1438. islem.sil.logger:close();
  1439. -- Silme işlemi sonuç kontrol
  1440. islem.sil.bitis(paket)
  1441. end
  1442. function islem.sil.set_logger(paket)
  1443. -- bu assert mps başına konulabilir
  1444. assert(path_exists(kokdizin..islem.paket.logdir),"islem.sil.set_logger : islem.paket.logdir is not availables, needs mps --ilk")
  1445. assert(path_exists(kokdizin..islem.sil.logdir),"islem.sil.set_logger : islem.sil.logdir is not availables, needs mps --ilk")
  1446. local logfile=kokdizin..islem.sil.logdir..paket..".log"
  1447. islem.sil.logger = assert(io.open(logfile, "w"),"islem.sil.set_logger logfile can not open")
  1448. islem.sil.logger:write(paket.."\t"..os.date("%x %H:%M:%S").."\n");
  1449. islem.sil.logger:write("--------------------------------------\n");
  1450. end
  1451. function islem.sil.bitis(paket)
  1452. -- Silme adımlarının başarılı bir şekilde tamamlandığını log dosyası ile kontrol eder.
  1453. local logfile=kokdizin..islem.sil.logdir..paket..".log"
  1454. assert(path_exists(logfile),"islem.sil.bitis : logfile is not available")
  1455. if not get_content(logfile):match("ERR@R") then
  1456. messages.package_uninstalled:format(paket):yaz(1)
  1457. else
  1458. messages.package_uninstallation_failed:format(paket):yaz(0)
  1459. end
  1460. end
  1461. function islem.sil.prepare_list(paket)
  1462. local sildos=islem.sil.dlistfile:format(kokdizin,paket)
  1463. local _kurulan=kokdizin..islem.paket.vt..paket.."/"..islem.kur.kurulandos
  1464. -- todo!!! silinecek dosyaların başına kök diizn ekleyerek gerçek yollu silineceklerin oluşturulması
  1465. --local komut='sed "s~^\'~%s~g" %s | sed "s/\'//" > %s'
  1466. -- silinecek dosyalardan ' karakterinin kaldirilmasi
  1467. local komut="sed 's/'\\''//g' %s > %s"
  1468. komut=komut:format(_kurulan,sildos)
  1469. shell(komut)
  1470. assert(get_size(sildos) > 0,"islem.sil.prepare_list : del.list is empty");
  1471. local log="prepare_list:\tOK"
  1472. islem.debug.yaz(log)
  1473. islem.sil.logger:write(log.."\n")
  1474. end
  1475. function islem.sil.filter_list(paket)
  1476. -- eğer paket dizin kaydında .silme isimli dosya varsa
  1477. -- o dosya içindeki alt alta sıralı dosyalar silinecekler listesinden elenecektir.
  1478. -- silinecekler başka dosya isimle içindekilerle karşılaştırılıp filtre edilenler silinir.
  1479. local keeplistfile=kokdizin..islem.paket.vt..paket.."/"..islem.sil.keeplist
  1480. local sildos=islem.sil.dlistfile:format(kokdizin,paket)
  1481. local log=""
  1482. if path_exists(keeplistfile) then
  1483. local komut_k='sed "s~^~%s~g" %s > %s'
  1484. komut_k=komut_k:format(kokdizin,keeplistfile,sildos..".keep")
  1485. shell(komut)
  1486. local komut_move="mv %s %s"
  1487. shell(komut_move:format(sildos,sildos.."f"))
  1488. local komut_f="sort %s %s |uniq -u > %s"
  1489. komut_f=komut_f:format(sildos..".f",keeplistfile,sildos)
  1490. shell(komut_f)
  1491. log="filter_list:\tOK"
  1492. else
  1493. log="filter_list:\tPASS"
  1494. end
  1495. islem.debug.yaz(log)
  1496. islem.sil.logger:write(log.."\n")
  1497. end
  1498. function islem.sil.uygula(paket)
  1499. local sildos=islem.sil.dlistfile:format(kokdizin,paket)
  1500. local sil_content=get_content(sildos);
  1501. -- Once tum paket *dosya*lari silinecek
  1502. -- Ardindan klasorler bos mu diye kontrol edilecek
  1503. -- Bos olan klasorler kaldirilacak
  1504. local exist=true
  1505. local delete=true
  1506. local log=""
  1507. local sil_komut="rm -rf %s"
  1508. local ret=nil
  1509. islem.sil.logger:write("---------------\n")
  1510. function smart_delete(file_list, no_check)
  1511. -- smart delete bir doysa+dizin listesi alir
  1512. -- Ilk olarak tum dosyalari kaldirir ve dizinleri arar
  1513. -- Ardindan bos olan dizinler kaldirilir
  1514. -- Son olarak bos olmayan dizinleri return eder
  1515. -- file_list bir string arrayi olmali
  1516. -- no_check bir boolean olmali
  1517. -- eger no_check 1 ise, tum dizinler
  1518. -- bos olup olmasina bakilmadan kalirilacak
  1519. to_remove={
  1520. files={},
  1521. dirs={}
  1522. }
  1523. for dos in file_list:gmatch("[^\r\n]+") do
  1524. file_attr = lfs.attributes(dos)
  1525. if file_attr then
  1526. if file_attr.mode == "file" then
  1527. table.insert(to_remove.files, dos)
  1528. else
  1529. _, count = dos:gsub('/', '/')
  1530. table.insert(to_remove.dirs, {dos, count})
  1531. end
  1532. end
  1533. end
  1534. -- tabloyu dizin hiyerasisine gore sirala
  1535. -- alttaki dizin tabloda uste gelir
  1536. function compare(a,b)
  1537. return a[2] > b[2]
  1538. end
  1539. table.sort(to_remove.dirs, compare)
  1540. -- once tum dosyalari kaldir
  1541. for _,v in pairs(to_remove.files) do
  1542. local result, reason = os.remove(v)
  1543. -- todo!!! dosya silinmemesine karsin error-check yap
  1544. if result then
  1545. else
  1546. end
  1547. end
  1548. nonempty_dirs={}
  1549. -- to_remove.dirs'i iterate et ve bos olan dizinleri kaldir
  1550. for i=1, #to_remove.dirs do
  1551. status, message, code = lfs.rmdir(to_remove.dirs[i][1])
  1552. if status == nil then
  1553. if code == 39 then
  1554. if no_check then
  1555. -- no_check set edilmisse, dizini recursive olarak kaldir
  1556. deletedir(to_remove.dirs[i])
  1557. else
  1558. -- Dizin bos degil, silme!, nonempty_dirs'e ekle
  1559. table.insert(nonempty_dirs, to_remove.dirs[i])
  1560. end
  1561. else
  1562. -- Hata yakala ve yazdir
  1563. hata_msg="Klasör silinemedi!".."\n"..message
  1564. hata_msg:yaz(0)
  1565. end
  1566. end
  1567. end
  1568. -- dizinleri recursive silmek icin yardimci function
  1569. function deletedir(dir)
  1570. for file in lfs.dir(dir) do
  1571. local file_path = dir..'/'..file
  1572. if file ~= "." and file ~= ".." then
  1573. if lfs.attributes(file_path, 'mode') == 'file' then
  1574. os.remove(file_path)
  1575. elseif lfs.attributes(file_path, 'mode') == 'directory' then
  1576. deletedir(file_path)
  1577. end
  1578. end
  1579. end
  1580. lfs.rmdir(dir)
  1581. end
  1582. return nonempty_dirs
  1583. end
  1584. -- sildos dosyasindaki entryleri smart_delete function'i ile sil
  1585. protected_dirs = smart_delete(sil_content)
  1586. -- Kullaniciya silinmeyen klasorleri goster
  1587. -- todo!!! bu ozelligi tamamla
  1588. -- kullanicidan input alip sil
  1589. delete_list={}
  1590. if #protected_dirs > 0 then
  1591. messages.confirm_dir_removing_msg:format(sildos_by_user):yaz(3)
  1592. sildos_by_user=islem.sil.dlistfile:format(kokdizin, paket)..".kor"
  1593. sildos_file = io.open(sildos_by_user, "w")
  1594. for i=1, #protected_dirs do
  1595. -- eger protected_dirs te varsa ancak kullanicinin degistirdigi dosyada yoksa
  1596. -- girdinin silinmesi gerekiyor
  1597. local dir ={}
  1598. dir.dir = protected_dirs[i][1]
  1599. dir.level =protected_dirs[i][2]
  1600. dir.children = {}
  1601. for j=i-1, 1, -1 do
  1602. if protected_dirs[j][2] == dir.level + 1 then
  1603. table.insert(dir.children, protected_dirs[j][1])
  1604. end
  1605. end
  1606. for file in lfs.dir(dir.dir) do
  1607. if file ~= "." and file ~= ".." then
  1608. file_path = dir.dir.."/"..file
  1609. if find(dir.children, file_path) < 0 then
  1610. sildos_file:write(file_path.."\n")
  1611. end
  1612. end
  1613. end
  1614. end
  1615. sildos_file:close()
  1616. messages.confirm_dir_removing_info:format(sildos_by_user):yaz(3)
  1617. local entries_from_user = {}
  1618. for line in io.lines(sildos_by_user) do
  1619. print(line)
  1620. table.insert(entries_from_user, line)
  1621. end
  1622. end
  1623. ----------
  1624. islem.sil.logger:write("---------------\n")
  1625. if exist and delete then
  1626. log="sil.uygula: \tOK";
  1627. islem.debug.yaz(log);
  1628. islem.sil.logger:write(log.."\n")
  1629. else
  1630. log="sil.uygula:\tERR@R";
  1631. log:yaz(3);
  1632. islem.sil.logger:write(log.."\n")
  1633. end
  1634. end
  1635. function islem.sil.paket_vt(paket)
  1636. local dizin=kokdizin..islem.paket.vt..paket
  1637. assert(path_exists(dizin),"islem.sil.paket_vt : dizin is not available")
  1638. local log=""
  1639. local komut_vt="rm -rf %s"
  1640. komut_vt=komut_vt:format(dizin)
  1641. shell(komut_vt);
  1642. -- linkin de silinmesi
  1643. shell(komut_vt.."#*");
  1644. if not path_exists(dizin) then
  1645. log="sil.paket_vt:\tOK";
  1646. islem.debug.yaz(log);
  1647. islem.sil.logger:write(log.."\n")
  1648. else
  1649. log="sil.paket_vt:\tERR@R";
  1650. log:yaz(3);
  1651. islem.sil.logger:write(log.."\n")
  1652. end
  1653. end
  1654. ------------------------------
  1655. -- Kur işlemleri
  1656. islem.kur={
  1657. retkey="kur:",
  1658. kurulandos="kurulan",
  1659. dizinler={"boot","etc","usr","opt","var","tools"}, -- paket içi desteklenen dizinler
  1660. usage="mps kur paket_ismi | paket_yolu",
  1661. logdir=islem.paket.logdir.."kur/",
  1662. logger=nil,
  1663. kurkos=true,
  1664. koskur=true,
  1665. otokos=true,
  1666. zorla=false,
  1667. comment=messages.comment_mps_install,
  1668. }
  1669. function islem.kur.agdan(paket)
  1670. --print ("ağdan kurma TEST AŞAMASINDA!")
  1671. assert(paket,"islem.kur.agdan : paket is nil")
  1672. -- 1.çalışma gerekleri tespit edilecek tablo=gerek paket c
  1673. -- islem gerek listesi global olduğu için sıfırlanması gerekir.
  1674. islem.gerek.liste={}
  1675. islem.gerek.job(paket,"c")
  1676. --print(paket,#islem.gerek.liste)
  1677. -- 2.paketvt ler den döngüde paket#surum-devir
  1678. local ret, pk=""
  1679. local kurliste={}
  1680. local pkpath=nil
  1681. -- 3. gereklerin sıralı indirme
  1682. for _,tsd in ipairs(islem.gerek.liste) do
  1683. -- 3.1 indirilecek size bilgi - kurulacak bilgi verilip onay ile
  1684. pk,_=tsd:match("([%a%d-_+]+)#+")
  1685. -- paket kurulu ise atlanacak
  1686. if islem.paket.kurulu_kontrol(pk) then
  1687. (messages.package_already_installed..":"..pk):yaz(2);
  1688. else
  1689. ret=islem.paket.pkvt_bilgi(pk)[1]
  1690. -- paket paket veritabanında bulunamaz ise, veritabanı güncellenmelidir.
  1691. if ret == nil then messages.package_not_found_inpkvt:format(pk):yaz(0) end
  1692. -- indirme işlemi
  1693. -- kurliste ye inen/indirilmiş paketin yolunun kaydı
  1694. pkpath=islem.indir.job(ret)
  1695. if pkpath == nil then
  1696. messages.package_dependency_dl_error:format(pk):yaz(3)
  1697. else
  1698. table.insert(kurliste,pkpath)
  1699. end
  1700. end
  1701. end
  1702. -- 4.gerekler kurulacak (yerelden kur ile cachedir den)
  1703. for _,pkyol in ipairs(kurliste) do
  1704. -- 4.1 indirilecek size bilgi - kurulacak bilgi verilip onay ile
  1705. islem.kur.yerelden(pkyol)
  1706. end
  1707. end
  1708. function islem.kur.yerelden(paket)
  1709. --print (paket) -- belki bu mps.log a atılabilir/nereden talimatlandığına dair
  1710. -- yerelden gelen paketin mevcut kontrolü
  1711. -- gönderen işlevler yapamazsa
  1712. if not paket then
  1713. messages.package_not_found:format(paket):yaz(0)
  1714. end
  1715. assert(paket ~= "","islem.kur.yerelden : paket is empty string")
  1716. -- print (paket,"yerelden")
  1717. -- adımlar: loglanacak, her işlem adımı log dosyasına atacak
  1718. -- önemli not: pcall ile işlemler uygulanacak, eğer break olursa sistem kaynaklı (ctrl+c vs)
  1719. -- işlem adımı ve onu çağıran süreç job dosyası state kayıt edilecek.
  1720. -- -1. paket arşivi kontrol edilir
  1721. local isim,surum,devir=islem.arsiv.kontrol(paket)
  1722. -- -2. logger set
  1723. islem.kur.set_logger(isim)
  1724. -- 0. paket kurulu kontrol yapılır
  1725. islem.kur.kurulu_kontrol(isim)
  1726. -- 1. /tmp altında geçici bir dizine çıkarılır
  1727. local tempdir=islem.arsiv.cikar(paket)
  1728. -- 2. libgerekler kontrol edilir- ldconfig sor
  1729. islem.shlib.kontrol(tempdir) --/ kontrol altına eksik shlibleri içeren paketler kurulabilir.
  1730. -- 3. hedef kurulum dizininde çakışan/var olan dosya kontrolü
  1731. islem.kur.dosya_kontrol(tempdir)
  1732. -- 4. koşkur varsa çalıştırılır 2.madde?
  1733. islem.kosuk.koskur(tempdir)
  1734. -- 5. geçici dizinden hedef dizin altına kopyalanır
  1735. islem.kur.kopyala(tempdir)
  1736. -- 6. kopyalanan dosyalar VT e yazılır, var/lib/mps/DB altına paketismi
  1737. -- tempdir altında kurulan dosyası, .icbilgi, .ustbilgi, kosuklar, libgerekler, pktlibler
  1738. islem.kur.vt_kayit(tempdir,isim,surum,devir)
  1739. -- 7. mtree ile karşılaştırma doğrulanır
  1740. -- 8. ldconfig güncellemesi
  1741. islem.kur.ld_update_handler(tempdir)
  1742. -- 9. kurkos çalıştırılır
  1743. islem.kosuk.kurkos(tempdir)
  1744. -- 10. otokos çalıştırılır
  1745. islem.kosuk.otokos_kur(tempdir)
  1746. -- 11. temizlik, başarı mesaj...
  1747. islem.kur.clean_tempdir(tempdir)
  1748. -- 12. log dosyası kapatılır.
  1749. islem.kur.logger:close();
  1750. -- 13. Paket kurulum sonucu
  1751. islem.kur.bitis(isim)
  1752. end
  1753. function islem.kur.clean_tempdir(tempdir)
  1754. -- kurma işlemleri bittikten sonra paket içeriğinin
  1755. -- geçici çıkarıldığı tempdir silinir.
  1756. local komut="rm -rf %s"
  1757. komut=komut:format(tempdir)
  1758. shell(komut)
  1759. end
  1760. function islem.kur.bitis(paket)
  1761. -- Kurulum adımlarının başarılı bir şekilde tamamlandığını log dosyası ile kontrol eder.
  1762. local logfile=kokdizin..islem.kur.logdir..paket..".log"
  1763. assert(path_exists(logfile),"islem.kur.bitis : logfile is not available")
  1764. if not get_content(logfile):match("ERR@R") then
  1765. messages.package_installed:format(paket):yaz(1)
  1766. else
  1767. messages.package_installation_failed:format(paket):yaz(0)
  1768. end
  1769. end
  1770. function islem.kur.set_logger(paket)
  1771. -- bu assert mps başına konulabilir
  1772. assert(path_exists(kokdizin..islem.paket.logdir),"islem.kur.set_logger : islem.paket.logdir is not available, needs mps --ilk")
  1773. assert(path_exists(kokdizin..islem.kur.logdir),"islem.kur.set_logger : islem.kur.logdir is not availables, needs mps --ilk")
  1774. local logfile=kokdizin..islem.kur.logdir..paket..".log"
  1775. --print("-",logfile)
  1776. islem.kur.logger = assert(io.open(logfile, "w"),"islem.kur.set_logger logfile can not open")
  1777. islem.kur.logger:write(paket.."\t"..os.date("%x %H:%M:%S").."\n");
  1778. islem.kur.logger:write("--------------------------------------\n");
  1779. end
  1780. function islem.kur.ld_update_handler(tempdir)
  1781. local log=""
  1782. if path_exists(tempdir..islem.paket.metadir..islem.paket.pktlib_dosya)
  1783. or path_exists(tempdir..islem.paket.metadir..islem.shlib.dosya) then
  1784. -- libgerek?(kurulu ise cache edilmiş olmalı), shlib varsa ldconfig edilecek.
  1785. islem.kur.ld_update()
  1786. log="ld_up_handler:\tOK";
  1787. islem.kur.logger:write(log.."\n")
  1788. else
  1789. messages.ld_update_pass:yaz()
  1790. log="ld_up_handler:\tPASS";
  1791. islem.kur.logger:write(log.."\n")
  1792. end
  1793. end
  1794. -- kura mahsus olmasın todo!!!
  1795. function islem.kur.ld_update(oper)
  1796. -- hedef kök dizinde ldconfig varsa güncelleme olur.
  1797. local log=""
  1798. if path_exists(kokdizin.."usr/bin/ldconfig")
  1799. or path_exists(kokdizin.."sbin/ldconfig") then
  1800. --print("ldconfig update edilecek")
  1801. local _cachedos="etc/ld.so.cache"
  1802. local komut1=("rm -f %s%s"):format(kokdizin,_cachedos)
  1803. --print(komut1)
  1804. shell(komut1)
  1805. local komut2=("ldconfig -r %s"):format(kokdizin)
  1806. --print(komut2)
  1807. shell(komut2)
  1808. else
  1809. (messages.ld_update_pass..kokdizin):yaz()
  1810. log="ld_update:\tPASS";
  1811. if oper then
  1812. islem[oper].logger:write(log.."\n")
  1813. else
  1814. islem.kur.logger:write(log.."\n")
  1815. end
  1816. end
  1817. end
  1818. function islem.kur.kopyala(tempdir)
  1819. -- geçici çıkarma dizininden sisteme kopyala işlemi
  1820. -- geçerli dizinler kontrol edilerek kopyalama yapılır
  1821. -- tempdir altındaki dizinleri islem.kur.dizinler ile karşılaştır.
  1822. local dirs=get_dirs(tempdir)
  1823. local kurulandos=tempdir..islem.kur.kurulandos
  1824. assert(dirs,"islem.kur.kopyala : dirs is nil")
  1825. --table.insert(dirs,"sbin")
  1826. local log=""
  1827. for _,dir in ipairs(dirs) do
  1828. if not has_value(islem.kur.dizinler,dir) and dir.."/" ~= islem.paket.metadir then
  1829. (messages.invalid_package_content..dir):yaz(3)
  1830. islem.kur.logger:write(messages.invalid_package_content..dir.."\n")
  1831. end
  1832. end
  1833. local komut=""
  1834. for _,dizin in ipairs(islem.kur.dizinler) do
  1835. if path_exists(tempdir..dizin) then
  1836. komut='cp -v -aflr %s %s | awk \'{split($0,a,"-> "); print a[2]}\' | sed \'s#%s#/#g\' >> %s'
  1837. komut=komut:format(tempdir..dizin,kokdizin,kokdizin,kurulandos)
  1838. shell(komut)
  1839. log="kur.kopyala:\tOK";
  1840. islem.debug.yaz(log)
  1841. islem.kur.logger:write(log.."\n")
  1842. end
  1843. end
  1844. end
  1845. function islem.kur.vt_kayit(tempdir,isim,surum,devir)
  1846. -- sisteme kopyalanan paketin paket veritabanı kaydının yapılması
  1847. -- ve kurulum logunun oluşturulması (adımlar loglanacak)
  1848. assert(isim,"islem.kur.vt_kayit : isim is nil")
  1849. local log=""
  1850. local paket_vt_dizin=kokdizin..islem.paket.vt..isim.."/"
  1851. -- linkin oluşturulması - indeksleme için
  1852. local paket_vt_dizin_link=kokdizin..islem.paket.vt..isim.."#"..surum.."-"..devir
  1853. -- paket_vt dizin oluşturma
  1854. local komut0=("rm -rf %s"):format(paket_vt_dizin)
  1855. shell(komut0)
  1856. local komut1=("mkdir -p %s"):format(paket_vt_dizin)
  1857. local komut_link=("ln -s %s %s"):format(paket_vt_dizin,paket_vt_dizin_link)
  1858. --print(komut1)
  1859. shell(komut1)
  1860. shell(komut_link)
  1861. -- / altındakileri silme engeli
  1862. assert(paket_vt_dizin ~= "/","islem.kur.vt_kayit : paket_vt_dizin must not be /")
  1863. -- paket_vt dizin temizlik
  1864. local komut2=("rm -rf %s*"):format(paket_vt_dizin)
  1865. --print(komut2)
  1866. shell(komut2)
  1867. -- paket.vt içerik kopyalama (tek tek bilgi dosyaları yada file olan her obje)
  1868. -- kurulan dosyası da eklenir, islem.kur içinde tanımlandığı için burda ekliyoruz.
  1869. -- kurulan dosyanın oluşması beklenir, oluşmadıysa sisteme dosya ve dizin kopyalama olmamıştır.
  1870. assert(path_exists(tempdir..islem.kur.kurulandos),"islem.kur.vt_kayit : kurulan file is not available -> no files, dirs copied!!!")
  1871. -- kurulan dosyasının paket kayıt dizine kaydı
  1872. shell(("cp -avf %s %s"):format(tempdir..islem.kur.kurulandos,paket_vt_dizin))
  1873. -- .meta dizini kopyala
  1874. shell(("cp -avf %s %s"):format(tempdir..islem.paket.metadir,paket_vt_dizin))
  1875. -- icbilgi dosyası kopyala
  1876. shell(("cp -avf %s %s"):format(tempdir..islem.icbilgi.dosya,paket_vt_dizin))
  1877. log="kur.vt_kayit:\tOK";
  1878. islem.debug.yaz(log)
  1879. islem.kur.logger:write(log.."\n")
  1880. -- vt_kayıt test edilecek!!!
  1881. end
  1882. function islem.kur.dosya_kontrol(tempdir)
  1883. -- sisteme kopyalanacak paket içeriğinin sistemde çakışan karşılık kontrolü
  1884. -- çakışanlar için strateji belirlenmeli: üzerine yaz, koru vs
  1885. local dosyalar=islem.icbilgi.dosyalar(tempdir)
  1886. assert(dosyalar,"islem.kur.dosya_kontrol : dosyalar is nil")
  1887. local ret=true
  1888. local log=""
  1889. local conflict_files={}
  1890. for _,dosya in ipairs(dosyalar) do
  1891. if path_exists(kokdizin..dosya) then
  1892. (messages.file_already_exists:format(kokdizin..dosya)):yaz(3)
  1893. table.insert(conflict_files,kokdizin..dosya)
  1894. ret=false
  1895. end
  1896. end
  1897. -- handling already exist files
  1898. if not ret and islem.kur.zorla == false then
  1899. if islem.diyalog.onay(messages.confirm_files_removing) then
  1900. -- conflict_files tablosundan dosyalar sıralı şekilde silinir
  1901. for _,dosya in ipairs(conflict_files) do
  1902. shell("rm -f "..dosya)
  1903. end
  1904. log="çakışan_dosya:\tOK";
  1905. else
  1906. -- tempdir i sil çıkış yap
  1907. -- print("koskurdan sonra olmalı çakşm,log da silinmeli!!! not yet")
  1908. -- islem.kur.clean_tempdir(tempdir)
  1909. -- os.exit()
  1910. log="çakışan_dosya:\tOVERRIDE";
  1911. end
  1912. islem.debug.yaz(log);
  1913. else
  1914. log="dosya_kontrol:\tOK";
  1915. islem.debug.yaz(log);
  1916. end
  1917. islem.kur.logger:write(log.."\n")
  1918. end
  1919. function islem.kur.kurulu_kontrol(paket)
  1920. -- sistemde kurulu paket kontrolü
  1921. -- burada kurulu pakete uygulanacak seçenek sorulur
  1922. -- sil/silme
  1923. assert(paket,"islem.kur.kurulu_kontrol : paket is nil")
  1924. local log=""
  1925. if islem.paket.kurulu_kontrol(paket) then
  1926. log=messages.package_already_installed;
  1927. messages.package_already_installed:yaz(0);
  1928. else
  1929. log="kurulu_kontrol:\tOK";
  1930. end
  1931. islem.debug.yaz(log)
  1932. islem.kur.logger:write(log.."\n")
  1933. end
  1934. function islem.kur.job(kur)
  1935. -- dikkat ! sıralı kurmayabilir tablo şeklinde geliyor
  1936. -- işlemlerin logu hazırlanacak.
  1937. for tip,tablo in pairs(kur) do
  1938. -- burası sıralı iş
  1939. if kur[tip] then
  1940. for _,job in ipairs(tablo) do
  1941. islem.kur[tip](job)
  1942. end
  1943. end
  1944. end
  1945. end
  1946. function islem.kur.handler(input)
  1947. -- işlem isminden sonra en az bir parametre olmalıdır.
  1948. if input.kurkos == "0" then islem.kur.kurkos=false end
  1949. if input.koskur == "0" then islem.kur.koskur=false end
  1950. if input.otokos == "0" then islem.kur.otokos=false end
  1951. if input.zorla == "1" then islem.kur.zorla=true end
  1952. local jobs={
  1953. agdan={},
  1954. yerelden={}
  1955. }
  1956. -- paketin yerel/ağ kaynak tespiti ve ilgili listeye eklenmesi
  1957. local function pk_analiz(pkt)
  1958. if pkt:match("mps.lz") then
  1959. -- yerelden kurulacak listeye eklenir
  1960. table.insert(jobs.yerelden,get_abspath(pkt))
  1961. else
  1962. local _talimatd=islem.talimat_bul.job(pkt)
  1963. if _talimatd then
  1964. -- ağdan kurulacak listeye eklenir
  1965. table.insert(jobs.agdan,_talimatd)
  1966. else
  1967. (messages.talimat_not_found..pkt):yaz(0)
  1968. end
  1969. end
  1970. end
  1971. -- konsoldan girilen paket girdi analiz
  1972. if input.paket then
  1973. for _,pk in ipairs(input.paket) do pk_analiz(pk) end
  1974. end
  1975. -- dosya parametresi içerik girdi analiz
  1976. if input.dosya then
  1977. if path_exists(input.dosya) then
  1978. for pk in (get_content(input.dosya)):gmatch("[^\r\n]+") do
  1979. pk_analiz(pk)
  1980. end
  1981. else
  1982. messages.file_not_found:format(dosya):yaz(0)
  1983. end
  1984. end
  1985. -- handler işlevinin test işlemi
  1986. if input.test then
  1987. for _,v in ipairs(jobs.agdan) do print("a",v) end
  1988. for _,v in ipairs(jobs.yerelden) do print("y",v) end
  1989. else
  1990. -- test yoksa bu işem yapılacak
  1991. islem.kur.job(jobs);
  1992. end
  1993. -- todo!!! işlemlerin logu okunacak
  1994. -- ("işlemlerin logu okunacak"):yaz(2)
  1995. end
  1996. --------------------------------------------
  1997. --------Güncelleme İşlemleri-------------------
  1998. islem.guncelle={
  1999. retkey="guncelle:",
  2000. comment=messages.usage_updating_repos,
  2001. usage="mps guncelle",
  2002. betikdepo={isim="betikdepo",tnm="Betik",path=milispath},
  2003. talimatdepo={isim="talimatdepo",tnm="Git",path=talimatname}
  2004. }
  2005. -- işlevler
  2006. function islem.guncelle.handler(input)
  2007. local sira=tonumber(input.sira)
  2008. -- mps güncelleme
  2009. if input.mps or input.hepsi then
  2010. islem.guncelle.mps()
  2011. end
  2012. -- talimat depolarının güncelleme
  2013. if input.git or input.hepsi then
  2014. islem.guncelle.gitdepo(sira,islem.guncelle.talimatdepo)
  2015. end
  2016. -- betik depolarının güncelleme
  2017. if input.betik or input.hepsi then
  2018. islem.guncelle.gitdepo(sira,islem.guncelle.betikdepo)
  2019. end
  2020. -- paketvt depoları güncelleme
  2021. if input.depo or input.hepsi then
  2022. islem.guncelle.paketvt(sira)
  2023. end
  2024. end
  2025. function islem.guncelle.mps()
  2026. -- todo!!! mps commit hash tutulacak oradan commit değer değişimi gösterilecek
  2027. -- değişim yoksa güncelleme yok
  2028. assert(path_exists(mps_path),"mps_path not exist")
  2029. assert(path_exists(mps_path.."/.git"),"invalid git directory");
  2030. ("MPS güncelleniyor:"):yaz(2);
  2031. ("------------------------------------"):yaz(2);
  2032. local komut="cd %s && git reset --hard HEAD && git pull ; chmod +x bin/mps*"
  2033. local ret=shell(komut:format(mps_path));
  2034. -- ret=shell(git_kont:format(repo,tmp,tmp))
  2035. ("------------------------------------"):yaz(2)
  2036. end
  2037. function islem.guncelle.paketvt(sira)
  2038. ("Paket veritaban(lar)ı güncelleniyor:"):yaz(2);
  2039. ("------------------------------------"):yaz(2);
  2040. if not path_exists(kokdizin..islem.paket.cachedir) then
  2041. local create_cache=("mkdir -p %s%s"):format(kokdizin,islem.paket.cachedir)
  2042. shell(create_cache)
  2043. end
  2044. sira=tonumber(sira)
  2045. local pkvt="paket.vt"
  2046. -- işlev içinde işlev paket.vt i indirmek için
  2047. -- paket.vt.gz gibi sıkıştırılmış gerçekleme yapılacak. todo!!!
  2048. function _indir(sunucu,sira)
  2049. -- io.write(sunucu.."/"..pkvt.."\t")
  2050. local link=sunucu.."/"..pkvt
  2051. local body, code = http.request(link)
  2052. code=tostring(code)
  2053. if code:match("connection refused") then
  2054. messages.server_connection_refused:format(sunucu):yaz(3)
  2055. elseif code=="404" then
  2056. messages.paketvt_not_found:yaz(3)
  2057. elseif code == "200" then
  2058. local kayit=kokdizin..islem.paket.cachedir.."/"..pkvt.."#"..sira
  2059. local f = assert(io.open(kayit, 'wb'))
  2060. f:write(body)
  2061. f:close();
  2062. -- ("+"):yaz(1);
  2063. --kayit:yaz(2);
  2064. if path_exists(kayit) then
  2065. (link):yaz(1);
  2066. else
  2067. messages.redownloading:format(kayit):yaz(2)
  2068. _indir(sunucu,sira);
  2069. end
  2070. elseif not body then
  2071. (link):yaz(3);
  2072. else
  2073. messages.unknown_error:format(link):yaz(0)
  2074. end
  2075. end
  2076. -- eğer sadece bir paket sunucu güncellenmek istenirse
  2077. if sira then
  2078. -- sıra aşımlı paket vt güncellenmek istenirse
  2079. if #ayar.sunucu < sira then
  2080. messages.package_db_out_of_order:yaz(0)
  2081. end
  2082. if ayar.sunucu[sira] then
  2083. _indir(ayar.sunucu[sira],sira)
  2084. end
  2085. -- çoklu sunucu güncelleme
  2086. else
  2087. for _sira,sunucu in ipairs(ayar.sunucu) do
  2088. _indir(sunucu,_sira)
  2089. end
  2090. end
  2091. ("------------------------------------"):yaz(2);
  2092. end
  2093. function islem.guncelle.gitdepo(sira,depo)
  2094. -- tip=betikdepo, gitdepo
  2095. -- depo={isim="betikdepo",tnm="Betik",path=milispath}
  2096. -- depo={isim="gitdepo",tnm="Git",path=talimatname}
  2097. -- bin, ayarlar lı betikdepo güncelleme yapılacak todo!!!
  2098. assert(depo,"depo is nil!!!");
  2099. (depo.tnm.." depoları güncelleniyor:"):yaz(2);
  2100. ("------------------------------------"):yaz(2);
  2101. -- iç işlevler
  2102. function do_clone(repo,path)
  2103. local komut="git clone %s %s"
  2104. local ret=shell(komut:format(repo,path))
  2105. end
  2106. function do_pull(path)
  2107. assert(path_exists(path.."/.git"),"invalid git directory")
  2108. local komut="cd %s && git pull"
  2109. local ret=shell(komut:format(path))
  2110. end
  2111. function esitle(repoyol,altdizin,hedef)
  2112. -- todo!!! eşitlenecek dizinden sadece talimat içeren
  2113. -- dizinleri alarak eşitleme yap veya sonda silme
  2114. local komut="cp -rf %s/%s/* %s/"
  2115. if path_exists(repoyol.."/"..altdizin) then
  2116. shell(komut:format(repoyol, altdizin ,hedef))
  2117. else
  2118. messages.git_repo_subdir_not_found:yaz(0)
  2119. end
  2120. end
  2121. function yedekle(dizin)
  2122. local komut="mv %s %s.ydk"
  2123. assert(path_exists(dizin),dizin.." dizini yok!")
  2124. shell(komut:format(dizin,dizin))
  2125. -- dizin yedeklenerek yeni boş oluşturulur.
  2126. assert(lfs.mkdir(dizin),dizin.." oluşturulamadı.")
  2127. end
  2128. -- yedeklenen dizin güncellenemediğinden geri yedeklenir.
  2129. function geri_yedekle(dizin)
  2130. local komut="mv %s.ydk %s"
  2131. assert(path_exists(dizin..".ydk"),dizin..".ydk dizini yok!")
  2132. shell(komut:format(dizin,dizin))
  2133. end
  2134. -- yedeklenen dizinin silinmesi
  2135. function yedek_sil(dizin)
  2136. local komut="rm -rf %s.ydk"
  2137. assert(path_exists(dizin..".ydk"),dizin..".ydk dizini yok!")
  2138. shell(komut:format(dizin,dizin))
  2139. end
  2140. local _repo=""
  2141. local _repoyol=""
  2142. local duzey=""
  2143. local tmp=shell("mktemp")
  2144. -- git repo mevcut kontrol komut
  2145. local git_kont="git ls-remote -q %s > %s 2>&1;cat %s | head -n1 | awk '{print $1}'"
  2146. -- !!! burası farklı ayar.betikdepo
  2147. for bdepo,repolar in pairs(ayar[depo.isim]) do
  2148. -- !!! burası farklı
  2149. duzey=depo.path.."/"..bdepo
  2150. -- her talimat-betik düzeyinde yedekleme-eşitleme-eskiyi silme yapılacak
  2151. yedekle(duzey)
  2152. for repo,dizin in pairs(repolar) do
  2153. -- git repo mevcut kontrolü
  2154. local ret=shell(git_kont:format(repo,tmp,tmp))
  2155. io.write(bdepo," ",repo," ",dizin)
  2156. if ret:match("fatal") then
  2157. ("\t-"):yaz(1)
  2158. else
  2159. -- Git işlemleri
  2160. -- repo netde mevcut ise, yerelde yoksa clone varsa pull yapılacak.
  2161. _repo=repo:gsub("https://", "")
  2162. _repo=_repo:gsub("http://", "")
  2163. _repo=_repo:gsub("/", ".")
  2164. print("\t",_repo)
  2165. _repoyol=kokdizin..ayar.repo_dizin.."/".._repo
  2166. if path_exists(_repoyol) then
  2167. do_pull(_repoyol)
  2168. else
  2169. do_clone(repo, _repoyol)
  2170. end
  2171. -- Eşitleme işlemleri
  2172. esitle(_repoyol,dizin,duzey)
  2173. end
  2174. end
  2175. -- sıra-talimat düzeyi işlemler bittikten sonra .ydk düzey silinir.
  2176. if path_exists(duzey..".ydk") then
  2177. if lfs.rmdir(duzey) == true then
  2178. geri_yedekle(duzey)
  2179. else
  2180. yedek_sil(duzey)
  2181. end
  2182. end
  2183. end
  2184. shell(("rm -f %s"):format(tmp));
  2185. ("------------------------------------"):yaz(2);
  2186. end
  2187. -- Mps İşlemleri ----------------------------
  2188. -- -ayar öntanımlı ayarlar yükler/kopyalar
  2189. -- todo!!! mps kos altına alınacak
  2190. islem.ayarla={
  2191. retkey="ayarla:",
  2192. comment=messages.usage_configure,
  2193. usage="mps ayarla",
  2194. }
  2195. function islem.ayarla.handler()
  2196. -- mps için conf.lua yükleme komutu
  2197. local komut="cp -f %s/conf/conf.lua.sablon %s/conf/conf.lua"
  2198. shell(komut:format(mps_path,mps_path))
  2199. end
  2200. ------------------------------------------------------------
  2201. -----------------------------------------
  2202. -- Debug işlemleri
  2203. islem.debug={
  2204. retkey="debug",
  2205. }
  2206. function islem.debug.yaz(log)
  2207. if args.debug then
  2208. if log then
  2209. log:yaz()
  2210. else
  2211. messages.empty_log:yaz(0)
  2212. end
  2213. end
  2214. end
  2215. -----------------------------------------
  2216. ----------------------------------------
  2217. -- Yetkili çalıştırma kontrolü
  2218. authorised_check()
  2219. ---PARAMETRE ANALİZ
  2220. -- komutlar
  2221. -- kur, sil, in, gun, der, bil, ara, sor, kos
  2222. local parser = argparse("mps", "Milis Linux Paket Yöneticisi") :require_command(false)
  2223. --seçili olan komutu tespit etmek için
  2224. parser:command_target("command")
  2225. -- genel seçenekler
  2226. parser:flag "-v" "--version" :description "Sürüm bilgisi gösterir"
  2227. :action(function() print("MPS 2.0.8 - Milis Paket Sistemi milisarge@gmail.com") ;os.exit(0) end)
  2228. parser:option "--renk" :default(1) :description "Çıktının renkli olup olmama durumunu belirler"
  2229. parser:option "--kok" :default "/" :description "Mps işlemleri için hedef kök dizini belirtir"
  2230. parser:option "--ilkds" :args(0) :description "Milis dosya sistemi için hedef kök dizinde ilk yapılandırmaları yapar"
  2231. parser:option "--ilk" :args(0) :description "Mps nin hedef kök dizinde ilk yapılandırmaları yapar"
  2232. parser:flag "--ona" :description "Yapılacak mps işlemi için onay verir"
  2233. parser:flag "--debug" :description "Yapılan işlemlerin ayrıntılı çıktısını verir"
  2234. parser:flag "--test" :description "Yapılan işlemlerin sadece test işlevini çalıştırır"
  2235. -- komut parametreleri
  2236. local install = parser:command "kur" :description "paket kurma işlemi" -- :action(handler)
  2237. install:argument "paket" :args("*") :description "yerel/ağ paket girdileri"
  2238. install:option "-d" "--dosya" :description "dosyadan paketleri kurar"
  2239. install:option "--kurkos" :argname "<0/1>" :default "1" :description "paket kurulum sürecince kurkos betiklerinin çalıştırma durumunu belirler"
  2240. install:option "--koskur" :argname "<0/1>" :default "1" :description "paket kurulum sürecince kurkos betiklerinin çalıştırma durumunu belirler"
  2241. install:option "--otokos" :argname "<0/1>" :default "1" :description "paket kurulum sürecince kurkos betiklerinin çalıştırma durumunu belirler"
  2242. install:option "--zorla" :default "0" :description "zorla kurulum durumunu belirler"
  2243. local delete = parser:command "sil" :description "paket silme işlemi"
  2244. delete:argument "paket" :args("*") :description "paket girdileri (abc def ghi)"
  2245. delete:option "-d" "--dosya" :description "dosyadan paketleri siler"
  2246. delete:option "--kksiz" :args(0) :description "kurulu kontrolü yapılmaz"
  2247. local update = parser:command "gun" :description "güncelleme işlemleri"
  2248. update:option "-M" "--mps" :args(0) :description "mps i günceller"
  2249. update:option "-G" "--git" :args(0) :description "git depoları günceller"
  2250. update:option "-B" "--betik" :args(0) :description "betik depoları günceller"
  2251. update:option "-P" "--depo" :args(0) :description "paket depoları günceller"
  2252. update:option "-H" "--hepsi" :args(0) :description "Bütün güncellemeleri yapar -MGBP"
  2253. update:option "--sira" :default "1" :description "depo sırasını belirtilir"
  2254. local build = parser:command "der" :description "paket derleme işlemi"
  2255. build:argument "paket" :args("*") :description "paket girdileri (abc def ghi)"
  2256. build:option "-d" "--dosya" :description "dosyadan paketleri derler"
  2257. build:option "--kur" :args(0) :description "derledikten sonra kurar"
  2258. build:option "-t --tek" :args(0) :description "gerek kontrolü yapılmadan tek paket derlenir"
  2259. local fetch = parser:command "in" :description "paket indirme işlemi"
  2260. fetch:argument "paket" :args("*") :description "paket girdileri (abc def ghi)"
  2261. fetch:option "-d" "--dosya" :description "dosyadan paketleri indirir"
  2262. fetch:option "--sira" :default "1" :description "paketin indirileceği depo sırası belirtilir"
  2263. local search = parser:command "ara" :description "paket/talimat/tanım arama işlemi"
  2264. search:argument "arama" :args("+") :description "arama girdisi"
  2265. search:option "-t --talimat" :args(0) :description "talimat araması"
  2266. search:option "-p --dpaket" :args(0) :description "paket araması"
  2267. search:option "-a --tanim" :args(0) :description "tanım araması"
  2268. search:option "--hepsi" :default "1" :description "arama sonuçların hepsinin getirilmesi"
  2269. local info = parser:command "bil" :description "paket bilgi işlemleri"
  2270. info:argument "paket" :args("+") :description "paket girdileri"
  2271. info:option "-g --gerek" :description "gerek bilgileri -gc=çalışma -gd=derleme -gct=ters çalışma -gdt= ters derleme gereklerini verir"
  2272. info:option "--kk" :args(0) :description "paketin kurulu olma durumu"
  2273. info:option "--kdl" :args(0) :description "pakete ait kurulu dosya listesi"
  2274. info:option "--pl" :args(0) :description "pakete ait paylaşım kütüphane listesi"
  2275. info:option "--lg" :args(0) :description "paketin ihtiyaç duyduğu paylaşım kütüphane listesi"
  2276. info:option "--pkd" :args(0) :description "paketin kurulum doğrulaması yapılır"
  2277. local query = parser:command "sor" :description "genel sorgu işlemleri"
  2278. query:option "-L --kpl" :args(0) :description "kurulu paket listesini verir"
  2279. query:option "--hp" :argname "<aranan>" :args(1) :description "arama girdisinin kurulu hangi pakette olduğunu verir"
  2280. query:option "-d --def" :description "def sorguları"
  2281. local script = parser:command "kos" :description "paket için kur/sil/servis koşuk işlemleri"
  2282. script:argument "paket" :args("+") :description "paket girdileri"
  2283. script:option "--baskur" :description "başlama betiğini(servis) kurar"
  2284. script:option "--bassil" :description "başlama betiğini(servis) siler"
  2285. script:option "--kurkos" :description "kurulum sonrası betiklerini çalıştırır"
  2286. script:option "--koskur" :description "kurulum öncesi betiklerini çalıştırır"
  2287. script:option "--silkos" :description "silme sonrası betiklerini çalıştırır"
  2288. script:option "--kossil" :description "silme öncesi betiklerini çalıştırır"
  2289. -- parametrleri tabloya al
  2290. args=parser:parse()
  2291. args_handler()
  2292. -----------------------------------------