#!/usr/bin/python ## This script requires ArchLinux and: python3 and python-pythondialog, or python2, python2-pythondialog and python2-future ###### THIS SCRIPT NOT WORKS, ITS A TRY, THANKS ###### print ('\033[91m'+"Dont run this."+'\033[0m') sys.exit(0) #General imports (Python2 and 3) import os,sys,subprocess #Install and delete things, preparing installer subprocess.call("mount -o remount,size=700M /run/archiso/cowspace", shell=True) subprocess.call("pacman-key --init && pacman-key --populate && pacman -Sy archlinux-keyring --noconfirm", shell=True) subprocess.call("pacman -S reflector --noconfirm && reflector --verbose -l 6 --sort rate --save /etc/pacman.d/mirrorlist", shell=True) subprocess.call("pacman -R clonezilla darkhttpd diffutils grml-zsh-config irssi linux-atm lvm2 man-db man-pages mc ndisc6 nmap smartmontools testdisk vi vim vim-runtime openconnect pcsclite --noconfirm", shell=True) subprocess.call("rm -rf /var/cache/pacman/pkg/*", shell=True) subprocess.call("pacman -Su --noconfirm --ignore linux", shell=True) subprocess.call("rm -rf /var/cache/pacman/pkg/*", shell=True) subprocess.call("pacman -S gparted xf86-video-vesa xorg-xinit lwm xorg-xrandr xterm --noconfirm --needed", shell=True) subprocess.call("rm -rf /var/cache/pacman/pkg/*", shell=True) subprocess.call("rm /etc/X11/xinit/xinitrc", shell=True) subprocess.call("touch /etc/X11/xinit/xinitrc", shell=True) subprocess.call("chmod 777 /etc/X11/xinit/xinitrc", shell=True) subprocess.call('echo "#Start gparted with startx command" > /etc/X11/xinit/xinitrc', shell=True) subprocess.call('echo "lwm &" >> /etc/X11/xinit/xinitrc', shell=True) subprocess.call('echo "xrandr -s 1024x768 -r 60" >> /etc/X11/xinit/xinitrc', shell=True) subprocess.call('chmod 644 /etc/X11/xinit/xinitrc', shell=True) ### sudo echo "xterm -e '/usr/bin/python3 /root/installer.py' -geometry 120x35" >> /etc/X11/xinit/xinitrc #Try to see if its using python2 pythonver=sys.version_info[0] if pythonver < 3: print 'You are using python2, installing needed things..' subprocess.call("pacman -S python2-future python2-pythondialog --noconfirm --needed", shell=True) #Import future for using python3 syntax in python2 from __future__ import (absolute_import, division, print_function, unicode_literals) from builtins import * else: print 'You are using python3, installing needed things..' subprocess.call("pacman -S python-pythondialog --noconfirm --needed", shell=True) #Things installed, running... 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 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")