Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit11c3b90

Browse files
committed
Code clean-up
1 parentd862246 commit11c3b90

File tree

11 files changed

+296
-250
lines changed

11 files changed

+296
-250
lines changed

‎src/ashpk_core.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,19 @@ def chr_delete(snap):
155155
exceptsp.CalledProcessError:
156156
print(f"F: Failed to delete chroot snapshot{snap}.")
157157
# else:
158-
# print(f"Snapshot chroot {snap} deleted.") ### just when debugging
158+
# print(f"Snapshot chroot {snap} deleted.") # REVIEW just when debugging
159159

160160
# Chroot into snapshot and optionally run command(s)
161161
defchroot(snap,cmd=""):# TODO change cmd to cmds - IMPORTANT for install_profile
162162
ifnotos.path.exists(f"/.snapshots/rootfs/snapshot-{snap}"):
163163
print(f"F: Cannot chroot as snapshot{snap} doesn't exist.")
164164
elifos.path.exists(f"/.snapshots/rootfs/snapshot-chr{snap}"):# Make sure snapshot is not in use by another ash process
165-
print(f"F: Snapshot{snap} appears to be in use. If you're certain it's not in use, clear lock with 'ash unlock -s{snap}'.")### REMOVE_ALL_THESE_LINES
165+
print(f"F: Snapshot{snap} appears to be in use. If you're certain it's not in use, clear lock with 'ash unlock -s{snap}'.")# REVIEW remove all these lines
166166
elifsnap==0:
167167
print("F: Changing base snapshot is not allowed.")
168168
else:
169169
prepare(snap)
170-
excode=os.system(f"chroot /.snapshots/rootfs/snapshot-chr{snap}{' '.join(cmd)}")### TODO if you chroot, then run 'dua' and exit, it makes excode non-zero!
170+
excode=os.system(f"chroot /.snapshots/rootfs/snapshot-chr{snap}{' '.join(cmd)}")# TODO if you chroot, then run 'dua' and exit, it makes excode non-zero!
171171
ifexcode:
172172
chr_delete(snap)
173173
print("F: Chroot failed and changes discarded!")

‎src/distros/alpine/installer.py‎

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ def main():
4141
# Pre bootstrap
4242
pre_bootstrap()
4343

44+
# Mount-points for chrooting
45+
ashos_mounts()
46+
4447
# 2. Bootstrap and install packages in chroot
4548
whileTrue:
4649
try:
47-
strap(packages)
50+
strap()
4851
except (sp.CalledProcessError,HTTPError,URLError,FileNotFoundError,tarfile.ExtractError)ase:
4952
print(e)
5053
ifnotyes_no("F: Failed to strap package(s). Retry?"):
@@ -53,8 +56,7 @@ def main():
5356
else:# success
5457
break
5558

56-
# Mount-points for chrooting
57-
ashos_mounts()
59+
# Go inside chroot
5860
cur_dir_code=chroot_in("/mnt")
5961

6062
# 3. Package manager database and config files
@@ -69,12 +71,12 @@ def main():
6971
#os.system(f"{SUDO} sed -i 's|^#en_US.UTF-8|en_US.UTF-8|g' /mnt/etc/locale.gen")
7072
#os.system(f"{SUDO} chroot /mnt {SUDO} locale-gen")
7173
#os.system(f"echo 'LANG=en_US.UTF-8' | {SUDO} tee /mnt/etc/locale.conf")
72-
os.system(f"ln -sf /usr/share/zoneinfo/{tz} /etc/localtime")# removed /mnt/XYZ from both paths (and from all lines above)
74+
os.system(f"ln -sf /usr/share/zoneinfo/{tz} /etc/localtime")
7375
os.system("/sbin/hwclock --systohc")
7476

7577
# Post bootstrap
7678
post_bootstrap(super_group)
77-
ifyes_no("Replace Busybox's ash with Ash? (NOT recommended yet!)"):# REVIEW removed "{SUDO}" from all lines below (and all {SUDO}'s)
79+
ifyes_no("Replace Busybox's ash with Ash? (NOT recommended yet!)"):
7880
os.system("mv /bin/ash /bin/busyash")
7981
#os.system(f"{SUDO} mv /mnt/bin/ash /mnt/usr/bin/ash")
8082
#os.system(f"{SUDO} mv /mnt/usr/bin/ash /mnt/bin/ash")
@@ -83,30 +85,22 @@ def main():
8385
os.system("mv /usr/bin/ash /usr/bin/asd")
8486
print("Use asd instead of ash!")
8587

86-
# 5. Services (init, network, etc.) # REVIEW removed {SUDO} chroot /mnt /bin/bash -c '{SUDO} from all lines
88+
# 5. Services (init, network, etc.)
8789
os.system("/sbin/setup-interfaces")
8890
os.system(f"/usr/sbin/adduser{username} plugdev")
89-
os.system("/sbin/rc-update add devfs sysinit")
90-
os.system("/sbin/rc-update add dmesg sysinit")
91-
os.system("/sbin/rc-update add mdev sysinit")
92-
os.system("/sbin/rc-update add hwdrivers sysinit")
93-
os.system("/sbin/rc-update add cgroups sysinit")
94-
os.system("/sbin/rc-update add hwclock boot")
95-
os.system("/sbin/rc-update add modules boot")
96-
os.system("/sbin/rc-update add sysctl boot")
97-
os.system("/sbin/rc-update add hostname boot")
98-
os.system("/sbin/rc-update add bootmisc boot")
99-
os.system("/sbin/rc-update add syslog boot")
100-
os.system("/sbin/rc-update add swap boot")
101-
os.system("/sbin/rc-update add networking boot")
102-
os.system("/sbin/rc-update add seedrng boot")
103-
os.system("/sbin/rc-update add mount-ro shutdown")
104-
os.system("/sbin/rc-update add killprocs shutdown")
105-
os.system("/sbin/rc-update add savecache shutdown")
91+
92+
rc_update=find_command(["rc-update"])
93+
tuples= ["devfs sysinit","dmesg sysinit","mdev sysinit","hwdrivers sysinit","cgroups sysinit",
94+
"hwclock boot","modules boot","sysctl boot","hostname boot","bootmisc boot","syslog boot","swap boot","networking boot","seedrng boot",
95+
"mount-ro shutdown","killprocs shutdown","savecache shutdown"]
96+
foriintuples:
97+
os.system(f"{rc_update} add{i}")
10698
#os.system(f"{SUDO} chroot /mnt /bin/bash -c '/sbin/rc-service networkmanager start'")
10799

108100
# 6. Boot and EFI
109-
os.system('echo GRUB_CMDLINE_LINUX_DEFAULT=\\"modules=sd-mod,usb-storage,btrfs quiet rootfstype=btrfs\\" >> /etc/default/grub')# should be before initram create otherwise canonical error in grub-probe
101+
# should be before initram create otherwise canonical error in grub-probe
102+
withopen("/etc/default/grub","a")asf:
103+
f.write('GRUB_CMDLINE_LINUX_DEFAULT="modules=sd-mod,usb-storage,btrfs quiet rootfstype=btrfs"')
110104
initram_update()
111105
grub_ash(v)
112106

@@ -132,7 +126,7 @@ def get_apk_ver():
132126
minor=search('pkgrel=(.+?)\n',temp).group(1)
133127
returnf"{major}-r{minor}"
134128

135-
definitram_update():# REVIEW removed "{SUDO}" from all lines below
129+
definitram_update():
136130
ifis_luks:
137131
os.system("dd bs=512 count=4 if=/dev/random of=/etc/crypto_keyfile.bin iflag=fullblock")
138132
os.system("chmod 000 /etc/crypto_keyfile.bin")# Changed from 600 as even root doesn't need access
@@ -161,7 +155,7 @@ def initram_update(): # REVIEW removed "{SUDO}" from all lines below
161155
print(f"F: Creating initfs with kernel{kv} failed!")
162156
continue
163157

164-
defstrap(packages):
158+
defstrap():
165159
APK=get_apk_ver()# e.g. 2.14.0_rc1-r0
166160
withTemporaryDirectory(dir="/tmp",prefix="ash.")astmpdir:
167161
apk_file=urlopen(f"{URL}/{ARCH}/apk-tools-static-{APK}.apk").read()# curl -LO

‎src/distros/arch/installer.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ def main():
2424
# Pre bootstrap
2525
pre_bootstrap()
2626

27+
# Mount-points for chrooting
28+
ashos_mounts()
29+
2730
# 2. Bootstrap and install packages in chroot
2831
ifKERNELnotin ("-hardened","-lts","-zen"):# AUR required
2932
sp.call(f'{installer_dir}/src/distros/{distro}/aur/aurutils.sh',shell=True)
3033
whileTrue:
3134
try:
32-
strap(packages)
35+
strap()
3336
exceptsp.CalledProcessErrorase:
3437
print(e)
3538
ifnotyes_no("F: Failed to strap package(s). Retry?"):
@@ -38,8 +41,7 @@ def main():
3841
else:# success
3942
break
4043

41-
# Mount-points for chrooting
42-
ashos_mounts()
44+
# Go inside chroot
4345
cur_dir_code=chroot_in("/mnt")
4446

4547
# 3. Package manager database and config files
@@ -95,8 +97,8 @@ def initram_update(): # REVIEW removed "{SUDO}" from all lines below
9597
ifis_luksoris_format_btrfs:# REVIEW mkinitcpio needed to run without these conditions too?
9698
os.system(f"mkinitcpio -p linux{KERNEL}")
9799

98-
defstrap(pkg):
99-
sp.check_output(f"{SUDO}pacstrap /mnt --needed{pkg}",shell=True)
100+
defstrap():
101+
sp.check_call(f"pacstrap /mnt --needed{packages}",shell=True)
100102

101103
main()
102104

‎src/distros/cachyos/installer.py‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ def main():
2424
# Pre bootstrap
2525
pre_bootstrap()
2626

27-
# 2. Bootstrap and install packages in chroot
28-
excode=strap(packages)
29-
ifexcode!=0:
30-
sys.exit("F: Install failed!")
27+
# Mount-points for chrooting
28+
ashos_mounts()
3129

30+
# 2. Bootstrap and install packages in chroot
3231
whileTrue:
3332
try:
34-
strap(packages)
33+
strap()
3534
exceptsp.CalledProcessErrorase:
3635
print(e)
3736
ifnotyes_no("F: Failed to strap package(s). Retry?"):
@@ -40,8 +39,7 @@ def main():
4039
else:# success
4140
break
4241

43-
# Mount-points for chrooting
44-
ashos_mounts()
42+
# Go inside chroot
4543
cur_dir_code=chroot_in("/mnt")
4644

4745
# 3. Package manager database and config files
@@ -56,7 +54,7 @@ def main():
5654
os.system("locale-gen")
5755
os.system("echo 'LANG=en_US.UTF-8' > /etc/locale.conf")
5856
os.system(f"ln -sf /usr/share/zoneinfo/{tz} /etc/localtime")# removed /mnt/XYZ from both paths (and from all lines above)
59-
os.system("hwclock --systohc")
57+
os.system("/sbin/hwclock --systohc")
6058

6159
# Post bootstrap
6260
post_bootstrap(super_group)
@@ -66,7 +64,7 @@ def main():
6664
os.system("systemctl enable NetworkManager")
6765

6866
# 6. Boot and EFI
69-
initram_update(KERNEL)
67+
initram_update()
7068
grub_ash(v)
7169

7270
# BTRFS snapshots
@@ -85,7 +83,7 @@ def main():
8583
print("Installation complete!")
8684
print("You can reboot now :)")
8785

88-
definitram_update(KERNEL):# REVIEW removed "{SUDO}" from all lines below
86+
definitram_update():# REVIEW removed "{SUDO}" from all lines below
8987
ifis_luks:
9088
os.system("dd bs=512 count=4 if=/dev/random of=/etc/crypto_keyfile.bin iflag=fullblock")# removed /mnt/XYZ from output (and from lines below)
9189
os.system("chmod 000 /etc/crypto_keyfile.bin")# Changed from 600 as even root doesn't need access
@@ -97,8 +95,8 @@ def initram_update(KERNEL): # REVIEW removed "{SUDO}" from all lines below
9795
ifis_luksoris_format_btrfs:# REVIEW mkinitcpio needed to run without these conditions too?
9896
os.system(f"mkinitcpio -p linux{KERNEL}")
9997

100-
defstrap(pkg):
101-
sp.check_output(f"{SUDO}pacstrap /mnt --needed{pkg}",shell=True)
98+
defstrap():
99+
sp.check_call(f"pacstrap /mnt --needed{packages}",shell=True)
102100

103101
main()
104102

‎src/distros/debian/installer.py‎

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,35 @@
66
fromsrc.installer_coreimport*# NOQA
77
fromsetupimportargs,distro
88

9-
defmain():
10-
# 1. Define variables
11-
ARCH="amd64"
12-
RELEASE="sid"
13-
KERNEL=""
14-
packages=f"linux-image-{ARCH} btrfs-progs sudo curl dhcpcd5 locales nano\
15-
network-manager"# console-setup firmware-linux firmware-linux-nonfree os-prober
16-
ifnotis_ash_bundle:
17-
packages+=" python3 python3-anytree"
18-
ifis_efi:
19-
packages+=" grub-efi"# includes efibootmgr
20-
else:
21-
packages+=" grub-pc"
22-
ifis_luks:
23-
packages+=" cryptsetup cryptsetup-initramfs cryptsetup-run"
24-
super_group="sudo"
25-
v=""# GRUB version number in /boot/grubN
9+
# 1. Define variables
10+
ARCH="amd64"
11+
RELEASE="sid"
12+
KERNEL=""
13+
packages=f"linux-image-{ARCH} btrfs-progs sudo curl dhcpcd5 locales nano\
14+
network-manager"# console-setup firmware-linux firmware-linux-nonfree os-prober
15+
ifnotis_ash_bundle:
16+
packages+=" python3 python3-anytree"
17+
ifis_efi:
18+
packages+=" grub-efi"# includes efibootmgr
19+
else:
20+
packages+=" grub-pc"
21+
ifis_luks:
22+
packages+=" cryptsetup cryptsetup-initramfs cryptsetup-run"
23+
super_group="sudo"
24+
v=""# GRUB version number in /boot/grubN
2625

26+
defmain():
2727
# Pre bootstrap
2828
pre_bootstrap()
2929

30+
# Mount-points for chrooting
31+
ashos_mounts()
32+
3033
# 2. Bootstrap and install packages in chroot
34+
os.system("systemctl start ntp && sleep 30s && ntpq -p")# Sync time in the live iso
3135
whileTrue:
3236
try:
33-
strap(packages,ARCH,RELEASE)
37+
strap()
3438
exceptsp.CalledProcessErrorase:
3539
print(e)
3640
ifnotyes_no("F: Failed to strap package(s). Retry?"):
@@ -39,22 +43,20 @@ def main():
3943
else:# success
4044
break
4145

42-
# Mount-points for chrooting
43-
ashos_mounts()
44-
os.system("systemctl start ntp && sleep 30s && ntpq -p")# Sync time in the live iso
46+
# Go inside chroot
4547
cur_dir_code=chroot_in("/mnt")
4648

4749
# Install anytree and necessary packages in chroot
4850
try:
4951
open("/etc/apt/sources.list.d/multimedia.list","a").write(f"deb [trusted=yes] https://www.deb-multimedia.org{RELEASE} main")
5052
os.chmod("/tmp",0o1777)
53+
# REVIEW /tmp Otherwise error "Couldn't create temporary file /tmp/apt.conf.XYZ" # REVIEW necessary after switching to chroot_in and chroot_out? third line below necessary?
5154
commands=f'''
5255
apt-get -y update -oAcquire::AllowInsecureRepositories=true
5356
apt-get -y -f install deb-multimedia-keyring --allow-unauthenticated
5457
apt-get -y full-upgrade --allow-unauthenticated
5558
apt-get -y install --no-install-recommends --fix-broken{packages}
5659
'''
57-
# REVIEW /tmp Otherwise error "Couldn't create temporary file /tmp/apt.conf.XYZ" # REVIEW necessary after switching to chroot_in and chroot_out? second last line necessary?
5860
sp.check_call(commands,shell=True)
5961
except (Exception,sp.CalledProcessError,FileNotFoundError):
6062
sys.exit("Failed to download packages!")
@@ -106,10 +108,10 @@ def initram_update():
106108
os.system(f"cryptsetup luksAddKey{args[1]} /etc/crypto_keyfile.bin")
107109
os.system("sed -i -e 's|^#KEYFILE_PATTERN=|KEYFILE_PATTERN='/etc/crypto_keyfile.bin'|' /etc/cryptsetup-initramfs/conf-hook")
108110
os.system("echo UMASK=0077 >> /etc/initramfs-tools/initramfs.conf")
109-
os.system(f"echo 'luks_root '{args[1]}'/etc/crypto_keyfile.bin luks' >> /etc/crypttab")
111+
os.system(f"echo 'luks_root '{args[1]}' /etc/crypto_keyfile.bin luks' >> /etc/crypttab")
110112
os.system(f"update-initramfs -u")# REVIEW: What about kernel variants?
111113

112-
defstrap(pkg,ARCH,RELEASE):
114+
defstrap():
113115
excl=sp.check_output("dpkg-query -f '${binary:Package} ${Priority}\n' -W | grep -v 'required\\|important' | awk '{print $1}'",shell=True).decode('utf-8').strip().replace("\n",",")
114116
sp.check_call(f"debootstrap --arch{ARCH} --exclude={excl}{RELEASE} /mnt http://ftp.debian.org/debian",shell=True)# REVIEW --include={packages} ? --variant=minbase ?
115117

‎src/distros/endeavouros/installer.py‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ def main():
2626
# Pre bootstrap
2727
pre_bootstrap()
2828

29+
# Mount-points for chrooting
30+
ashos_mounts()
31+
2932
# 2. Bootstrap and install packages in chroot
33+
# If using EOS iso (# before: in section 3.)
34+
os.system(f"cp -a /etc/pacman.d/{distro}-mirrorlist /mnt/etc/pacman.d/")
35+
os.system("cp -a /etc/pacman.conf /mnt/etc/pacman.conf")
3036
ifKERNELnotin ("-hardened","-lts","-zen"):# AUR required
3137
sp.call(f'{installer_dir}/src/distros/{distro}/aur/aurutils.sh',shell=True)
3238
whileTrue:
@@ -40,11 +46,7 @@ def main():
4046
else:# success
4147
break
4248

43-
# Mount-points for chrooting
44-
ashos_mounts()
45-
# If using EOS iso (# before: in section 3.)
46-
os.system(f"sudo cp -a /etc/pacman.d/{distro}-mirrorlist /mnt/etc/pacman.d/")
47-
os.system("sudo cp -a /etc/pacman.conf /mnt/etc/pacman.conf")
49+
# Go inside chroot
4850
cur_dir_code=chroot_in("/mnt")
4951

5052
# 3. Package manager database and config files
@@ -62,7 +64,7 @@ def main():
6264
os.system("locale-gen")
6365
os.system("echo 'LANG=en_US.UTF-8' > /etc/locale.conf")
6466
os.system(f"ln -sf /usr/share/zoneinfo/{tz} /etc/localtime")# removed /mnt/XYZ from both paths (and from all lines above)
65-
os.system("hwclock --systohc")
67+
os.system("/sbin/hwclock --systohc")
6668

6769
# Post bootstrap
6870
post_bootstrap(super_group)
@@ -91,9 +93,9 @@ def main():
9193
print("Installation complete!")
9294
print("You can reboot now :)")
9395

94-
definitram_update():# REVIEW removed "{SUDO}" from all lines below
96+
definitram_update():
9597
ifis_luks:
96-
os.system("dd bs=512 count=4 if=/dev/random of=/etc/crypto_keyfile.bin iflag=fullblock")# removed /mnt/XYZ from output (and from lines below)
98+
os.system("dd bs=512 count=4 if=/dev/random of=/etc/crypto_keyfile.bin iflag=fullblock")
9799
os.system("chmod 000 /etc/crypto_keyfile.bin")# Changed from 600 as even root doesn't need access
98100
os.system(f"cryptsetup luksAddKey{args[1]} /etc/crypto_keyfile.bin")
99101
os.system("sed -i -e '/^HOOKS/ s/filesystems/encrypt filesystems/'\
@@ -103,8 +105,8 @@ def initram_update(): # REVIEW removed "{SUDO}" from all lines below
103105
ifis_luksoris_format_btrfs:# REVIEW mkinitcpio needed to run without these conditions too?
104106
os.system(f"mkinitcpio -p linux{KERNEL}")
105107

106-
defstrap(pkg):
107-
sp.check_output(f"{SUDO}pacstrap /mnt --needed{pkg}",shell=True)
108+
defstrap():
109+
sp.check_output(f"pacstrap /mnt --needed{packages}",shell=True)
108110

109111
main()
110112

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp