vo2ml.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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("homepage=", ""); if i ==1 then talimat.url=v:gsub('%"',"") end
  82. v,i=line:gsub("short_desc=", ""); if i ==1 then talimat.tanim=v:gsub('%"',"") end
  83. v,i=line:gsub("checksum=", ""); if i ==1 then talimat.sha256=v:gsub('%"',"");;sonakt="sha256" end
  84. v,i=line:gsub("make_build_args=", ""); if i ==1 then talimat.ekconf=v:gsub('%"',"") end
  85. v,i=line:gsub("configure_args=", ""); if i ==1 then talimat.ekconf=v:gsub('%"',"");sonakt="ekconf" end
  86. v,i=line:gsub("build_style=", ""); if i ==1 then talimat.dptip=v end
  87. v,i=line:gsub("distfiles=", ""); if i ==1 then talimat.kaynak=v:gsub('%"',"");;sonakt="kaynak" end
  88. for k,v in line:gmatch("(pre_configure).+") do preconfigure=1;sonakt="" end
  89. if preconfigure==1 and line ~= '}' then talimat.derle=talimat.derle..line.."\n" end
  90. if line == '}' and preconfigure==1 then preconfigure=0;talimat.derle=talimat.derle:gsub("pre_configure%(%)%s%{","") end
  91. for k,v in line:gmatch("(pre_build).+") do prebuild=1;sonakt="" end
  92. if prebuild==1 and line ~= '}' then talimat.derle=talimat.derle..line.."\n" end
  93. if line == '}' and prebuild==1 then prebuild=0;talimat.derle=talimat.derle:gsub("pre_build%(%)%s%{","") end
  94. for k,v in line:gmatch("(do_build).+") do dobuild=1;sonakt="" end
  95. if dobuild==1 and line ~= '}' then talimat.derle=talimat.derle..line.."\n" end
  96. if line == '}' and dobuild==1 then dobuild=0;talimat.derle=talimat.derle:gsub("do_build%(%)%s%{","") end
  97. for k,v in line:gmatch("(do_install).+") do doinstall=1;sonakt="" end
  98. if doinstall==1 and line ~= '}' then talimat.pakur=talimat.pakur..line.."\n" end
  99. if line == '}' and doinstall==1 then doinstall=0;talimat.pakur=talimat.pakur:gsub("do_install%(%)%s%{","") end
  100. for k,v in line:gmatch("(post_install).+") do postinstall=1;sonakt="" end
  101. if postinstall==1 and line ~= '}' then talimat.pakur=talimat.pakur..line.."\n" end
  102. if line == '}' and postinstall==1 then postinstall=0;talimat.pakur=talimat.pakur:gsub("post_install%(%)%s%{","") end
  103. -- boşlukla başlayan satır yakalanması
  104. if line:match('^%s(.*)') then
  105. if sonakt == "gerek" then
  106. talimat[sonakt]=talimat[sonakt].." "..line:gsub('%"',"")
  107. elseif sonakt == "kaynak" or sonakt == "sha256" then
  108. talimat[sonakt]=talimat[sonakt]..line.."\n"
  109. elseif sonakt == "ekconf" then
  110. talimat[sonakt]=talimat[sonakt]..line.."\n"
  111. end
  112. sonakt=""
  113. end
  114. end
  115. -- son temizlikler ve değişiklikler
  116. talimat.gerek=talimat.gerek:gsub("-devel","")
  117. talimat.gerek=talimat.gerek:lower()
  118. talimat.kaynak=talimat.kaynak:gsub("homepage","url")
  119. -- eşleştirme
  120. talimat.dptip=talimat.dptip:gsub("gnu%-makefile","gnu")
  121. talimat.dptip=talimat.dptip:gsub("gnu%-configure","gnu")
  122. talimat.kaynak=talimat.kaynak:gsub("pkgname","isim")
  123. talimat.kaynak=talimat.kaynak:gsub("version","surum")
  124. talimat.pakur=talimat.pakur:gsub("${DESTDIR}","${PKG}")
  125. talimat.pakur=talimat.pakur:gsub("${FILESDIR}","${SRC}")
  126. end
  127. --local link="https://raw.githubusercontent.com/void-linux/void-packages/master/srcpkgs/xfdesktop/template"
  128. --local link="http://localhost:9999/paket.vt"
  129. --local kayit="denem2e2.template"
  130. local void_template="https://raw.githubusercontent.com/void-linux/void-packages/master/srcpkgs/%s/template"
  131. local paket=arg[1]
  132. local link=void_template:format(paket)
  133. local kayit="/tmp/"..paket..".template"
  134. if _indir(link,kayit) then
  135. parse(kayit)
  136. end
  137. --print("--")
  138. --tprint(talimat)
  139. print("-------------------------")
  140. -- tanımın Türkçe'ye oto çevirisi
  141. command="ceviri en:tr '%s' | awk 'NR==3' " .. ' | sed -r "s/\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" '
  142. local handle = io.popen(command:format(talimat.tanim))
  143. local result = handle:read("*a")
  144. handle:close()
  145. if result ~= "" then talimat.tanim=result:gsub("\n","") end
  146. -- talimat dosyasının üretilmesi
  147. talimatd=("/tmp/%s#%s-1"):format(talimat.isim:lower(),talimat.surum)
  148. os.execute(("mkdir -p %s"):format(talimatd))
  149. file = io.open(talimatd.."/talimat", "w")
  150. function fprint(data)
  151. if data == nil then data="" end
  152. file:write(data.."\n")
  153. end
  154. fprint("[paket]")
  155. fprint(("tanim = %s"):format(talimat.tanim))
  156. fprint(("paketci = %s"):format(talimat.paketci))
  157. fprint(("grup = %s"):format(talimat.grup))
  158. fprint(("url = %s"):format(talimat.url))
  159. fprint()
  160. fprint("[gerek]")
  161. fprint(("derleme = %s"):format(talimat.gerek:gsub("^%s", "")))
  162. fprint("calisma =")
  163. fprint()
  164. fprint("[kaynak]")
  165. for s in talimat.kaynak:gmatch("[^\r\n]+") do
  166. fprint(("1 = %s"):format(s))
  167. end
  168. fprint()
  169. fprint("[sha256]")
  170. for s in talimat.sha256:gmatch("[^\r\n]+") do
  171. fprint(("1 = %s"):format(s))
  172. end
  173. fprint()
  174. fprint("[derle]")
  175. for s in talimat.derle:gmatch("[^\r\n]+") do
  176. fprint("betik = "..s:gsub("^%s", ""))
  177. end
  178. if talimat.ekconf ~= "" then fprint(("ekconf = %s"):format(talimat.ekconf)) end
  179. fprint(("tip = %s"):format(talimat.dptip))
  180. fprint()
  181. fprint("[pakur]")
  182. fprint(("tip = %s"):format(talimat.dptip))
  183. for s in talimat.pakur:gmatch("[^\r\n]+") do
  184. fprint("betik = "..s:gsub("^%s", ""))
  185. end
  186. -------------------------------------------------------
  187. print("kayıt: "..talimatd.."/talimat")