3131
3232def initram_update ():
3333if is_luks :
34- os .system ("sudo dd bs=512 count=4 if=/dev/random of=/mnt/etc/crypto_keyfile.bin iflag=fullblock" )
35- os .system ("sudo chmod 000 /mnt/etc/crypto_keyfile.bin" )# Changed from 600 as even root doesn't need access
36- os .system (f"sudo cryptsetup luksAddKey{ args [1 ]} /mnt/etc/crypto_keyfile.bin" )
37- os .system ("sudo sed -i -e '/^HOOKS/ s/filesystems/encrypt filesystems/'\
34+ os .system (f" { SUDO } dd bs=512 count=4 if=/dev/random of=/mnt/etc/crypto_keyfile.bin iflag=fullblock" )
35+ os .system (f" { SUDO } chmod 000 /mnt/etc/crypto_keyfile.bin" )# Changed from 600 as even root doesn't need access
36+ os .system (f"{ SUDO } cryptsetup luksAddKey{ args [1 ]} /mnt/etc/crypto_keyfile.bin" )
37+ os .system (f" { SUDO } sed -i -e '/^HOOKS/ s/filesystems/encrypt filesystems/'\
3838 -e 's|^FILES=(|FILES=(/etc/crypto_keyfile.bin|' /mnt/etc/mkinitcpio.conf" )### IMPORTANT TODO
3939if is_format_btrfs :### REVIEW TEMPORARY
40- os .system ("sudo sed -i 's|ext4|ext4 btrfs|' /mnt/etc/mkinitfs/mkinitfs.conf" )### TODO if array not empty, needs to be "btrfs "
40+ os .system (f" { SUDO } sed -i 's|ext4|ext4 btrfs|' /mnt/etc/mkinitfs/mkinitfs.conf" )### TODO if array not empty, needs to be "btrfs "
4141if is_luks or is_format_btrfs :### REVIEW: does mkinitcpio need to be run without these conditions too?
4242try :# work with default kernel modules first
43- subprocess .check_output ("sudo chroot /mntsudo mkinitfs -b / -f /etc/fstab" ,shell = True )### REVIEW <kernelvers>
43+ subprocess .check_output (f" { SUDO } chroot /mnt{ SUDO } mkinitfs -b / -f /etc/fstab" ,shell = True )### REVIEW <kernelvers>
4444except subprocess .CalledProcessError :# and if errors
4545kv = os .listdir ('/mnt/lib/modules' )
4646try :
4747if len (kv )== 1 :
48- subprocess .check_output (f"sudo chroot /mntsudo mkinitfs -b / -f /etc/fstab -k{ '' .join (kv )} " ,shell = True )
48+ subprocess .check_output (f"{ SUDO } chroot /mnt{ SUDO } mkinitfs -b / -f /etc/fstab -k{ '' .join (kv )} " ,shell = True )
4949except :
5050print (f"F: Creating initfs with either live default or{ kv } kernels failed!" )
5151print ("Next, type just folder name from /mnt/lib/modules i.e. 5.15.104-0-lts" )
5252while True :
5353try :
5454kv = get_item_from_path ("kernel version" ,"/mnt/lib/modules" )
55- subprocess .check_output (f"sudo chroot /mntsudo mkinitfs -b / -f /etc/fstab -k{ kv } " ,shell = True )
55+ subprocess .check_output (f"{ SUDO } chroot /mnt{ SUDO } mkinitfs -b / -f /etc/fstab -k{ kv } " ,shell = True )
5656break # Success
5757except subprocess .CalledProcessError :
5858print (f"F: Creating initfs with kernel{ kv } failed!" )
@@ -64,9 +64,9 @@ def initram_update():
6464# 2. Bootstrap and install packages in chroot
6565os .system (f"curl -LO{ URL } /{ ARCH } /apk-tools-static-{ APK } .apk" )
6666os .system ("tar zxf apk-tools-static-*.apk" )
67- excode1 = os .system (f"sudo ./sbin/apk.static --arch{ ARCH } -X{ URL } -U --allow-untrusted --root /mnt --initdb --no-cache add alpine-base" )### REVIEW Is "/" needed after {URL} ?
67+ excode1 = os .system (f"{ SUDO } ./sbin/apk.static --arch{ ARCH } -X{ URL } -U --allow-untrusted --root /mnt --initdb --no-cache add alpine-base" )### REVIEW Is "/" needed after {URL} ?
6868copy ("./src/distros/alpine/repositories" ,"/mnt/etc/apk/" )### REVIEW MOVED from down at section 3 to here as installing 'bash' was giving error
69- os .system ("sudo cp --dereference /etc/resolv.conf /mnt/etc/" )# --remove-destination ### not writing through dangling symlink! (TODO: try except)
69+ os .system (f" { SUDO } cp --dereference /etc/resolv.conf /mnt/etc/" )# --remove-destination ### not writing through dangling symlink! (TODO: try except)
7070
7171try :
7272os .system (f"chroot /mnt /bin/sh -c '/sbin/apk update && /sbin/apk add{ packages } '" )
@@ -80,55 +80,55 @@ def initram_update():
8080ash_chroot ()
8181
8282# 3. Package manager database and config files
83- #os.system("sudo cp -r /mnt/var/lib/apk/. /mnt/usr/share/ash/db") ### REVIEW seems always empty?
83+ #os.system(f"{SUDO} cp -r /mnt/var/lib/apk/. /mnt/usr/share/ash/db") ### REVIEW seems always empty?
8484# /var/cache/apk/ , /var/lib/apk/ , /etc/apk/cache/
85- os .system ("sudo mv /mnt/lib/apk /mnt/usr/share/ash/db/" )
86- os .system ("sudo ln -srf /mnt/usr/share/ash/db/apk /mnt/lib/apk" )
85+ os .system (f" { SUDO } mv /mnt/lib/apk /mnt/usr/share/ash/db/" )
86+ os .system (f" { SUDO } ln -srf /mnt/usr/share/ash/db/apk /mnt/lib/apk" )
8787
8888# 4. Update hostname, hosts, locales and timezone, hosts
89- os .system (f"echo{ hostname } |sudo tee /mnt/etc/hostname" )
90- os .system (f"echo 127.0.0.1{ hostname } { distro } |sudo tee -a /mnt/etc/hosts" )
91- #os.system("sudo sed -i 's|^#en_US.UTF-8|en_US.UTF-8|g' /mnt/etc/locale.gen")
92- #os.system("sudo chroot /mntsudo locale-gen")
93- #os.system("echo 'LANG=en_US.UTF-8' |sudo tee /mnt/etc/locale.conf")
94- os .system (f"sudo ln -srf /mnt/usr/share/zoneinfo/{ tz } /mnt/etc/localtime" )
95- os .system ("sudo chroot /mnt /sbin/hwclock --systohc" )
89+ os .system (f"echo{ hostname } |{ SUDO } tee /mnt/etc/hostname" )
90+ os .system (f"echo 127.0.0.1{ hostname } { distro } |{ SUDO } tee -a /mnt/etc/hosts" )
91+ #os.system(f"{SUDO} sed -i 's|^#en_US.UTF-8|en_US.UTF-8|g' /mnt/etc/locale.gen")
92+ #os.system(f"{SUDO} chroot /mnt{SUDO} locale-gen")
93+ #os.system(f "echo 'LANG=en_US.UTF-8' |{SUDO} tee /mnt/etc/locale.conf")
94+ os .system (f"{ SUDO } ln -srf /mnt/usr/share/zoneinfo/{ tz } /mnt/etc/localtime" )
95+ os .system (f" { SUDO } chroot /mnt /sbin/hwclock --systohc" )
9696
9797# Post bootstrap
9898post_bootstrap (super_group )
9999if yes_no ("Replace Busybox's ash with Ash? (NOT recommended yet!)" ):
100- os .system (f"sudo mv /mnt/bin/ash /mnt/bin/busyash" )
101- #os.system(f"sudo mv /mnt/bin/ash /mnt/usr/bin/ash")
102- #os.system(f"sudo mv /mnt/usr/bin/ash /mnt/bin/ash")
100+ os .system (f"{ SUDO } mv /mnt/bin/ash /mnt/bin/busyash" )
101+ #os.system(f"{SUDO} mv /mnt/bin/ash /mnt/usr/bin/ash")
102+ #os.system(f"{SUDO} mv /mnt/usr/bin/ash /mnt/bin/ash")
103103print ("Ash replaced Busybox's ash (which is now busyash)!" )
104104else :
105- os .system (f"sudo mv /mnt/usr/bin/ash /mnt/usr/bin/asd" )
105+ os .system (f"{ SUDO } mv /mnt/usr/bin/ash /mnt/usr/bin/asd" )
106106print ("Use asd instead of ash!" )
107107
108108# 5. Services (init, network, etc.)
109- os .system ("sudo chroot /mnt /bin/bash -c '/sbin/setup-interfaces'" )
110- os .system (f"sudo chroot /mnt /bin/bash -c '/usr/sbin/adduser{ username } plugdev'" )
111- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add devfs sysinit'" )
112- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add dmesg sysinit'" )
113- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add mdev sysinit'" )
114- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add hwdrivers sysinit'" )
115- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add cgroups sysinit'" )
116- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add hwclock boot'" )
117- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add modules boot'" )
118- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add sysctl boot'" )
119- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add hostname boot'" )
120- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add bootmisc boot'" )
121- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add syslog boot'" )
122- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add swap boot'" )
123- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add networking boot'" )
124- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add seedrng boot'" )
125- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add mount-ro shutdown'" )
126- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add killprocs shutdown'" )
127- os .system ("sudo chroot /mnt /bin/bash -c 'sudo /sbin/rc-update add savecache shutdown'" )
128- #os.system("sudo chroot /mnt /bin/bash -c '/sbin/rc-service networkmanager start'")
109+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '/sbin/setup-interfaces'" )
110+ os .system (f"{ SUDO } chroot /mnt /bin/bash -c '/usr/sbin/adduser{ username } plugdev'" )
111+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add devfs sysinit'" )
112+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add dmesg sysinit'" )
113+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add mdev sysinit'" )
114+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add hwdrivers sysinit'" )
115+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add cgroups sysinit'" )
116+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add hwclock boot'" )
117+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add modules boot'" )
118+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add sysctl boot'" )
119+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add hostname boot'" )
120+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add bootmisc boot'" )
121+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add syslog boot'" )
122+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add swap boot'" )
123+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add networking boot'" )
124+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add seedrng boot'" )
125+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add mount-ro shutdown'" )
126+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add killprocs shutdown'" )
127+ os .system (f" { SUDO } chroot /mnt /bin/bash -c '{ SUDO } /sbin/rc-update add savecache shutdown'" )
128+ #os.system(f"{SUDO} chroot /mnt /bin/bash -c '/sbin/rc-service networkmanager start'")
129129
130130# 6. Boot and EFI
131- os .system ('echo GRUB_CMDLINE_LINUX_DEFAULT=\\ "modules=sd-mod,usb-storage,btrfs quiet rootfstype=btrfs\\ " |sudo tee -a /mnt/etc/default/grub' )# should be before initram create otherwise canonical error in grub-probe
131+ os .system (f 'echo GRUB_CMDLINE_LINUX_DEFAULT=\\ "modules=sd-mod,usb-storage,btrfs quiet rootfstype=btrfs\\ " |{ SUDO } tee -a /mnt/etc/default/grub' )# should be before initram create otherwise canonical error in grub-probe
132132initram_update ()
133133grub_ash (v )
134134