paket2 89 KB

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