vo2ml.lua 7.6 KB

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