kurulum.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QProgressBar, QMessageBox, qApp
  2. from PyQt5.QtCore import QTimer, QThread
  3. from PyQt5.QtGui import QPixmap
  4. import os, time
  5. class Kurulum(QWidget):
  6. def __init__(self, ebeveyn=None):
  7. super(Kurulum, self).__init__(ebeveyn)
  8. self.e = ebeveyn
  9. kutu = QVBoxLayout()
  10. kutu.setContentsMargins(0,0,0,0)
  11. self.setLayout(kutu)
  12. self.slayt_label = QLabel()
  13. self.slayt_label.setFixedSize(950,475)
  14. kutu.addWidget(self.slayt_label)
  15. self.bilgi_label = QLabel()
  16. kutu.addWidget(self.bilgi_label)
  17. self.surec_cubugu = QProgressBar()
  18. kutu.addWidget(self.surec_cubugu)
  19. def slaytci(self):
  20. self.slaytlar = os.listdir("slaytlar")
  21. self.slaytlar.sort()
  22. self.bulunulan_slayt = 1
  23. self.slayt_sayisi = len(self.slaytlar)
  24. self.slayt_label.setPixmap(QPixmap("slaytlar/" + self.slaytlar[0]))
  25. self.zaman = QTimer(self)
  26. self.zaman.setInterval(30000)
  27. self.zaman.timeout.connect(self.slay_degistir)
  28. self.zaman.start()
  29. def slay_degistir(self):
  30. self.bulunulan_slayt += 1
  31. if self.bulunulan_slayt > self.slayt_sayisi:
  32. self.bulunulan_slayt = 1
  33. self.slayt_label.setPixmap(QPixmap("slaytlar/"+self.slaytlar[self.bulunulan_slayt-1]))
  34. def showEvent(self, event):
  35. self.e.setWindowTitle(self.e.d[self.e.s_d]["Milis Linux Yükleniyor"])
  36. self.slaytci()
  37. kurulum = kurulumThread(self)
  38. kurulum.start()
  39. class kurulumThread(QThread):
  40. CANLI_KULL="atilla"
  41. canli_kull_yol="/etc/canli_kullanici"
  42. if os.path.exists(canli_kull_yol):
  43. CANLI_KULL=open(canli_kull_yol,"r").read()
  44. CANLI_KULL=CANLI_KULL.strip()
  45. else:
  46. print ("canlı kullanıcını belirten dosya bulunamadı.")
  47. qApp.closeAllWindows()
  48. def __init__(self, ebeveyn=None):
  49. super(kurulumThread, self).__init__(ebeveyn)
  50. self.f = ebeveyn
  51. self.e = self.f.e
  52. def run(self):
  53. self.e.geri_dugme.setDisabled(True)
  54. self.e.ileri_dugme.setDisabled(True)
  55. kbolum = self.e.milis_ayarlar["disk_bolum"]
  56. kformat = self.e.milis_ayarlar["disk_format"]
  57. kbaglam = "/mnt"
  58. ktakas = self.e.milis_ayarlar["disk_takasbolum"]
  59. kisim = self.e.milis_ayarlar["kullanici_adi"]
  60. kuisim = self.e.milis_ayarlar["gercek_ad"]
  61. ksifre = self.e.milis_ayarlar["giris_sifresi"]
  62. krootsifre = self.e.milis_ayarlar["admin_sifresi"]
  63. kotogiris = self.e.milis_ayarlar["otomatik_giris"]
  64. kgrubkur = self.e.milis_ayarlar["grub-kur"]
  65. kdil = self.e.milis_ayarlar["dil"]
  66. kzaman = self.e.milis_ayarlar["konum"]
  67. bilgisayar_adi = self.e.milis_ayarlar["bilgisayar_adi"]
  68. self.f.bilgi_label.setText(self.e.d[self.e.s_d]["Değişiklikler Diske Uygulanıyor..."])
  69. if self.e.disk:
  70. try:
  71. self.e.disk.commit()
  72. except:
  73. pass
  74. if kformat:
  75. self.f.surec_cubugu.setValue(0)
  76. self.f.bilgi_label.setText(self.e.d[self.e.s_d]["Diskler Formatlanıyor..."])
  77. self.bolumFormatla(kbolum)
  78. if ktakas != "":
  79. self.f.surec_cubugu.setValue(0)
  80. self.f.bilgi_label.setText(self.e.d[self.e.s_d]["Takas Alanı Ayarlanıyor..."])
  81. self.takasAyarla(ktakas)
  82. self.f.surec_cubugu.setValue(0)
  83. self.f.bilgi_label.setText(kbolum + self.e.d[self.e.s_d][" bölümü "] + kbaglam + self.e.d[self.e.s_d][" bağlamına bağlanıyor..."])
  84. self.bolumBagla(kbolum, kbaglam)
  85. self.f.surec_cubugu.setValue(0)
  86. self.f.bilgi_label.setText(self.e.d[self.e.s_d]["Kullanıcı Oluşturuluyor..."])
  87. self.kullaniciOlustur(kuisim, kisim, ksifre, krootsifre)
  88. self.f.surec_cubugu.setValue(0)
  89. self.f.bilgi_label.setText(self.e.d[self.e.s_d]["Sistem Kopyalanıyor..."])
  90. self.sistemKopyala(kbaglam)
  91. self.f.surec_cubugu.setValue(0)
  92. self.f.bilgi_label.setText(self.e.d[self.e.s_d]["kişisel ayarlar oluşturuluyor..."])
  93. self.kisiselOlustur(kbaglam, kdil, kzaman, kotogiris, kisim, bilgisayar_adi)
  94. self.f.surec_cubugu.setValue(0)
  95. self.f.bilgi_label.setText(self.e.d[self.e.s_d]["initrd oluşturuluyor..."])
  96. self.initrdOlustur(kbaglam)
  97. if kgrubkur:
  98. self.f.surec_cubugu.setValue(0)
  99. self.f.bilgi_label.setText(self.e.d[self.e.s_d]["Grub Kuruluyor..."])
  100. self.grubKur(kbolum, kbaglam)
  101. self.f.surec_cubugu.setValue(0)
  102. self.bolumCoz(kbolum)
  103. self.e.asama_degistir(8)
  104. def bolumFormatla(self, hedef):
  105. komut = "umount -l " + hedef
  106. self.f.bilgi_label.setText(komut)
  107. if os.path.exists(hedef):
  108. os.system(komut)
  109. self.f.surec_cubugu.setValue(50)
  110. komut2 = "mkfs.ext4 -F " + hedef
  111. try:
  112. os.system(komut2)
  113. self.f.surec_cubugu.setValue(100)
  114. except OSError as e:
  115. QMessageBox.warning(self, self.e.d[self.e.s_d]["Hata"], str(e))
  116. qApp.closeAllWindows()
  117. self.f.bilgi_label.setText(hedef + self.e.d[self.e.s_d][" disk bölümü formatlandı."])
  118. else:
  119. QMessageBox.warning(self, self.e.d[self.e.s_d]["Hata"], self.e.d[self.e.s_d]["Disk bulunamadı. Program kapatılacak."])
  120. qApp.closeAllWindows()
  121. def takasAyarla(self, bolum):
  122. self.f.bilgi_label.setText("mkswap " + bolum)
  123. os.system("mkswap " + bolum)
  124. self.f.bilgi_label.setText(
  125. 'echo "UUID=`lsblk -ln -o UUID ' + bolum + '` none swap sw 0 0" | tee -a /etc/fstab')
  126. os.system('echo "UUID=`lsblk -ln -o UUID ' + bolum + '` none swap sw 0 0" | tee -a /etc/fstab')
  127. def bolumBagla(self, hedef, baglam):
  128. komut = "mount " + hedef + " " + baglam
  129. try:
  130. os.system(komut)
  131. self.f.surec_cubugu.setValue(100)
  132. except OSError as e:
  133. QMessageBox.warning(self, self.e.d[self.e.s_d]["Hata"], str(e))
  134. qApp.closeAllWindows()
  135. self.f.bilgi_label.setText(hedef + " " + baglam + self.e.d[self.e.s_d][" altına bağlandı."])
  136. def toplamBoyutTespit(self, liste):
  137. self.toplamBoyut = []
  138. for i in liste:
  139. if os.path.exists("/" + i):
  140. komut = "du -s /" + i
  141. donut_ = self.e.komutCalistirFonksiyon(komut)
  142. donut = donut_.split("\n")
  143. boyut_ = donut[len(donut) - 2]
  144. boyut = boyut_.split("\t")
  145. self.toplamBoyut.append(int(boyut[0]))
  146. def kullaniciOlustur(self, uzun_isim, kullisim, kullsifre, rootsifre):
  147. uzun_isim = uzun_isim.replace(' ', '_')
  148. os.system("kopar " + uzun_isim + " " + kullisim)
  149. self.f.surec_cubugu.setValue(20)
  150. os.system('echo -e "' + kullsifre + '\n' + kullsifre + '" | passwd ' + kullisim)
  151. os.system('echo -e "' + rootsifre + '\n' + rootsifre + '" | passwd root')
  152. self.f.surec_cubugu.setValue(40)
  153. ayar_komut = "cp -rf /home/"+self.CANLI_KULL+"/.config /home/"+kullisim
  154. os.system(ayar_komut)
  155. self.f.surec_cubugu.setValue(60)
  156. ayar_komut2 = "cp -r /root/.xinitrc /home/" + kullisim + "/"
  157. os.system(ayar_komut2)
  158. self.f.surec_cubugu.setValue(80)
  159. #saat_komut = "saat_ayarla_tr"
  160. #os.system(saat_komut)
  161. self.f.surec_cubugu.setValue(100)
  162. self.f.bilgi_label.setText(kullisim + self.e.d[self.e.s_d][" kullanıcısı başarıyla oluşturuldu."])
  163. def sistemKopyala(self, baglam):
  164. os.system("clear")
  165. komut1 = "rm -rf /root/Masaüstü/kurulum.desktop"
  166. komut2 = "rm -rf /root/Desktop/kurulum.desktop"
  167. komut3 = "umount -l /home/"+self.CANLI_KULL+"/.gvfs"
  168. os.system(komut1)
  169. os.system(komut2)
  170. os.system(komut3)
  171. self.f.bilgi_label.setText(self.e.d[self.e.s_d]["Dizinler kopyalanmaya başlanıyor..."])
  172. dizinler = ["bin", "boot", "home", "lib", "sources", "usr", "depo", "etc", "lib64", "opt", "root", "sbin","var"]
  173. yenidizinler = ["srv", "proc", "tmp", "mnt", "sys", "run", "dev", "media"]
  174. self.toplamBoyutTespit(dizinler)
  175. self.baglam = baglam
  176. self.progressDurum = True
  177. progresThread = progressAyarciSinif(self)
  178. progresThread.start()
  179. self.dizinSirasi = 0
  180. mikdiz = len(dizinler)
  181. for dizin in dizinler:
  182. self.kopyalanacakDizinAdi = dizin
  183. self.dizinSirasi += 1
  184. self.f.bilgi_label.setText(str(self.dizinSirasi) + "/" + str(mikdiz) +" "+ dizin + self.e.d[self.e.s_d][" kopyalanıyor..."])
  185. komut = "rsync --delete -axHAWX --numeric-ids /" + dizin + " " + baglam + " --exclude /proc"
  186. os.system(komut)
  187. qApp.processEvents()
  188. self.f.surec_cubugu.setValue(0)
  189. self.f.bilgi_label.setText(self.e.d[self.e.s_d]["Yeni Dizinler Oluşturuluyor..."])
  190. self.progressDurum = False
  191. i = 0
  192. mikdiz = len(yenidizinler)
  193. for ydizin in yenidizinler:
  194. i += 1
  195. komut = "mkdir -p " + baglam + "/" + ydizin
  196. os.system(komut)
  197. yuzde = str(round(i / mikdiz, 2))[2:]
  198. if len(yuzde) == 1:
  199. yuzde = yuzde + "0"
  200. self.f.surec_cubugu.setValue(int(yuzde))
  201. self.f.bilgi_label.setText(dizin + self.e.d[self.e.s_d][" kopyalandı."])
  202. qApp.processEvents()
  203. def kisiselOlustur(self, hedef, dil, zaman, otogiris, isim, bilgisayar_adi):
  204. bolge=zaman.split("/")[0]
  205. yer=zaman.split("/")[1]
  206. lokal_ayarlar=open("/tmp/locale.conf","w")
  207. icerik="LC_ALL="+dil+" \n"
  208. icerik+="LANG="+dil+" \n"
  209. icerik+="LANGUAGE="+dil
  210. lokal_ayarlar.write(icerik)
  211. lokal_ayarlar.close()
  212. os.system("cp /usr/share/zoneinfo/"+bolge+"/"+yer+" " + hedef + "/etc/localtime")
  213. os.system("mount --bind /dev " + hedef + "/dev")
  214. self.f.surec_cubugu.setValue(25)
  215. os.system("mount --bind /sys " + hedef + "/sys")
  216. self.f.surec_cubugu.setValue(50)
  217. os.system("mount --bind /proc " + hedef + "/proc")
  218. os.system("mount --bind /run " + hedef + "/run")
  219. self.f.surec_cubugu.setValue(75)
  220. os.system("cp -rf /tmp/locale.conf " + hedef + "/etc/")
  221. komut_skel="cp -rf /run/initramfs/live/updates/home/"+self.CANLI_KULL+"/* "+ hedef + "/etc/skel/"
  222. print("komut_koş:",komut_skel)
  223. komut_evdizin="cp -rf /run/initramfs/live/updates/home/"+self.CANLI_KULL+"/.* "+ hedef + "/home/"+isim+"/"
  224. print("komut_koş:",komut_evdizin)
  225. os.system(komut_evdizin)
  226. os.system('chroot ' + hedef + ' rm -rf /home/'+self.CANLI_KULL)
  227. os.system('chroot ' + hedef + ' rm -rf /root/bin/canli_kullanici.sh')
  228. os.system('chroot ' + hedef + ' rm -rf /etc/canli_kullanici')
  229. os.system('chroot ' + hedef + ' rm -rf /opt/Milis-Yukleyici')
  230. os.system('chroot ' + hedef + ' rm -rf '+self.canli_kull_yol)
  231. os.system('chroot ' + hedef + ' rm -rf /root/Desktop/kurulum.desktop')
  232. os.system('chroot ' + hedef + ' rm -rf /home/'+isim+'/Desktop/kurulum.desktop')
  233. os.system('chroot ' + hedef + ' rm -rf /root/Masaüstü/kurulum.desktop')
  234. os.system('chroot ' + hedef + ' rm -rf /home/'+isim+'/Masaüstü/kurulum.desktop')
  235. os.system('chroot ' + hedef + ' rm -rf /root/Masaüstü/milis-kur.desktop')
  236. os.system('chroot ' + hedef + ' userdel '+self.CANLI_KULL)
  237. os.system('chroot ' + hedef + ' rm /etc/shadow- /etc/gshadow- /etc/passwd- /etc/group- ')
  238. os.system('chroot ' + hedef + ' sed -i "/^'+self.CANLI_KULL+'/d" /etc/security/opasswd ')
  239. #os.system('chroot ' + hedef + ' cp /etc/slim.conf.orj /etc/slim.conf ')
  240. os.system('chroot ' + hedef + ' cp /etc/lightdm/lightdm.conf.orj /etc/lightdm/lightdm.conf ')
  241. #y
  242. os.system("rm -rf "+hedef+"/home/"+isim+"/Desktop")
  243. #y
  244. dil_oz=dil.split(".")[0]
  245. os.system('chroot ' + hedef + ' su - '+isim+' -c "echo '+dil_oz+' > /home/'+isim+'/.config/user-dirs.locale" ')
  246. if dil_oz == "tr_TR":
  247. os.system("cp /opt/user-dirs.dirs "+hedef+"/home/"+isim+"/.config/")
  248. os.system('chroot ' + hedef + ' su - '+isim+' -c "xdg-user-dirs-update --force" ')
  249. os.system("mv "+hedef+"/home/"+isim+"/Downloads "+hedef+"/home/"+isim+"/İndirilenler" )
  250. else:
  251. os.system('chroot ' + hedef + ' su - '+isim+' -c "xdg-user-dirs-update --force" ')
  252. os.system('chroot ' + hedef + ' rm -rf /opt/user-dirs.dir')
  253. os.system('chroot ' + hedef + ' chown '+isim+':'+isim+' -R /home/'+isim)
  254. os.system('chroot ' + hedef + ' setfacl -m u:'+isim+':rw /dev/snd/* ')
  255. if otogiris is True:
  256. os.system('chroot ' + hedef + ' sed -i s/"#autologin-user .*"/"autologin-user='+isim+'/" /etc/lightdm/lightdm.conf')
  257. os.system('chroot ' + hedef + ' sed -i s/"#autologin-user-timeout .*"/"autologin-user-timeout=0/" /etc/lightdm/lightdm.conf')
  258. # hostname'nin hosts içine eklenmesi
  259. os.system('echo "127.0.0.1 '+bilgisayar_adi+'" >> '+hedef+'/etc/hosts')
  260. os.system('sed -i -e "s|HOSTNAME=.*|HOSTNAME="'+bilgisayar_adi+'"|g" '+hedef+'/etc/sysconfig/network')
  261. self.f.surec_cubugu.setValue(100)
  262. self.f.bilgi_label.setText(self.e.d[self.e.s_d]["kişisel ayarlar oluşturuldu"])
  263. def initrdOlustur(self, hedef):
  264. self.f.surec_cubugu.setValue(75)
  265. os.system('chroot ' + hedef + ' rm -f /boot/initramfs')
  266. os.system('chroot ' + hedef + ' rm -f /boot/kernel')
  267. #os.system("cp /run/initramfs/live/boot/kernel "+hedef+"/boot/kernel-$(uname -r)")
  268. os.system("cp /boot/kernel-* "+hedef+"/boot/")
  269. os.system('chroot ' + hedef + ' dracut --no-hostonly --add-drivers "ahci" -f /boot/initramfs')
  270. os.system('chroot ' + hedef + ' ln -s /boot/kernel-* /boot/kernel')
  271. self.f.surec_cubugu.setValue(100)
  272. self.f.bilgi_label.setText(self.e.d[self.e.s_d]["initrd oluşturuldu"])
  273. def grubKur(self, hedef, baglam):
  274. hedef = hedef[:-1]
  275. os.system("cp -f /root/bin/tamir_grub_plymouth "+baglam+"/root/bin/")
  276. os.system("chroot "+baglam+" tamir_grub_plymouth")
  277. if hedef == "/dev/mmcblk0": # SD kart'a kurulum fix
  278. os.system('chroot ' + baglam + 'grub-install /dev/mmcblk0')
  279. # os.system("grub-install --boot-directory="+baglam+"/boot /dev/mmcblk0")
  280. self.f.surec_cubugu.setValue(100)
  281. else:
  282. # os.system("grub-install --boot-directory="+baglam+"/boot " + hedef)
  283. os.system('chroot ' + baglam + ' grub-install ' + hedef)
  284. self.f.surec_cubugu.setValue(50)
  285. os.system("chroot " + baglam + " grub-mkconfig -o /boot/grub/grub.cfg")
  286. self.f.surec_cubugu.setValue(100)
  287. self.f.bilgi_label.setText(self.e.d[self.e.s_d]["Grub Kuruldu."])
  288. def bolumCoz(self, hedef):
  289. komut = "umount -l " + hedef
  290. try:
  291. os.system(komut)
  292. except OSError as e:
  293. QMessageBox.warning(self, self.e.d[self.e.s_d]["Hata"], str(e))
  294. qApp.closeAllWindows()
  295. self.f.surec_cubugu.setValue(100)
  296. self.f.bilgi_label.setText(hedef + self.e.d[self.e.s_d][" çözüldü."])
  297. class progressAyarciSinif(QThread):
  298. def __init__(self, ebeveyn=None):
  299. super(progressAyarciSinif, self).__init__(ebeveyn)
  300. self.e = ebeveyn
  301. self.f = self.e.f
  302. def run(self):
  303. while self.e.progressDurum:
  304. self.guncelle()
  305. time.sleep(1)
  306. def guncelle(self):
  307. boyut = self.boyutTespit()
  308. toplamBoyut = self.e.toplamBoyut[self.e.dizinSirasi - 1]
  309. if boyut < toplamBoyut:
  310. yuzde = str(round(boyut / toplamBoyut, 2))[2:]
  311. if len(yuzde) == 1:
  312. yuzde = yuzde + "0"
  313. self.f.surec_cubugu.setValue(int(yuzde))
  314. else:
  315. self.f.surec_cubugu.setValue(100)
  316. def boyutTespit(self):
  317. try:
  318. komut = "du -s " + self.e.baglam + "/" + self.e.kopyalanacakDizinAdi
  319. donut_ = self.e.e.komutCalistirFonksiyon(komut)
  320. donut = donut_.split("\n")
  321. boyut_ = donut[len(donut) - 2]
  322. boyut = boyut_.split("\t")
  323. return int(boyut[0])
  324. except:
  325. return 0