mps.lua 77 KB

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