vo2ml.lua 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #!/usr/bin/env slua
  2. --[[
  3. Milis Linux Talimat Hazırlama Destek Betiği
  4. Void Linux template[1] yapısını Milis Linux 2.1 talimat yapısına çevirir.
  5. milisarge@gmail.com 2022
  6. [1] https://github.com/void-linux/void-packages/tree/master/srcpkgs
  7. ]]--
  8. -- Gerekler
  9. -- /usr/milis/mps/static/slua
  10. -- oto tanım çevirici için ceviri awk betiği lazım -https://github.com/soimort/translate-shell
  11. -- Kullanım
  12. -- ./vo2ml.lua paket_ismi
  13. local l5 = require("l5")
  14. local static="/usr/milis/mps/static/"
  15. local cmd = {
  16. http_code=function (link) return (static.."curl -ILs %s"):format(link) end,
  17. http_body=function (progress,link) return (static.."curl %s -L %s"):format(progress,link) end,
  18. }
  19. function string:run()
  20. local handle=io.popen(self)
  21. local result=handle:read('*all')
  22. handle:close()
  23. -- komut çıktısı sonu yeni satır karakterin silinmesi - en sondaki \n
  24. if result:sub(-1) == "\n" then
  25. --result=result:gsub("\n", "")
  26. result=result:sub(1,-2)
  27. end
  28. return result
  29. end
  30. function stat(path)
  31. return l5.lstat3(path)
  32. end
  33. function http_request(link,progress)
  34. local pb="-s"
  35. if progress == "progress" then
  36. pb="--progress-bar"
  37. end
  38. local code=cmd.http_code(link):run()
  39. local body=""
  40. if code:match("200") then
  41. body=cmd.http_body(pb,link):run()
  42. return body,"200"
  43. elseif code:match("404") then
  44. return body,"404"
  45. else
  46. return body,"can't connect"
  47. end
  48. end
  49. --local body, code = http_request(link)
  50. local talimat={
  51. isim="",
  52. surum="",
  53. devir=1,
  54. paketci="milisarge",
  55. grup="kütüphane",
  56. url="",
  57. sha256="",
  58. gerek="",
  59. tanim="",
  60. ekconf="",
  61. dptip="",
  62. kaynak="",
  63. derle="",
  64. pakur="",
  65. }
  66. function _indir(link,kayit)
  67. local body, code = http_request(link)
  68. if body == nil then
  69. body, code = http_request(link)
  70. end
  71. code=tostring(code)
  72. if code:match("connection refused") then
  73. print(code)
  74. elseif code=="404" then
  75. print("not found")
  76. elseif code == "200" then
  77. local f = assert(io.open(kayit, 'wb'))
  78. f:write(body)
  79. f:close();
  80. if stat(kayit) then
  81. print("kaynak: "..link)
  82. return true
  83. else
  84. print("redown..")
  85. _indir(link,kayit);
  86. end
  87. elseif not body then
  88. print("sorunlu link")
  89. else
  90. print("unknw err",code)
  91. end
  92. return false
  93. end
  94. function tprint(tablo)
  95. for key, value in pairs(tablo) do
  96. print (key.. " = "..value)
  97. end
  98. end
  99. function parse(template)
  100. if not stat(template) then return {} end
  101. for line in io.lines(template) do
  102. v,i=line:gsub("^hostmakedepends=", ""); if i ==1 then talimat.gerek=talimat.gerek.." "..v:gsub('%"',"");sonakt="gerek" end
  103. v,i=line:gsub("^makedepends=", ""); if i ==1 then talimat.gerek=talimat.gerek.." "..v:gsub('%"',"");sonakt="gerek" end
  104. v,i=line:gsub("^depends=", ""); if i ==1 then talimat.gerek=talimat.gerek.." "..v:gsub('%"',"");sonakt="gerek" end
  105. v,i=line:gsub("pkgname=", ""); if i ==1 then talimat.isim=v end
  106. v,i=line:gsub("version=", ""); if i ==1 then talimat.surum=v end
  107. v,i=line:gsub("build_wrksrc=", ""); if i ==1 then talimat.arsiv=v end
  108. v,i=line:gsub("wrksrc=", ""); if i ==1 then talimat.arsiv=v end
  109. v,i=line:gsub("homepage=", ""); if i ==1 then talimat.url=v:gsub('%"',"") end
  110. v,i=line:gsub("short_desc=", ""); if i ==1 then talimat.tanim=v:gsub('%"',"") end
  111. --v,i=line:gsub("short_desc+=", ""); if i ==1 then print("short+") end
  112. v,i=line:gsub("checksum=", ""); if i ==1 then talimat.sha256=v:gsub('%"',"");sonakt="sha256" end
  113. v,i=line:gsub("make_build_args=", ""); if i ==1 then talimat.ekconf=v:gsub('%"',"") end
  114. v,i=line:gsub("configure_args=", ""); if i ==1 then talimat.ekconf=v:gsub('%"',"");sonakt="ekconf" end
  115. v,i=line:gsub("build_style=", ""); if i ==1 then talimat.dptip=v end
  116. v,i=line:gsub("distfiles=", ""); if i ==1 then talimat.kaynak=v:gsub('%"',"");;sonakt="kaynak" end
  117. for k,v in line:gmatch("(pre_configure).+") do preconfigure=1;sonakt="" end
  118. if preconfigure==1 and line ~= '}' then talimat.derle=talimat.derle..line.."\n" end
  119. if line == '}' and preconfigure==1 then preconfigure=0;talimat.derle=talimat.derle:gsub("pre_configure%(%)%s%{","") end
  120. for k,v in line:gmatch("(pre_build).+") do prebuild=1;sonakt="" end
  121. if prebuild==1 and line ~= '}' then talimat.derle=talimat.derle..line.."\n" end
  122. if line == '}' and prebuild==1 then prebuild=0;talimat.derle=talimat.derle:gsub("pre_build%(%)%s%{","") end
  123. for k,v in line:gmatch("(do_build).+") do dobuild=1;sonakt="" end
  124. if dobuild==1 and line ~= '}' then talimat.derle=talimat.derle..line.."\n" end
  125. if line == '}' and dobuild==1 then dobuild=0;talimat.derle=talimat.derle:gsub("do_build%(%)%s%{","") end
  126. for k,v in line:gmatch("(do_install).+") do doinstall=1;sonakt="" end
  127. if doinstall==1 and line ~= '}' then talimat.pakur=talimat.pakur..line.."\n" end
  128. if line == '}' and doinstall==1 then doinstall=0;talimat.pakur=talimat.pakur:gsub("do_install%(%)%s%{","") end
  129. for k,v in line:gmatch("(post_install).+") do postinstall=1;sonakt="" end
  130. if postinstall==1 and line ~= '}' then talimat.pakur=talimat.pakur..line.."\n" end
  131. if line == '}' and postinstall==1 then postinstall=0;talimat.pakur=talimat.pakur:gsub("post_install%(%)%s%{","") end
  132. -- boşlukla başlayan satır yakalanması
  133. if line:match('^%s(.*)') then
  134. if sonakt == "gerek" then
  135. talimat[sonakt]=talimat[sonakt].." "..line:gsub('%"',"")
  136. elseif sonakt == "kaynak" or sonakt == "sha256" then
  137. for _, word in ipairs({"short_desc%+=", "hostmakedepends=", "XBPS"}) do
  138. v,i=line:gsub(word, ""); if i ==1 then line="" end
  139. end
  140. talimat[sonakt]=talimat[sonakt]..line.."\n"
  141. elseif sonakt == "ekconf" then
  142. talimat[sonakt]=talimat[sonakt]..line.."\n"
  143. end
  144. sonakt=""
  145. end
  146. end
  147. -- son temizlikler ve değişiklikler
  148. talimat.gerek=talimat.gerek:gsub("-devel","")
  149. talimat.gerek=talimat.gerek:lower()
  150. talimat.kaynak=talimat.kaynak:gsub("homepage","url")
  151. -- eşleştirme
  152. talimat.dptip=talimat.dptip:gsub("gnu%-makefile","gnu")
  153. talimat.dptip=talimat.dptip:gsub("gnu%-configure","gnu")
  154. talimat.dptip=talimat.dptip:gsub("python3%-module","py3")
  155. talimat.kaynak=talimat.kaynak:gsub("pkgname","isim")
  156. talimat.kaynak=talimat.kaynak:gsub("version","surum")
  157. if talimat.arsiv then
  158. talimat.arsiv=talimat.arsiv:gsub("pkgname","isim")
  159. talimat.arsiv=talimat.arsiv:gsub("version","surum")
  160. end
  161. talimat.derle=talimat.derle:gsub("${makejobs}","${MAKEJOBS}")
  162. talimat.pakur=talimat.pakur:gsub("${DESTDIR}","${PKG}")
  163. talimat.pakur=talimat.pakur:gsub("${FILESDIR}","${SRC}")
  164. end
  165. --local link="https://raw.githubusercontent.com/void-linux/void-packages/master/srcpkgs/xfdesktop/template"
  166. --local link="http://localhost:9999/paket.vt"
  167. --local kayit="denem2e2.template"
  168. local void_template="https://raw.githubusercontent.com/void-linux/void-packages/master/srcpkgs/%s/template"
  169. local paket=arg[1]
  170. local link=void_template:format(paket)
  171. local kayit="/tmp/"..paket..".template"
  172. if _indir(link,kayit) then
  173. parse(kayit)
  174. end
  175. --print("--")
  176. --tprint(talimat)
  177. print("-------------------------")
  178. -- tanımın Türkçe'ye oto çevirisi
  179. command="ceviri en:tr '%s' | awk 'NR==3' " .. ' | sed -r "s/\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" '
  180. local handle = io.popen(command:format(talimat.tanim))
  181. local result = handle:read("*a")
  182. handle:close()
  183. if result ~= "" then talimat.tanim=result:gsub("\n","") end
  184. -- talimat dosyasının üretilmesi
  185. talimatd=("/tmp/%s#%s-1"):format(talimat.isim:lower(),talimat.surum)
  186. os.execute(("mkdir -p %s"):format(talimatd))
  187. file = io.open(talimatd.."/talimat", "w")
  188. function fprint(data)
  189. if data == nil then data="" end
  190. file:write(data.."\n")
  191. end
  192. fprint("[paket]")
  193. fprint(("tanim = %s"):format(talimat.tanim))
  194. fprint(("paketci = %s"):format(talimat.paketci))
  195. fprint(("grup = %s"):format(talimat.grup))
  196. fprint(("url = %s"):format(talimat.url))
  197. if talimat.arsiv then
  198. fprint(("arsiv = %s"):format(talimat.arsiv))
  199. end
  200. fprint()
  201. fprint("[gerek]")
  202. fprint(("derleme = %s"):format(talimat.gerek:gsub("^%s", "")))
  203. fprint("calisma =")
  204. fprint()
  205. fprint("[kaynak]")
  206. for s in talimat.kaynak:gmatch("[^\r\n]+") do
  207. fprint(("1 = %s"):format(s))
  208. end
  209. fprint()
  210. fprint("[sha256]")
  211. for s in talimat.sha256:gmatch("[^\r\n]+") do
  212. fprint(("1 = %s"):format(s))
  213. end
  214. fprint()
  215. fprint("[derle]")
  216. for s in talimat.derle:gmatch("[^\r\n]+") do
  217. fprint("betik = "..s:gsub("^%s", ""))
  218. end
  219. if talimat.ekconf ~= "" then fprint(("ekconf = %s"):format(talimat.ekconf)) end
  220. fprint(("tip = %s"):format(talimat.dptip))
  221. fprint()
  222. fprint("[pakur]")
  223. fprint(("tip = %s"):format(talimat.dptip))
  224. for s in talimat.pakur:gmatch("[^\r\n]+") do
  225. fprint("betik = "..s:gsub("^%s", ""))
  226. end
  227. -------------------------------------------------------
  228. print("kayıt: "..talimatd.."/talimat")