mps.lua 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860
  1. #!/usr/bin/env lua
  2. -- mps lua kodlaması
  3. -- IMPORT --
  4. local milispath=os.getenv("MILIS_PATH")
  5. if not milispath then milispath="/usr/aylinux" end
  6. local talimatname=os.getenv("TALIMATNAME")
  7. if not talimatname then talimatname=milispath.."/".."talimatname" end
  8. local mps_path=os.getenv("MPS_PATH")
  9. if not mps_path then mps_path=milispath.."/".."mps" end
  10. --package.cpath = package.cpath .. ";"..mps_path.."/lua/?.so"
  11. -- 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/milis/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("not implemented yet")
  90. end
  91. --islem[args.command]["handler"](args)
  92. else
  93. print("not implemented yet")
  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. -- milis dizini yoksa oluşturuyoruz.
  118. if path_exists(milispath) == false then
  119. shell("mkdir -p "..kokdizin..milispath)
  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. -- Milis 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 (mps 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="mps 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 dizin not found!")
  275. local talimatf=talimatd.."/talimat"
  276. assert(path_exists(talimatf),talimatf.." file not found!")
  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="mps 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="mps 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ümd ile derlenmesi gereken sürümd 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("eski sürüm paket 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. -- Milis 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 is not found")
  663. assert(paket:match("kur"),"islem.arsiv.kontrol : paket suffix is not kur")
  664. assert(get_size(paket) ~=0,"islem.arsiv.kontrol : paket size equals zero")
  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. -- Milis 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 is not found")
  811. assert(get_size(icdosya) > 0,"islem.kur.dosya_kontrol : icbilgi size equals zero")
  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="mps 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="mps 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. if input.db then
  1491. islem.sil.only_vt(rpaket)
  1492. else
  1493. islem.sil.job(rpaket)
  1494. end
  1495. end
  1496. end
  1497. -- silmesi onaylanmış paket sayı bilgisi
  1498. -- sistem güncellemede kullanılacak.
  1499. return #remlist
  1500. end
  1501. function islem.sil.job(paket)
  1502. -- tek bir paketi siler
  1503. assert(paket,"islem.sil.paket : paket is nil")
  1504. -- sed "s/^'/\/mnt/" kurulan.s | sed "s/'//"
  1505. -- sil adımları
  1506. -- 0. logger set
  1507. islem.sil.set_logger(paket)
  1508. -- 1. silinecek dosya listesi hazırla
  1509. islem.sil.prepare_list(paket)
  1510. -- 2. silinecekleri filtrele(keeplist)
  1511. islem.sil.filter_list(paket)
  1512. -- 3. kos-sil betiğini kontrol et / çalıştır
  1513. islem.kosuk.kossil(paket)
  1514. -- 4. Dosyaları güvenli! sil ve logla
  1515. islem.sil.uygula(paket)
  1516. -- 5. sil-kos betiğini kontrol et / çalıştır
  1517. islem.kosuk.silkos(paket)
  1518. -- 6. paket veritabanı güncelle sil
  1519. islem.sil.paket_vt(paket)
  1520. -- silmeden sonra ld.so.cache güncellemesi için
  1521. islem.kur.ld_update("sil");
  1522. -- log dosyası kapatılır.
  1523. islem.sil.logger:close();
  1524. -- Silme işlemi sonuç kontrol
  1525. islem.sil.bitis(paket)
  1526. end
  1527. function islem.sil.set_logger(paket)
  1528. -- bu assert mps başına konulabilir
  1529. assert(path_exists(kokdizin..islem.paket.logdir),"islem.sil.set_logger : islem.paket.logdir is not availables, needs mps --ilk")
  1530. assert(path_exists(kokdizin..islem.sil.logdir),"islem.sil.set_logger : islem.sil.logdir is not availables, needs mps --ilk")
  1531. local logfile=kokdizin..islem.sil.logdir..paket..".log"
  1532. islem.sil.logger = assert(io.open(logfile, "w"),"islem.sil.set_logger logfile can not open")
  1533. islem.sil.logger:write(paket.."\t"..os.date("%x %H:%M:%S").."\n");
  1534. islem.sil.logger:write("--------------------------------------\n");
  1535. end
  1536. function islem.sil.bitis(paket)
  1537. -- Silme adımlarının başarılı bir şekilde tamamlandığını log dosyası ile kontrol eder.
  1538. local logfile=kokdizin..islem.sil.logdir..paket..".log"
  1539. assert(path_exists(logfile),"islem.sil.bitis : logfile is not available")
  1540. if not get_content(logfile):match("ERR@R") then
  1541. messages.package_uninstalled:format(paket):yaz(1)
  1542. else
  1543. messages.package_uninstallation_failed:format(paket):yaz(0)
  1544. end
  1545. end
  1546. function islem.sil.prepare_list(paket)
  1547. local sildos=islem.sil.dlistfile:format(kokdizin,paket)
  1548. local _kurulan=kokdizin..islem.paket.vt..paket.."/"..islem.kur.kurulandos
  1549. -- todo!!! silinecek dosyaların başına kök diizn ekleyerek gerçek yollu silineceklerin oluşturulması
  1550. --local komut='sed "s~^\'~%s~g" %s | sed "s/\'//" > %s'
  1551. -- silinecek dosyalardan ' karakterinin kaldirilmasi
  1552. local komut="sed 's/'\\''//g' %s > %s"
  1553. komut=komut:format(_kurulan,sildos)
  1554. shell(komut)
  1555. assert(get_size(sildos) > 0,"islem.sil.prepare_list : del.list is empty");
  1556. local log="prepare_list:\tOK"
  1557. islem.debug.yaz(log)
  1558. islem.sil.logger:write(log.."\n")
  1559. end
  1560. function islem.sil.filter_list(paket)
  1561. -- eğer paket dizin kaydında .silme isimli dosya varsa
  1562. -- o dosya içindeki alt alta sıralı dosyalar silinecekler listesinden elenecektir.
  1563. -- silinecekler başka dosya isimle içindekilerle karşılaştırılıp filtre edilenler silinir.
  1564. local keeplistfile=kokdizin..islem.paket.vt..paket.."/"..islem.sil.keeplist
  1565. local sildos=islem.sil.dlistfile:format(kokdizin,paket)
  1566. local log=""
  1567. if path_exists(keeplistfile) then
  1568. local komut_k='sed "s~^~%s~g" %s > %s'
  1569. komut_k=komut_k:format(kokdizin,keeplistfile,sildos..".keep")
  1570. shell(komut)
  1571. local komut_move="mv %s %s"
  1572. shell(komut_move:format(sildos,sildos.."f"))
  1573. local komut_f="sort %s %s |uniq -u > %s"
  1574. komut_f=komut_f:format(sildos..".f",keeplistfile,sildos)
  1575. shell(komut_f)
  1576. log="filter_list:\tOK"
  1577. else
  1578. log="filter_list:\tPASS"
  1579. end
  1580. islem.debug.yaz(log)
  1581. islem.sil.logger:write(log.."\n")
  1582. end
  1583. function islem.sil.uygula(paket)
  1584. local sildos=islem.sil.dlistfile:format(kokdizin,paket)
  1585. local sil_content=get_content(sildos);
  1586. -- Once tum paket *dosya*lari silinecek
  1587. -- Ardindan klasorler bos mu diye kontrol edilecek
  1588. -- Bos olan klasorler kaldirilacak
  1589. local exist=true
  1590. local delete=true
  1591. local log=""
  1592. local sil_komut="rm -rf %s"
  1593. local ret=nil
  1594. islem.sil.logger:write("---------------\n")
  1595. function smart_delete(file_list, no_check)
  1596. -- smart delete bir doysa+dizin listesi alir
  1597. -- Ilk olarak tum dosyalari kaldirir ve dizinleri arar
  1598. -- Ardindan bos olan dizinler kaldirilir
  1599. -- Son olarak bos olmayan dizinleri return eder
  1600. -- file_list bir string arrayi olmali
  1601. -- no_check bir boolean olmali
  1602. -- eger no_check 1 ise, tum dizinler
  1603. -- bos olup olmasina bakilmadan kalirilacak
  1604. to_remove={
  1605. files={},
  1606. dirs={}
  1607. }
  1608. for dos in file_list:gmatch("[^\r\n]+") do
  1609. file_attr = lfs.attributes(dos)
  1610. if file_attr then
  1611. if file_attr.mode == "file" then
  1612. table.insert(to_remove.files, dos)
  1613. else
  1614. _, count = dos:gsub('/', '/')
  1615. table.insert(to_remove.dirs, {dos, count})
  1616. end
  1617. end
  1618. end
  1619. -- tabloyu dizin hiyerasisine gore sirala
  1620. -- alttaki dizin tabloda uste gelir
  1621. function compare(a,b)
  1622. return a[2] > b[2]
  1623. end
  1624. table.sort(to_remove.dirs, compare)
  1625. -- once tum dosyalari kaldir
  1626. for _,v in pairs(to_remove.files) do
  1627. local result, reason = os.remove(v)
  1628. -- todo!!! dosya silinmemesine karsin error-check yap
  1629. if result then
  1630. else
  1631. end
  1632. end
  1633. nonempty_dirs={}
  1634. -- to_remove.dirs'i iterate et ve bos olan dizinleri kaldir
  1635. -- todo !!! buranın yenilenmesi gerek lfs. linklerde sorunlu.
  1636. for i=1, #to_remove.dirs do
  1637. -- zorla siliniecek dizin kontrolü
  1638. -- __pycache__ gibi, temel dizin adı ile kontrol edilmektedir.
  1639. if has_value(islem.sil.force_remove_dirs,get_basename(to_remove.dirs[i][1])) then
  1640. os.execute("rm -rf "..to_remove.dirs[i][1])
  1641. else
  1642. status, message, code = lfs.rmdir(to_remove.dirs[i][1])
  1643. if status == nil then
  1644. if code == 39 then
  1645. if no_check then
  1646. -- no_check set edilmisse, dizini recursive olarak kaldir
  1647. deletedir(to_remove.dirs[i])
  1648. else
  1649. -- Dizin bos degil, silme!, nonempty_dirs'e ekle
  1650. --if not has_value(islem.sil.force_remove_dirs,get_basename(to_remove.dirs[i][1])) then
  1651. table.insert(nonempty_dirs, to_remove.dirs[i])
  1652. --end
  1653. end
  1654. elseif code == 20 then
  1655. -- bir dizinin linki durumundadır
  1656. -- todo!!! link ise zorla silinecektir. farklı durumlar gözlemlenecek.
  1657. os.execute("rm -f "..to_remove.dirs[i][1])
  1658. else
  1659. -- Hata yakala ve yazdir
  1660. hata_msg="Klasör silinemedi!".."\n"..message..
  1661. hata_msg:yaz(0)
  1662. end
  1663. end
  1664. end
  1665. end
  1666. -- dizinleri recursive silmek icin yardimci function
  1667. function deletedir(dir)
  1668. for file in lfs.dir(dir) do
  1669. local file_path = dir..'/'..file
  1670. if file ~= "." and file ~= ".." then
  1671. if lfs.attributes(file_path, 'mode') == 'file' then
  1672. os.remove(file_path)
  1673. elseif lfs.attributes(file_path, 'mode') == 'directory' then
  1674. deletedir(file_path)
  1675. end
  1676. end
  1677. end
  1678. lfs.rmdir(dir)
  1679. end
  1680. return nonempty_dirs
  1681. end
  1682. -- sildos dosyasindaki entryleri smart_delete function'i ile sil
  1683. protected_dirs = smart_delete(sil_content)
  1684. -- Kullaniciya silinmeyen klasorleri goster
  1685. -- todo!!! bu ozelligi tamamla
  1686. -- kullanicidan input alip sil
  1687. delete_list={}
  1688. if #protected_dirs > 0 then
  1689. messages.confirm_dir_removing_msg:format(sildos_by_user):yaz(3)
  1690. sildos_by_user=islem.sil.dlistfile:format(kokdizin, paket)..".kor"
  1691. sildos_file = io.open(sildos_by_user, "w")
  1692. for i=1, #protected_dirs do
  1693. -- eger protected_dirs te varsa ancak kullanicinin degistirdigi dosyada yoksa
  1694. -- girdinin silinmesi gerekiyor
  1695. local dir ={}
  1696. dir.dir = protected_dirs[i][1]
  1697. dir.level =protected_dirs[i][2]
  1698. dir.children = {}
  1699. for j=i-1, 1, -1 do
  1700. if protected_dirs[j][2] == dir.level + 1 then
  1701. table.insert(dir.children, protected_dirs[j][1])
  1702. end
  1703. end
  1704. for file in lfs.dir(dir.dir) do
  1705. if file ~= "." and file ~= ".." then
  1706. file_path = dir.dir.."/"..file
  1707. if find(dir.children, file_path) < 0 then
  1708. sildos_file:write(file_path.."\n")
  1709. end
  1710. end
  1711. end
  1712. end
  1713. sildos_file:close()
  1714. messages.confirm_dir_removing_info:format(sildos_by_user):yaz(3)
  1715. local entries_from_user = {}
  1716. for line in io.lines(sildos_by_user) do
  1717. print(line)
  1718. table.insert(entries_from_user, line)
  1719. end
  1720. end
  1721. ----------
  1722. islem.sil.logger:write("---------------\n")
  1723. if exist and delete then
  1724. log="sil.uygula: \tOK";
  1725. islem.debug.yaz(log);
  1726. islem.sil.logger:write(log.."\n")
  1727. else
  1728. log="sil.uygula:\tERR@R";
  1729. log:yaz(3);
  1730. islem.sil.logger:write(log.."\n")
  1731. end
  1732. end
  1733. function islem.sil.paket_vt(paket)
  1734. local dizin=kokdizin..islem.paket.vt..paket
  1735. assert(path_exists(dizin),"islem.sil.paket_vt : dizin is not available")
  1736. local log=""
  1737. local komut_vt="rm -rf %s"
  1738. komut_vt=komut_vt:format(dizin)
  1739. shell(komut_vt);
  1740. -- linkin de silinmesi
  1741. shell(komut_vt.."#*");
  1742. if not path_exists(dizin) then
  1743. log="sil.paket_vt:\tOK";
  1744. islem.debug.yaz(log);
  1745. islem.sil.logger:write(log.."\n")
  1746. else
  1747. log="sil.paket_vt:\tERR@R";
  1748. log:yaz(3);
  1749. islem.sil.logger:write(log.."\n")
  1750. end
  1751. end
  1752. function islem.sil.only_vt(paket)
  1753. islem.sil.set_logger(paket)
  1754. islem.sil.paket_vt(paket)
  1755. islem.sil.logger:close()
  1756. islem.sil.bitis(paket)
  1757. end
  1758. ------------------------------
  1759. -- Kur işlemleri
  1760. islem.kur={
  1761. retkey="kur:",
  1762. kurulandos="kurulan",
  1763. dizinler={"boot","etc","usr","opt","var","tools"}, -- paket içi desteklenen dizinler
  1764. usage="mps kur paket_ismi | paket_yolu",
  1765. logdir=islem.paket.logdir.."kur/",
  1766. logger=nil,
  1767. kurkos=true,
  1768. koskur=true,
  1769. otokos=true,
  1770. zorla=false,
  1771. comment=messages.comment_mps_install,
  1772. }
  1773. function islem.kur.agdan(paket)
  1774. assert(paket,"islem.kur.agdan : paket is nil")
  1775. -- 1.çalışma gerekleri tespit edilecek tablo=gerek paket c
  1776. -- islem gerek listesi global olduğu için sıfırlanması gerekir.
  1777. islem.gerek.liste={}
  1778. islem.gerek.list={}
  1779. islem.gerek.job(paket,"c")
  1780. --print(paket,#islem.gerek.liste)
  1781. -- 2.paketvt ler den döngüde paket#surum-devir
  1782. local ret, pk=""
  1783. local kurliste={}
  1784. local pkpath=nil
  1785. -- 3. gereklerin sıralı indirme
  1786. function controller(tsd)
  1787. -- gerekli paket kurulu kontrolü yapılıp indirilir
  1788. local pk,_=tsd:match("([%a%d-_+]+)#+")
  1789. -- paket kurulu ise atlanacak
  1790. if islem.paket.kurulu_kontrol(pk) then
  1791. (messages.package_already_installed..":"..pk):yaz(2);
  1792. else
  1793. ret=islem.paket.pkvt_bilgi(pk)[1]
  1794. -- paket paket veritabanında bulunamaz ise, veritabanı güncellenmelidir.
  1795. if ret == nil then messages.package_not_found_inpkvt:format(pk):yaz(0) end
  1796. -- indirme işlemi
  1797. -- kurliste ye inen/indirilmiş paketin yolunun kaydı
  1798. pkpath=islem.indir.job(ret)
  1799. if pkpath == nil then
  1800. messages.package_dependency_dl_error:format(pk):yaz(3)
  1801. else
  1802. table.insert(kurliste,pkpath)
  1803. end
  1804. end
  1805. end
  1806. -- controller için görev tablosu
  1807. local threads = {}
  1808. function co_adder (tsd)
  1809. -- create coroutine
  1810. local co = coroutine.create(
  1811. function ()
  1812. controller(tsd)
  1813. end)
  1814. -- görev tablosuna işin(thread) eklenmesi
  1815. table.insert(threads, co)
  1816. end
  1817. for _,tsd in ipairs(islem.gerek.liste) do
  1818. -- 3.1 indirilecek size bilgi - kurulacak bilgi verilip onay ile
  1819. -- eski kod için controller i aç dispatcher i kapat.
  1820. --controller(tsd)
  1821. co_adder(tsd)
  1822. end
  1823. function dispatcher()
  1824. while true do
  1825. local n = #threads
  1826. if n == 0 then break end -- no more threads to run
  1827. for i=1,n do
  1828. local status, res = coroutine.resume(threads[i])
  1829. if not res then -- thread finished its task?
  1830. table.remove(threads, i)
  1831. break
  1832. end
  1833. end
  1834. end
  1835. end
  1836. -- multithread kontrol ve indirme işlemi
  1837. dispatcher()
  1838. -- 4.gerekler kurulacak (yerelden kur ile cachedir den)
  1839. for _,pkyol in ipairs(kurliste) do
  1840. -- 4.1 indirilecek size bilgi - kurulacak bilgi verilip onay ile
  1841. islem.kur.yerelden(pkyol)
  1842. end
  1843. end
  1844. function islem.kur.yerelden(paket)
  1845. --print (paket) -- belki bu mps.log a atılabilir/nereden talimatlandığına dair
  1846. -- yerelden gelen paketin mevcut kontrolü
  1847. -- gönderen işlevler yapamazsa
  1848. if not paket then
  1849. messages.package_not_found:format(paket):yaz(0)
  1850. end
  1851. assert(paket ~= "","islem.kur.yerelden : paket is empty string")
  1852. -- print (paket,"yerelden")
  1853. -- adımlar: loglanacak, her işlem adımı log dosyasına atacak
  1854. -- önemli not: pcall ile işlemler uygulanacak, eğer break olursa sistem kaynaklı (ctrl+c vs)
  1855. -- işlem adımı ve onu çağıran süreç job dosyası state kayıt edilecek.
  1856. -- 0. paket arşivi kontrol edilir
  1857. local isim,surum,devir=islem.arsiv.kontrol(paket)
  1858. -- 1. logger set
  1859. islem.kur.set_logger(isim)
  1860. -- 2. paket kurulu kontrol yapılır
  1861. islem.kur.kurulu_kontrol(isim)
  1862. -- 3. /tmp altında geçici bir dizine çıkarılır
  1863. local tempdir=islem.arsiv.cikar(paket)
  1864. -- 4. libgerekler kontrol edilir- ldconfig sor
  1865. islem.shlib.kontrol(tempdir) --/ kontrol altına eksik shlibleri içeren paketler kurulabilir.
  1866. -- 5. hedef kurulum dizininde çakışan/var olan dosya kontrolü
  1867. islem.kur.dosya_kontrol(tempdir)
  1868. -- 6. koşkur varsa çalıştırılır 2.madde?
  1869. islem.kosuk.koskur(tempdir)
  1870. -- 7. geçici dizinden hedef dizin altına kopyalanır
  1871. islem.kur.kopyala(tempdir)
  1872. -- 8. kopyalanan dosyalar VT e yazılır, var/lib/mps/DB altına paketismi
  1873. -- tempdir altında kurulan dosyası, .icbilgi, .ustbilgi, kosuklar, libgerekler, pktlibler
  1874. islem.kur.vt_kayit(tempdir,isim,surum,devir)
  1875. -- 9. mtree ile karşılaştırma doğrulanır
  1876. -- 10. ldconfig güncellemesi
  1877. islem.kur.ld_update_handler(tempdir)
  1878. -- 11. kurkos çalıştırılır
  1879. islem.kosuk.kurkos(tempdir)
  1880. -- 12. otokos çalıştırılır
  1881. islem.kosuk.otokos_kur(tempdir)
  1882. -- 13. temizlik, başarı mesaj...
  1883. islem.kur.clean_tempdir(tempdir)
  1884. -- 14. log dosyası kapatılır.
  1885. islem.kur.logger:close();
  1886. -- 15. Paket kurulum sonucu
  1887. islem.kur.bitis(isim)
  1888. end
  1889. function islem.kur.clean_tempdir(tempdir)
  1890. -- kurma işlemleri bittikten sonra paket içeriğinin
  1891. -- geçici çıkarıldığı tempdir silinir.
  1892. local komut="rm -rf %s"
  1893. komut=komut:format(tempdir)
  1894. shell(komut)
  1895. end
  1896. function islem.kur.bitis(paket)
  1897. -- Kurulum adımlarının başarılı bir şekilde tamamlandığını log dosyası ile kontrol eder.
  1898. local logfile=kokdizin..islem.kur.logdir..paket..".log"
  1899. assert(path_exists(logfile),"islem.kur.bitis : logfile is not available")
  1900. if not get_content(logfile):match("ERR@R") then
  1901. messages.package_installed:format(paket):yaz(1)
  1902. else
  1903. messages.package_installation_failed:format(paket):yaz(0)
  1904. end
  1905. end
  1906. function islem.kur.set_logger(paket)
  1907. -- bu assert mps başına konulabilir
  1908. assert(path_exists(kokdizin..islem.paket.logdir),"islem.kur.set_logger : islem.paket.logdir is not available, needs mps --ilk")
  1909. assert(path_exists(kokdizin..islem.kur.logdir),"islem.kur.set_logger : islem.kur.logdir is not availables, needs mps --ilk")
  1910. local logfile=kokdizin..islem.kur.logdir..paket..".log"
  1911. --print("-",logfile)
  1912. islem.kur.logger = assert(io.open(logfile, "w"),"islem.kur.set_logger logfile can not open")
  1913. islem.kur.logger:write(paket.."\t"..os.date("%x %H:%M:%S").."\n");
  1914. islem.kur.logger:write("--------------------------------------\n");
  1915. end
  1916. function islem.kur.ld_update_handler(tempdir)
  1917. local log=""
  1918. if path_exists(tempdir..islem.paket.metadir..islem.paket.pktlib_dosya)
  1919. or path_exists(tempdir..islem.paket.metadir..islem.shlib.dosya) then
  1920. -- libgerek?(kurulu ise cache edilmiş olmalı), shlib varsa ldconfig edilecek.
  1921. islem.kur.ld_update()
  1922. log="ld_up_handler:\tOK";
  1923. islem.kur.logger:write(log.."\n")
  1924. else
  1925. messages.ld_update_pass:yaz()
  1926. log="ld_up_handler:\tPASS";
  1927. islem.kur.logger:write(log.."\n")
  1928. end
  1929. end
  1930. -- kura mahsus olmasın todo!!!
  1931. function islem.kur.ld_update(oper)
  1932. -- hedef kök dizinde ldconfig varsa güncelleme olur.
  1933. local log=""
  1934. if path_exists(kokdizin.."usr/bin/ldconfig")
  1935. or path_exists(kokdizin.."sbin/ldconfig") then
  1936. --print("ldconfig update edilecek")
  1937. local _cachedos="etc/ld.so.cache"
  1938. local komut1=("rm -f %s%s"):format(kokdizin,_cachedos)
  1939. --print(komut1)
  1940. shell(komut1)
  1941. local komut2=("ldconfig -r %s"):format(kokdizin)
  1942. --print(komut2)
  1943. shell(komut2)
  1944. else
  1945. (messages.ld_update_pass..kokdizin):yaz()
  1946. log="ld_update:\tPASS";
  1947. if oper then
  1948. islem[oper].logger:write(log.."\n")
  1949. else
  1950. islem.kur.logger:write(log.."\n")
  1951. end
  1952. end
  1953. end
  1954. function islem.kur.kopyala(tempdir)
  1955. -- geçici çıkarma dizininden sisteme kopyala işlemi
  1956. -- geçerli dizinler kontrol edilerek kopyalama yapılır
  1957. -- tempdir altındaki dizinleri islem.kur.dizinler ile karşılaştır.
  1958. local dirs=get_dirs(tempdir)
  1959. local kurulandos=tempdir..islem.kur.kurulandos
  1960. assert(dirs,"islem.kur.kopyala : dirs is nil")
  1961. --table.insert(dirs,"sbin")
  1962. local log=""
  1963. for _,dir in ipairs(dirs) do
  1964. if not has_value(islem.kur.dizinler,dir) and dir.."/" ~= islem.paket.metadir then
  1965. (messages.invalid_package_content..dir):yaz(3)
  1966. islem.kur.logger:write(messages.invalid_package_content..dir.."\n")
  1967. end
  1968. end
  1969. local komut=""
  1970. for _,dizin in ipairs(islem.kur.dizinler) do
  1971. if path_exists(tempdir..dizin) then
  1972. komut='cp -v -aflr %s %s | awk \'{split($0,a,"-> "); print a[2]}\' | sed \'s#%s#/#g\' >> %s'
  1973. komut=komut:format(tempdir..dizin,kokdizin,kokdizin,kurulandos)
  1974. shell(komut)
  1975. log="kur.kopyala:\tOK";
  1976. islem.debug.yaz(log)
  1977. islem.kur.logger:write(log.."\n")
  1978. end
  1979. end
  1980. end
  1981. function islem.kur.vt_kayit(tempdir,isim,surum,devir)
  1982. -- sisteme kopyalanan paketin paket veritabanı kaydının yapılması
  1983. -- ve kurulum logunun oluşturulması (adımlar loglanacak)
  1984. assert(isim,"islem.kur.vt_kayit : isim is nil")
  1985. local log=""
  1986. local paket_vt_dizin=kokdizin..islem.paket.vt..isim.."/"
  1987. -- linkin oluşturulması - indeksleme için
  1988. local paket_vt_dizin_link=kokdizin..islem.paket.vt..isim.."#"..surum.."-"..devir
  1989. -- paket_vt dizin oluşturma
  1990. local komut0=("rm -rf %s"):format(paket_vt_dizin)
  1991. shell(komut0)
  1992. local komut1=("mkdir -p %s"):format(paket_vt_dizin)
  1993. local komut_link=("ln -s %s %s"):format(paket_vt_dizin,paket_vt_dizin_link)
  1994. --print(komut1)
  1995. shell(komut1)
  1996. shell(komut_link)
  1997. -- / altındakileri silme engeli
  1998. assert(paket_vt_dizin ~= "/","islem.kur.vt_kayit : paket_vt_dizin must not be /")
  1999. -- paket_vt dizin temizlik
  2000. local komut2=("rm -rf %s*"):format(paket_vt_dizin)
  2001. --print(komut2)
  2002. shell(komut2)
  2003. -- paket.vt içerik kopyalama (tek tek bilgi dosyaları yada file olan her obje)
  2004. -- kurulan dosyası da eklenir, islem.kur içinde tanımlandığı için burda ekliyoruz.
  2005. -- kurulan dosyanın oluşması beklenir, oluşmadıysa sisteme dosya ve dizin kopyalama olmamıştır.
  2006. assert(path_exists(tempdir..islem.kur.kurulandos),"islem.kur.vt_kayit : kurulan file is not available -> no files, dirs copied!!!")
  2007. -- kurulan dosyasının paket kayıt dizine kaydı
  2008. shell(("cp -avf %s %s"):format(tempdir..islem.kur.kurulandos,paket_vt_dizin))
  2009. -- .meta dizini kopyala
  2010. shell(("cp -avf %s %s"):format(tempdir..islem.paket.metadir,paket_vt_dizin))
  2011. -- icbilgi dosyası kopyala
  2012. shell(("cp -avf %s %s"):format(tempdir..islem.icbilgi.dosya,paket_vt_dizin))
  2013. log="kur.vt_kayit:\tOK";
  2014. islem.debug.yaz(log)
  2015. islem.kur.logger:write(log.."\n")
  2016. -- vt_kayıt test edilecek!!!
  2017. end
  2018. function islem.kur.dosya_kontrol(tempdir)
  2019. -- sisteme kopyalanacak paket içeriğinin sistemde çakışan karşılık kontrolü
  2020. -- çakışanlar için strateji belirlenmeli: üzerine yaz, koru vs
  2021. local dosyalar=islem.icbilgi.dosyalar(tempdir)
  2022. assert(dosyalar,"islem.kur.dosya_kontrol : dosyalar is nil")
  2023. local ret=true
  2024. local log=""
  2025. local conflict_files={}
  2026. for _,dosya in ipairs(dosyalar) do
  2027. if path_exists(kokdizin..dosya) then
  2028. (messages.file_already_exists:format(kokdizin..dosya)):yaz(3)
  2029. table.insert(conflict_files,kokdizin..dosya)
  2030. ret=false
  2031. end
  2032. end
  2033. -- handling already exist files
  2034. if not ret and islem.kur.zorla == false then
  2035. if islem.diyalog.onay(messages.confirm_files_removing) then
  2036. -- conflict_files tablosundan dosyalar sıralı şekilde silinir
  2037. for _,dosya in ipairs(conflict_files) do
  2038. shell("rm -f "..dosya)
  2039. end
  2040. log="çakışan_dosya:\tOK";
  2041. else
  2042. -- tempdir i sil çıkış yap
  2043. -- print("koskurdan sonra olmalı çakşm,log da silinmeli!!! not yet")
  2044. -- islem.kur.clean_tempdir(tempdir)
  2045. -- os.exit()
  2046. log="çakışan_dosya:\tOVERRIDE";
  2047. end
  2048. islem.debug.yaz(log);
  2049. else
  2050. log="dosya_kontrol:\tOK";
  2051. islem.debug.yaz(log);
  2052. end
  2053. islem.kur.logger:write(log.."\n")
  2054. end
  2055. function islem.kur.kurulu_kontrol(paket)
  2056. -- sistemde kurulu paket kontrolü
  2057. -- burada kurulu pakete uygulanacak seçenek sorulur
  2058. -- sil/silme
  2059. assert(paket,"islem.kur.kurulu_kontrol : paket is nil")
  2060. local log=""
  2061. if islem.paket.kurulu_kontrol(paket) then
  2062. log=messages.package_already_installed;
  2063. messages.package_already_installed:yaz(0);
  2064. else
  2065. log="kurulu_kontrol:\tOK";
  2066. end
  2067. islem.debug.yaz(log)
  2068. islem.kur.logger:write(log.."\n")
  2069. end
  2070. function islem.kur.job(kur)
  2071. -- dikkat ! sıralı kurmayabilir tablo şeklinde geliyor
  2072. -- işlemlerin logu hazırlanacak.
  2073. for tip,tablo in pairs(kur) do
  2074. -- burası sıralı iş
  2075. if kur[tip] then
  2076. for _,job in ipairs(tablo) do
  2077. islem.kur[tip](job)
  2078. end
  2079. end
  2080. end
  2081. end
  2082. function islem.kur.handler(input)
  2083. -- işlem isminden sonra en az bir parametre olmalıdır.
  2084. if input.kurkos == "0" then islem.kur.kurkos=false end
  2085. if input.koskur == "0" then islem.kur.koskur=false end
  2086. if input.otokos == "0" then islem.kur.otokos=false end
  2087. if input.zorla == true then islem.kur.zorla=true end
  2088. local jobs={
  2089. agdan={},
  2090. yerelden={}
  2091. }
  2092. -- paketin yerel/ağ kaynak tespiti ve ilgili listeye eklenmesi
  2093. function pk_analiz(pkt)
  2094. local _paket=""
  2095. if pkt:match("kur") then
  2096. -- yerelden kurulacak listeye eklenir
  2097. --print("yerelden kurulacak",pkt)
  2098. table.insert(jobs.yerelden,get_abspath(pkt))
  2099. _paket,_,_,_=pkt:match(paket_arsiv_pattern)
  2100. else
  2101. local _talimatd=islem.talimat_bul.job(pkt)
  2102. if _talimatd then
  2103. -- ağdan kurulacak listeye eklenir
  2104. table.insert(jobs.agdan,_talimatd)
  2105. else
  2106. (messages.talimat_not_found..pkt):yaz(0)
  2107. end
  2108. _paket=pkt
  2109. end
  2110. -- tekrar parametresi verildiyse paketi silecek.
  2111. if input.tekrar == true then
  2112. islem.sil.handler({paket={_paket}})
  2113. end
  2114. end
  2115. -- konsoldan girilen paket girdi analiz
  2116. if input.paket then
  2117. for _,pk in ipairs(input.paket) do pk_analiz(pk) end
  2118. end
  2119. -- dosya parametresi içerik girdi analiz
  2120. if input.dosya then
  2121. if path_exists(input.dosya) then
  2122. for pk in (get_content(input.dosya)):gmatch("[^\r\n]+") do
  2123. pk_analiz(pk)
  2124. end
  2125. else
  2126. messages.file_not_found:format(dosya):yaz(0)
  2127. end
  2128. end
  2129. -- handler işlevinin test işlemi
  2130. if input.test then
  2131. for _,v in ipairs(jobs.agdan) do print("a",v) end
  2132. for _,v in ipairs(jobs.yerelden) do print("y",v) end
  2133. else
  2134. -- test yoksa bu işem yapılacak
  2135. islem.kur.job(jobs);
  2136. end
  2137. -- todo!!! işlemlerin logu okunacak
  2138. -- ("işlemlerin logu okunacak"):yaz(2)
  2139. end
  2140. --------------------------------------------
  2141. --------Güncelleme İşlemleri-------------------
  2142. islem.guncelle={
  2143. retkey="guncelle:",
  2144. comment=messages.usage_updating_repos,
  2145. usage="mps guncelle",
  2146. betikdepo={isim="betikdepo",tnm="Betik",path=milispath},
  2147. talimatdepo={isim="talimatdepo",tnm="Git",path=talimatname},
  2148. paketlist={},
  2149. }
  2150. -- işlevler
  2151. function islem.guncelle.handler(input)
  2152. local sira=tonumber(input.sira)
  2153. -- mps güncelleme
  2154. if input.mps then
  2155. islem.guncelle.mps()
  2156. end
  2157. -- talimat depolarının güncelleme
  2158. if input.git then
  2159. islem.guncelle.gitdepo(sira,islem.guncelle.talimatdepo)
  2160. end
  2161. -- betik depolarının güncelleme
  2162. if input.betik then
  2163. islem.guncelle.gitdepo(sira,islem.guncelle.betikdepo)
  2164. end
  2165. -- paketvt depoları güncelleme
  2166. if input.depo then
  2167. islem.guncelle.paketvt(sira)
  2168. end
  2169. -- sistem güncelleme
  2170. if input.sistem then
  2171. islem.guncelle.sistem(input)
  2172. end
  2173. -- paket güncelleme
  2174. if input.paket then
  2175. islem.guncelle.paket(input)
  2176. end
  2177. if not input.mps and not input.git and
  2178. not input.betik and not input.depo and
  2179. not input.sistem and not input.paket then
  2180. islem.guncelle.mps()
  2181. islem.guncelle.gitdepo(sira,islem.guncelle.talimatdepo)
  2182. islem.guncelle.gitdepo(sira,islem.guncelle.betikdepo)
  2183. islem.guncelle.paketvt(sira)
  2184. end
  2185. end
  2186. function islem.guncelle.hesapla()
  2187. local kkomut="find %s -type l | xargs -I {} basename {}"
  2188. kkomut=kkomut:format(kokdizin..islem.paket.vt)
  2189. local k_pak={}
  2190. for line in shell(kkomut):gmatch("[^\r\n]+") do
  2191. local paket,sd=line:match("(.*)#(.*)")
  2192. k_pak[paket]=sd
  2193. end
  2194. --[=====[
  2195. --local pkomut=[[cat %s/paket.vt#* | awk 'BEGIN{FS=" "} {print $1 "#" $2 "-" $3}']]
  2196. pkomut=pkomut:format(kokdizin..islem.paket.cachedir)
  2197. local p_pak={}
  2198. for line in shell(pkomut):gmatch("[^\r\n]+") do
  2199. local paket,sd=line:match("(.*)#(.*)")
  2200. p_pak[paket]=sd
  2201. end
  2202. --]=====]
  2203. -- paket vtlerden ilk bulduğu eşleşen paket bilgisi değeri getirecek
  2204. local pb,psd=""
  2205. for paket,sd in pairs(k_pak) do
  2206. pb=islem.paket.pkvt_bilgi(paket)[1]
  2207. if pb == nil then psd=nil
  2208. else psd=pb.surum.."-"..pb.devir end
  2209. if psd ~= k_pak[paket] then
  2210. islem.guncelle.paketlist[paket]={mevcut=k_pak[paket],guncel=pb}
  2211. end
  2212. end
  2213. --[=====[
  2214. for paket,sd in pairs(k_pak) do
  2215. if p_pak[paket] ~= k_pak[paket] then
  2216. islem.guncelle.paketlist[paket]={mevcut=k_pak[paket],guncel=p_pak[paket]}
  2217. end
  2218. end
  2219. --]=====]
  2220. end
  2221. function islem.guncelle.sistem(input)
  2222. -- test aşamasında
  2223. -- ilk önce talimatname ve paket depo eşitliğine bakılacak
  2224. -- talimat ile paket sürümleri aynı olmak zorundadır yoksa derleyerek üretim gerekir.
  2225. -- bu durum garantilendikten sonra ikili depodan güncelleme tespiti yapılıp sistem güncellenebilir.
  2226. --local tkomut="find %s -name talimat | xargs -I {} dirname {} | xargs -I {} basename {}"
  2227. --tkomut=tkomut:format(milispath)
  2228. ---local t_pak={}
  2229. --for line in shell(tkomut):gmatch("[^\r\n]+") do
  2230. -- table.insert(t_pak, line)
  2231. --end
  2232. -- find /usr/milis/talimatname/ -name talimat | xargs -I {} dirname {} | xargs -I {} basename {}
  2233. -- kurulu paket list
  2234. -- find /var/lib/mps/db -type l | xargs -I {} basename {}
  2235. local esgeclist=input.esgec
  2236. islem.guncelle.hesapla()
  2237. local dppk=""
  2238. for _paket,bilgi in pairs(islem.guncelle.paketlist) do
  2239. if bilgi.guncel == nil then dppk="depoda olmayan paket"
  2240. else dppk=bilgi.guncel.surum.."-"..bilgi.guncel.devir end
  2241. if has_value(esgeclist,_paket) == true then
  2242. print(_paket,"güncellemesi es geçildi.")
  2243. else
  2244. -- güncelleme işlemi - durum sorgulanacaksa işlem yaptırılmaz.
  2245. if input.durum == true then
  2246. -- güncelleme bilgisi
  2247. print(string.format("%-15s %-10s -> %s",_paket,bilgi["mevcut"],dppk))
  2248. else
  2249. islem.guncelle.paket({paket={_paket},ona=input.ona})
  2250. end
  2251. end
  2252. end
  2253. -- not islem.guncelle.paketlist key-value şeklinde # ile length alınamaz
  2254. end
  2255. function islem.guncelle.paket(input)
  2256. -- 1 güncellenecek paket listesi için güncelleme hesaplanacak
  2257. -- 2 guncellenecek paket listesinde yer alıyor mu
  2258. -- 3 paket depodan güncel paketi indir, doğrula
  2259. -- 4 eski paketi kaldır. (geri kurtarma için eski paket depo?)
  2260. -- 5 paketdepo inen yeni paketi kur.
  2261. -- -S ile guncellemeler hesaplanmış olabilir değilse hesaplanacak
  2262. local paketgirdi=input.paket
  2263. if next(islem.guncelle.paketlist) == nil then
  2264. islem.guncelle.hesapla()
  2265. end
  2266. local pb,par,pyol=""
  2267. -- silme onay değişkeni
  2268. local s_onay=0
  2269. -- döngü halinde paket listesindeki paketler güncellenecek.
  2270. for _,paket in ipairs(paketgirdi) do
  2271. if islem.guncelle.paketlist[paket] == nil then
  2272. print(paket,"için güncelleme mevcut değil!")
  2273. else
  2274. pb=islem.guncelle.paketlist[paket]
  2275. if pb.guncel == nil then
  2276. print(paket,pb.mevcut,"depoda olmayan paket")
  2277. else
  2278. print(paket,pb.mevcut,pb.guncel.surum.."-"..pb.guncel.devir)
  2279. islem.indir.handler({paket={paket}})
  2280. par=paf:format(paket,pb.guncel.surum,pb.guncel.devir,pb.guncel.mimari)
  2281. pyol=kokdizin..islem.paket.cachedir.."/"..par
  2282. if path_exists(pyol) then
  2283. s_onay=islem.sil.handler({paket={paket},ona=input.ona})
  2284. if s_onay == 1 and islem.paket.kurulu_kontrol(paket) ~= true then
  2285. --islem.kur.yerelden(pyol)
  2286. -- gerekler tekrar hesaplanacak
  2287. islem.kur.agdan(islem.talimat_bul.job(paket))
  2288. end
  2289. else
  2290. print(pyol,"güncellenecek paket yolu bulunamadı")
  2291. end
  2292. end
  2293. end
  2294. s_onay=0
  2295. end
  2296. --print("paket güncellemesi deneme kullanımındadır!")
  2297. end
  2298. function islem.guncelle.mps()
  2299. -- todo!!! mps commit hash tutulacak oradan commit değer değişimi gösterilecek
  2300. -- değişim yoksa güncelleme yok
  2301. assert(path_exists(mps_path),"mps_path not exist")
  2302. assert(path_exists(mps_path.."/.git"),"invalid git directory");
  2303. ("MPS güncelleniyor:"):yaz(2);
  2304. ("------------------------------------"):yaz(2);
  2305. local komut="cd %s && git reset --hard HEAD && git pull ; chmod +x bin/mps*"
  2306. local ret=shell(komut:format(mps_path));
  2307. -- ret=shell(git_kont:format(repo,tmp,tmp))
  2308. ("------------------------------------"):yaz(2)
  2309. end
  2310. function islem.guncelle.paketvt(sira)
  2311. -- todo!!! eskiden inen paketvt#x ler old a taşınacak
  2312. -- başarılı indirmeler olunca silinecek şekilde ayarlanacak
  2313. -- şu an bağlantı yoksa mevcutu da silimiş oluyor- bağlantı olmadan
  2314. -- paket te inemez olarak kabul edildi.
  2315. -- todo!!! bir önceki sürüm paketler için depo tahsisi ve güncellemelerde geri kurtarma deposu olarak kullanılması?
  2316. local onbellek_depo=kokdizin..islem.paket.cachedir.."/"
  2317. ("Paket veritaban(lar)ı güncelleniyor:"):yaz(2);
  2318. ("------------------------------------"):yaz(2);
  2319. -- paket önbellek depo yoksa oluşturulur.
  2320. if not path_exists(kokdizin..islem.paket.cachedir) then
  2321. local create_cache=("mkdir -p %s"):format(onbellek_depo)
  2322. shell(create_cache)
  2323. end
  2324. -- Eski kalıntı paket.vt# dosyaları temizlenmesi
  2325. local del_old_vts=("rm -f %s%s"):format(onbellek_depo,"paket.vt#*")
  2326. shell(del_old_vts)
  2327. sira=tonumber(sira)
  2328. local pkvt="paket.vt"
  2329. -- işlev içinde işlev paket.vt i indirmek için
  2330. -- paket.vt.gz gibi sıkıştırılmış gerçekleme yapılacak. todo!!!
  2331. function _indir(sunucu,sira)
  2332. -- io.write(sunucu.."/"..pkvt.."\t")
  2333. local link=sunucu.."/"..pkvt
  2334. local body, code = http.request(link)
  2335. code=tostring(code)
  2336. if code:match("connection refused") then
  2337. messages.server_connection_refused:format(sunucu):yaz(3)
  2338. elseif code=="404" then
  2339. messages.paketvt_not_found:yaz(3)
  2340. elseif code == "200" then
  2341. local kayit=onbellek_depo..pkvt.."#"..sira
  2342. local f = assert(io.open(kayit, 'wb'))
  2343. f:write(body)
  2344. f:close();
  2345. -- ("+"):yaz(1);
  2346. --kayit:yaz(2);
  2347. if path_exists(kayit) then
  2348. (link):yaz(1);
  2349. else
  2350. messages.redownloading:format(kayit):yaz(2)
  2351. _indir(sunucu,sira);
  2352. end
  2353. elseif not body then
  2354. (link):yaz(3);
  2355. else
  2356. messages.unknown_error:format(link):yaz(0)
  2357. end
  2358. end
  2359. -- eğer sadece bir paket sunucu güncellenmek istenirse
  2360. if sira > 0 then
  2361. -- sıra aşımlı paket vt güncellenmek istenirse
  2362. if #ayar.sunucu < sira then
  2363. messages.package_db_out_of_order:yaz(0)
  2364. end
  2365. if ayar.sunucu[sira] then
  2366. _indir(ayar.sunucu[sira],sira)
  2367. end
  2368. -- çoklu sunucu güncelleme - sıra 0 ve 0dan küçük ise
  2369. else
  2370. for _sira,sunucu in ipairs(ayar.sunucu) do
  2371. _indir(sunucu,_sira)
  2372. end
  2373. end
  2374. ("------------------------------------"):yaz(2);
  2375. end
  2376. function islem.guncelle.gitdepo(sira,depo)
  2377. -- tip=betikdepo, gitdepo
  2378. -- depo={isim="betikdepo",tnm="Betik",path=milispath}
  2379. -- depo={isim="gitdepo",tnm="Git",path=talimatname}
  2380. -- bin, ayarlar lı betikdepo güncelleme yapılacak todo!!!
  2381. assert(depo,"depo is nil!!!");
  2382. (depo.tnm.." depoları güncelleniyor:"):yaz(2);
  2383. ("------------------------------------"):yaz(2);
  2384. -- iç işlevler
  2385. function do_clone(repo,path)
  2386. local komut="git clone --depth 1 %s %s"
  2387. local ret=shell(komut:format(repo,path))
  2388. end
  2389. function do_pull(path)
  2390. assert(path_exists(path.."/.git"),"invalid git directory")
  2391. local komut="cd %s && git pull"
  2392. local ret=shell(komut:format(path))
  2393. end
  2394. function esitle(repoyol,altdizin,hedef)
  2395. -- todo!!! eşitlenecek dizinden sadece talimat içeren
  2396. -- dizinleri alarak eşitleme yap veya sonda silme
  2397. local komut="cp -rf %s/%s/* %s/"
  2398. if path_exists(repoyol.."/"..altdizin) then
  2399. shell(("mkdir -p %s"):format(hedef))
  2400. shell(komut:format(repoyol, altdizin ,hedef))
  2401. else
  2402. messages.git_repo_subdir_not_found:yaz(0)
  2403. end
  2404. end
  2405. function yedekle(dizin)
  2406. local komut="mv %s %s.ydk"
  2407. assert(path_exists(dizin),dizin.." dizini yok!")
  2408. shell(komut:format(dizin,dizin))
  2409. -- dizin yedeklenerek yeni boş oluşturulur.
  2410. assert(lfs.mkdir(dizin),dizin.." oluşturulamadı.")
  2411. end
  2412. -- yedeklenen dizin güncellenemediğinden geri yedeklenir.
  2413. function geri_yedekle(dizin)
  2414. local komut="mv %s.ydk %s"
  2415. assert(path_exists(dizin..".ydk"),dizin..".ydk dizini yok!")
  2416. shell(komut:format(dizin,dizin))
  2417. end
  2418. -- yedeklenen dizinin silinmesi
  2419. function yedek_sil(dizin)
  2420. local komut="rm -rf %s.ydk"
  2421. assert(path_exists(dizin..".ydk"),dizin..".ydk dizini yok!")
  2422. shell(komut:format(dizin,dizin))
  2423. end
  2424. local _repo=""
  2425. local _repoyol=""
  2426. local duzey=""
  2427. local tmp=shell("mktemp")
  2428. -- git repo mevcut kontrol komut
  2429. local git_kont="git ls-remote -q %s > %s 2>&1;cat %s | head -n1 | awk '{print $1}'"
  2430. -- !!! burası farklı ayar.betikdepo
  2431. for bdepo,repolar in pairs(ayar[depo.isim]) do
  2432. -- !!! burası farklı
  2433. duzey=depo.path.."/"..bdepo
  2434. -- her talimat-betik düzeyinde yedekleme-eşitleme-eskiyi silme yapılacak
  2435. if path_exists(duzey) then
  2436. yedekle(duzey)
  2437. end
  2438. for repo,dizin in pairs(repolar) do
  2439. -- git repo mevcut kontrolü
  2440. local ret=shell(git_kont:format(repo,tmp,tmp))
  2441. io.write(bdepo," ",repo," ",dizin)
  2442. if ret:match("fatal") then
  2443. ("\t-"):yaz(1)
  2444. else
  2445. -- Git işlemleri
  2446. -- repo netde mevcut ise, yerelde yoksa clone varsa pull yapılacak.
  2447. _repo=repo:gsub("https://", "")
  2448. _repo=_repo:gsub("http://", "")
  2449. _repo=_repo:gsub("/", ".")
  2450. print("\t",_repo)
  2451. _repoyol=kokdizin..ayar.repo_dizin.."/".._repo
  2452. if path_exists(_repoyol) then
  2453. do_pull(_repoyol)
  2454. else
  2455. do_clone(repo, _repoyol)
  2456. end
  2457. -- Eşitleme işlemleri
  2458. esitle(_repoyol,dizin,duzey)
  2459. end
  2460. end
  2461. -- sıra-talimat düzeyi işlemler bittikten sonra .ydk düzey silinir.
  2462. if path_exists(duzey..".ydk") then
  2463. if lfs.rmdir(duzey) == true then
  2464. geri_yedekle(duzey)
  2465. else
  2466. yedek_sil(duzey)
  2467. end
  2468. end
  2469. end
  2470. shell(("rm -f %s"):format(tmp));
  2471. ("------------------------------------"):yaz(2);
  2472. end
  2473. -- Mps İşlemleri ----------------------------
  2474. -- -ayar öntanımlı ayarlar yükler/kopyalar
  2475. -- todo!!! mps kos altına alınacak
  2476. islem.ayarla={
  2477. retkey="ayarla:",
  2478. comment=messages.usage_configure,
  2479. usage="mps ayarla",
  2480. }
  2481. function islem.ayarla.handler()
  2482. -- mps için conf.lua yükleme komutu
  2483. local komut="cp -f %s/conf/conf.lua.sablon %s/conf/conf.lua"
  2484. shell(komut:format(mps_path,mps_path))
  2485. end
  2486. ------------------------------------------------------------
  2487. -----------------------------------------
  2488. -- Debug işlemleri
  2489. islem.debug={
  2490. retkey="debug",
  2491. }
  2492. function islem.debug.yaz(log)
  2493. if args.debug then
  2494. if log then
  2495. log:yaz()
  2496. else
  2497. messages.empty_log:yaz(0)
  2498. end
  2499. end
  2500. end
  2501. -----------------------------------------
  2502. ----------------------------------------
  2503. -- Yetkili çalıştırma kontrolü
  2504. authorised_check()
  2505. ---PARAMETRE ANALİZ
  2506. -- komutlar
  2507. -- kur, sil, in, gun, der, bil, ara, sor, kos
  2508. local parser = argparse("mps", "Milis Linux Paket Yöneticisi") :require_command(false)
  2509. --seçili olan komutu tespit etmek için
  2510. parser:command_target("command")
  2511. -- genel seçenekler
  2512. parser:flag "-v" "--version" :description "Sürüm bilgisi gösterir"
  2513. :action(function() print("MPS 2.1.1 - Milis Paket Sistemi milisarge@gmail.com") ;os.exit(0) end)
  2514. parser:option "--renk" :default(1) :description "Çıktının renkli olup olmama durumunu belirler"
  2515. parser:option "--kok" :default "/" :description "Mps işlemleri için hedef kök dizini belirtir"
  2516. parser:option "--ilkds" :args(0) :description "Milis dosya sistemi için hedef kök dizinde ilk yapılandırmaları yapar"
  2517. parser:option "--ilk" :args(0) :description "Mps nin hedef kök dizinde ilk yapılandırmaları yapar"
  2518. parser:flag "--ona" :description "Yapılacak mps işlemi için onay verir"
  2519. parser:flag "--debug" :description "Yapılan işlemlerin ayrıntılı çıktısını verir"
  2520. parser:flag "--test" :description "Yapılan işlemlerin sadece test işlevini çalıştırır"
  2521. -- komut parametreleri
  2522. local install = parser:command "kur" :description "paket kurma işlemi" -- :action(handler)
  2523. install:argument "paket" :args("*") :description "yerel/ağ paket girdileri"
  2524. install:option "-d" "--dosya" :description "dosyadan paketleri kurar"
  2525. install:option "--kurkos" :argname "<0/1>" :default "1" :description "paket kurulum sürecince kurkos betiklerinin çalıştırma durumunu belirler"
  2526. install:option "--koskur" :argname "<0/1>" :default "1" :description "paket kurulum sürecince kurkos betiklerinin çalıştırma durumunu belirler"
  2527. install:option "--otokos" :argname "<0/1>" :default "1" :description "paket kurulum sürecince kurkos betiklerinin çalıştırma durumunu belirler"
  2528. install:option "--zorla" :args(0) :description "zorla kurulum durumunu belirler"
  2529. install:option "--tekrar" :args(0) :description "paketin yeniden kurulur"
  2530. local delete = parser:command "sil" :description "paket silme işlemi"
  2531. delete:argument "paket" :args("*") :description "paket girdileri (abc def ghi)"
  2532. delete:option "-d" "--dosya" :description "dosyadan paketleri siler"
  2533. delete:option "--kksiz" :args(0) :description "kurulu kontrolü yapılmaz"
  2534. delete:option "--db" :args(0) :description "sadece vt kaydı silinir."
  2535. local update = parser:command "gun" :description "güncelleme işlemleri"
  2536. update:option "-M" "--mps" :args(0) :description "mps i günceller"
  2537. update:option "-G" "--git" :args(0) :description "git depoları günceller"
  2538. update:option "-B" "--betik" :args(0) :description "betik depoları günceller"
  2539. update:option "-P" "--depo" :args(0) :description "paket depoları günceller"
  2540. update:option "-S" "--sistem" :args(0) :description "sistemi günceller"
  2541. update:option "--sira" :default "0" :description "depo sırasını belirtilir"
  2542. update:option "--paket" :args("*") :description "ilgili paketi günceller"
  2543. update:option "--esgec" :args("*") :default "{}" :description "esgeçilecek paketleri belirtir"
  2544. update:option "--durum" :args(0) :description "Güncelleme durum bilgisi verir. Güncelleme yapmaz."
  2545. local build = parser:command "der" :description "paket derleme işlemi"
  2546. build:argument "paket" :args("*") :description "paket girdileri (abc def ghi)"
  2547. build:option "-d" "--dosya" :description "dosyadan paketleri derler"
  2548. build:option "--kur" :args(0) :description "derledikten sonra kurar"
  2549. build:option "-t --tek" :args(0) :description "gerek kontrolü yapılmadan tek paket derlenir"
  2550. local fetch = parser:command "in" :description "paket indirme işlemi"
  2551. fetch:argument "paket" :args("*") :description "paket girdileri (abc def ghi)"
  2552. fetch:option "-d" "--dosya" :description "dosyadan paketleri indirir"
  2553. fetch:option "--sira" :default "1" :description "paketin indirileceği depo sırası belirtilir"
  2554. local search = parser:command "ara" :description "paket/talimat/tanım arama işlemi"
  2555. search:argument "arama" :args("+") :description "arama girdisi"
  2556. search:option "-t --talimat" :args(0) :description "talimat araması"
  2557. search:option "-a --tanim" :args(0) :description "tanım araması"
  2558. search:option "--hepsi" :default "1" :description "talimat aramada hepsinin getirilmesi"
  2559. local info = parser:command "bil" :description "paket bilgi işlemleri"
  2560. info:argument "paket" :args("+") :description "paket girdileri"
  2561. info:option "-g --gerek" :description "gerek bilgileri -gc=çalışma -gd=derleme -gct=ters çalışma -gdt= ters derleme gereklerini verir"
  2562. info:option "--kk" :args(0) :description "paketin kurulu olma durumu"
  2563. info:option "--kdl" :args(0) :description "pakete ait kurulu dosya listesi"
  2564. info:option "--pl" :args(0) :description "pakete ait paylaşım kütüphane listesi"
  2565. info:option "--lg" :args(0) :description "paketin ihtiyaç duyduğu paylaşım kütüphane listesi"
  2566. info:option "--pkd" :args(0) :description "paketin kurulum doğrulaması yapılır"
  2567. local query = parser:command "sor" :description "genel sorgu işlemleri"
  2568. query:option "-L --kpl" :args(0) :description "kurulu paket listesini verir"
  2569. query:option "--dpl" :args(0) :description "depolardaki paket listesini verir"
  2570. query:option "--tpl" :args(0) :description "temel paket listesini verir"
  2571. query:option "--hp" :argname "<aranan>" :args(1) :description "arama girdisinin kurulu hangi pakette olduğunu verir"
  2572. local script = parser:command "kos" :description "paket için kur/sil/servis koşuk işlemleri"
  2573. script:argument "paket" :args("+") :description "paket girdileri"
  2574. script:option "--baskur" :description "başlama betiğini(servis) kurar"
  2575. script:option "--bassil" :description "başlama betiğini(servis) siler"
  2576. script:option "--kurkos" :description "kurulum sonrası betiklerini çalıştırır"
  2577. script:option "--koskur" :description "kurulum öncesi betiklerini çalıştırır"
  2578. script:option "--silkos" :description "silme sonrası betiklerini çalıştırır"
  2579. script:option "--kossil" :description "silme öncesi betiklerini çalıştırır"
  2580. -- parametrleri tabloya al
  2581. args=parser:parse()
  2582. args_handler()
  2583. -----------------------------------------