mirror of
https://gitlab.com/JKANetwork/JKArch.git
synced 2026-02-23 05:23:46 +01:00
122 lines
3.6 KiB
Python
122 lines
3.6 KiB
Python
#!/usr/bin/python3
|
|
## This script requires ArchLinux, reflector, python3 and python-pythondialog
|
|
|
|
###### THIS SCRIPT NOT WORKS, ITS A TRY, THANKS ######
|
|
print ('\033[91m'+"Dont run this."+'\033[0m')
|
|
import sys; sys.exit(0)
|
|
|
|
import os, subprocess
|
|
from dialog import Dialog
|
|
dialog = Dialog(dialog="dialog")
|
|
FNULL = open(os.devnull, 'w')
|
|
|
|
# Import colors for printing
|
|
class bcolors:
|
|
PNK = '\033[95m' # Pink
|
|
BLU = '\033[94m' # Blue
|
|
GRE = '\033[92m' # Green
|
|
YEL = '\033[93m' # Yellow
|
|
RED = '\033[91m' # Red
|
|
END = '\033[0m' # Default?
|
|
|
|
def disable(self):
|
|
self.PNK = ''
|
|
self.BLU = ''
|
|
self.GRE = ''
|
|
self.YEL = ''
|
|
self.RED = ''
|
|
self.END = ''
|
|
|
|
# Function to pause program to wait for the user
|
|
def pause():
|
|
input('Press <ENTER> to continue')
|
|
|
|
# Exec command, returns status of command
|
|
def execC(command,out="",err=""):
|
|
#Example: execC('ls -l')
|
|
if out == "" and err == "":
|
|
return subprocess.call(command, shell=True)
|
|
elif out != "" and err == "":
|
|
return subprocess.call(command, shell=True, stdout=out)
|
|
elif out != "" and err != "":
|
|
return subprocess.call(command, shell=True, stdout=out, stderr=err)
|
|
|
|
# This funcion clears screen
|
|
def clear():
|
|
os.system('cls' if os.name == 'nt' else 'clear')
|
|
|
|
# This funcion show a "dialog-like" message
|
|
def mostrardialog(title,msg):
|
|
#Example: mostrardialog("Titulo","Mensaje")
|
|
dialog.set_background_title("JKArch installer")
|
|
res = dialog.msgbox(msg, title=title)
|
|
clear()
|
|
return res
|
|
|
|
# This function shows a yesnobox that return a dialog.OK or dialog.CANCEL
|
|
def yesnobox(msg):
|
|
#Example: response = yesnobox("¿Estás de acuerdo?")
|
|
dialog.set_background_title("JKArch installer")
|
|
res = dialog.yesno(msg)
|
|
clear()
|
|
return res
|
|
|
|
def menudialog(title,options):
|
|
#Example: res = menudialog("Elige",[("Li","Linux","W","Windows")])
|
|
code, tag = dialog.menu("Some text that will be displayed above the menu entries", choices=options)
|
|
clear()
|
|
return tag
|
|
|
|
# This function runs a command and shows result. Also can be silent or not silent
|
|
# multicmd is 0 as unique, 1 as first, 2 as middle, and 3 as last
|
|
# runas can be sudo, chroot, and chuser
|
|
# If silent = 0 -> show all; 1 -> silent command; 2 -> Output good ever (And silent)
|
|
def comm(msg,silent,runas,command,multicmd=0):
|
|
#Example: comm("Directory list",0,"sudo","ls -l")
|
|
if runas == "chroot":
|
|
command="chroot /mnt /bin/bash -c \""+command+"\""
|
|
elif runas == "chuser":
|
|
command="chroot /mnt /bin/bash -c \"su $nameuser -c \""+command+"\" \" "
|
|
if multicmd == 0 or multicmd == 1:
|
|
print ("[RUNNING] " + msg)
|
|
if silent == 0:
|
|
statusC = execC(command)
|
|
elif silent == 1:
|
|
statusC = execC(command,FNULL)
|
|
elif silent == 2:
|
|
statusC = execC(command,FNULL,FNULL)
|
|
|
|
if (statusC == 0 or silent == 2) and (multicmd == 0 or multicmd == 3):
|
|
print ("["+bcolors.GRE +" OK "+bcolors.END +"] " + msg)
|
|
elif statusC != 0:
|
|
print ("["+bcolors.RED +"FAILED"+bcolors.END +"] " + msg)
|
|
|
|
|
|
comm("Directory list",0,"sudo","ls -l")
|
|
comm("Directory list",1,"sudo","ls -l")
|
|
response = yesnobox("¿Estás de acuerdo con usar Python?")
|
|
if response == dialog.OK:
|
|
print ("Estas avisado.")
|
|
|
|
|
|
|
|
|
|
###Start install
|
|
sclang = menudialog("Selecciona el idioma",[("es","Español","en","Ingles")])
|
|
execC("loadkeys "+sclang,FNULL,FNULL)
|
|
comm("Desmontando particiones",2,"sudo","umount /mnt/*/* & umount /mnt/* & umount /mnt")
|
|
usr_partitions
|
|
usr_date
|
|
usr_selectapps
|
|
usr_userpass
|
|
|
|
## TODO RESUMEN ##
|
|
|
|
installconf
|
|
|
|
usr_otheropts
|
|
|
|
mostrardialog("End","Setup finished, press enter to reboot")
|
|
execC("mv /tmp/install.log /mnt/home/$nameuser/install.log",FNULL)
|
|
comm("Desmontando particiones",2,"sudo","umount /mnt/*/* & umount /mnt/* & umount /mnt")
|
|
execC("reboot") |