paket 88 KB

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