Compare commits

...

8 commits

Author SHA1 Message Date
Asterisk
5bf806eea0 Merge branch 'fix-arch-repo' into 'main'
Handle repos better

See merge request blendOS/system-tools/akshara!8
2025-04-17 19:51:40 +00:00
askiiart
48ad492117
handle repos better
* add bootstrap repo
* add fallback for all repos
* make listing `https://` optional (http must be listed if applicable)
2025-04-16 23:47:40 -05:00
Asterisk
740d3efb5d Merge branch 'upstreaming-fixes' into 'main'
Upstreaming misc fixes

See merge request blendOS/system-tools/akshara!7
2025-04-09 02:39:00 +00:00
askiiart
53e7c32106
chore: format 2025-04-08 13:03:57 -05:00
askiiart
27da28ccca
add custom bootstrap mirror option 2025-04-08 13:03:36 -05:00
askiiart
cba45e457e
remove update on exit (with flag to not do that) 2025-04-08 12:50:25 -05:00
Asterisk
e14cc419a0 Merge branch 'fix-aur-broken' into 'main'
AUR packages work now

See merge request blendOS/system-tools/akshara!6
2024-10-09 18:01:15 +00:00
askiiart
19b90e85f4
AUR packages work now 2024-10-09 10:40:48 -05:00
2 changed files with 80 additions and 31 deletions

105
akshara Executable file → Normal file
View file

@ -103,10 +103,11 @@ def error(err):
def interpret_track(blend_release):
result = yaml.safe_load(requests.get(blend_release.get('impl') + '/' + blend_release.get('track') + '.yaml', allow_redirects=True).content.decode())
result = yaml.safe_load(requests.get(blend_release.get(
'impl') + '/' + blend_release.get('track') + '.yaml', allow_redirects=True).content.decode())
if (type(result.get('impl')) == str and
type(result.get('track')) != 'custom'):
type(result.get('track')) != 'custom'):
res = interpret_track(result)
for i in res.keys():
@ -137,33 +138,60 @@ def update_system():
blend_release = yaml.load(
blend_release_file, Loader=yaml.FullLoader)
# TODO: Add check that all packages actually exist
info('downloading Arch tarball...')
# The mirror to use for downloading the bootstrap image
# For example, for the Arch mirror at mirrors.acm.wpi.edu, you'd use https://mirrors.acm.wpi.edu/archlinux
arch_repo = blend_release.get("arch-repo")
if type(arch_repo) != str:
# default arch and bootstrap repo
arch_repo = "geo.mirror.pkgbuild.com"
bootstrap_repo = blend_release.get("bootstrap-repo")
if type(bootstrap_repo) != str:
bootstrap_repo = arch_repo
# TODO: default to https if http/https isn't listed
# keeping disabled for consistency because i can't find `repo` to add it (and to add a fallback)
if not (arch_repo.startswith("https://") or arch_repo.startswith("http://")):
arch_repo = "https://" + arch_repo
if not (bootstrap_repo.startswith("https://") or bootstrap_repo.startswith("http://")):
bootstrap_repo = "https://" + bootstrap_repo
# same (fallback and https) for repo
repo = blend_release.get("repo")
if type(repo) != str:
repo = "https://pkg-repo.blendos.co"
elif not (repo.startswith("https://") or repo.startswith("http://")):
repo = "https://" + repo
if not os.path.isfile('/.update.tar.zst'):
if exec('wget', '-q', '--show-progress', 'https://geo.mirror.pkgbuild.com/iso/latest/archlinux-bootstrap-x86_64.tar.zst', '-O', '/.update.tar.zst') != 0:
if exec('wget', '-q', '--show-progress', f'{bootstrap_repo}/iso/latest/archlinux-bootstrap-x86_64.tar.zst', '-O', '/.update.tar.zst') != 0:
warn('failed download')
print()
info('trying download again...')
print()
exec('rm', '-f', '/.update.tar.zst')
if exec('wget', '-q', '--show-progress', 'https://geo.mirror.pkgbuild.com/iso/latest/archlinux-bootstrap-x86_64.tar.zst', '-O', '/.update.tar.zst') != 0:
if exec('wget', '-q', '--show-progress', f'{bootstrap_repo}/iso/latest/archlinux-bootstrap-x86_64.tar.zst', '-O', '/.update.tar.zst') != 0:
error('failed download')
print()
error('update failed')
sys.exit(50)
if exec('bash', '-c', 'sha256sum -c --ignore-missing <(wget -qO- https://geo.mirror.pkgbuild.com/iso/latest/sha256sums.txt | sed "s/archlinux-bootstrap-x86_64\\.tar\\.zst/.update.tar.zst/g") 2>/dev/null') != 0:
if exec('bash', '-c', f'sha256sum -c --ignore-missing <(wget -qO- {bootstrap_repo}/iso/latest/sha256sums.txt | sed "s/archlinux-bootstrap-x86_64\\.tar\\.zst/.update.tar.zst/g") 2>/dev/null') != 0:
error('failed checksum verification')
print()
info('trying download again...')
exec('rm', '-f', '/.update.tar.zst')
if exec('wget', '-q', '--show-progress', 'https://geo.mirror.pkgbuild.com/iso/latest/archlinux-bootstrap-x86_64.tar.zst', '-O', '/.update.tar.zst') != 0:
if exec('wget', '-q', '--show-progress', f'{bootstrap_repo}/iso/latest/archlinux-bootstrap-x86_64.tar.zst', '-O', '/.update.tar.zst') != 0:
error('failed download')
print()
error('update failed')
sys.exit(50)
return
if exec('bash', '-c', 'sha256sum -c --ignore-missing <(wget -qO- https://geo.mirror.pkgbuild.com/iso/latest/sha256sums.txt | sed "s/archlinux-bootstrap-x86_64\\.tar\\.zst/.update.tar.zst/g") 2>/dev/null') != 0:
if exec('bash', '-c', f'sha256sum -c --ignore-missing <(wget -qO- {bootstrap_repo}/iso/latest/sha256sums.txt | sed "s/archlinux-bootstrap-x86_64\\.tar\\.zst/.update.tar.zst/g") 2>/dev/null') != 0:
error('failed checksum verification')
print()
error('update failed')
@ -201,7 +229,7 @@ def update_system():
]
if (type(blend_release.get('impl')) == str and
type(blend_release.get('track')) != 'custom'):
type(blend_release.get('track')) != 'custom'):
res = interpret_track(blend_release)
for i in res.keys():
@ -230,14 +258,13 @@ def update_system():
pacman_mirrorlist_conf.write('nameserver 1.1.1.1\n')
with open('/.new_rootfs/etc/pacman.d/mirrorlist', 'w') as pacman_mirrorlist_conf:
if type(blend_release.get('arch-repo')) == str:
pacman_mirrorlist_conf.write(f'Server = {blend_release.get("arch-repo")}/$repo/os/$arch\n')
else:
pacman_mirrorlist_conf.write('Server = https://geo.mirror.pkgbuild.com/$repo/os/$arch\n')
pacman_mirrorlist_conf.write(
f'Server = {arch_repo}/$repo/os/$arch\n')
exec_chroot('mkdir', '-p', '/var/cache/pacman/pkg')
exec_chroot('rm', '-rf', '/var/cache/pacman/pkg')
exec('cp', '-r', '/var/cache/pacman/pkg', '/.new_rootfs/var/cache/pacman')
exec('cp', '-r', '/var/cache/pacman/pkg',
'/.new_rootfs/var/cache/pacman')
# update packages
exec_chroot('pacman-key', '--init')
@ -253,26 +280,32 @@ def update_system():
if return_val == 0:
break
exec_chroot('reflector', '--latest', '5', '--protocol', 'https', '--sort', 'rate', '--save', '/etc/pacman.d/mirrorlist')
exec_chroot('reflector', '--latest', '5', '--protocol', 'https',
'--sort', 'rate', '--save', '/etc/pacman.d/mirrorlist')
#exec_chroot('sed', 's/#//g', '-i', '/etc/pacman.d/mirrorlist')
#exec_chroot('bash', '-c', 'grep "^Server =" /etc/pacman.d/mirrorlist > /etc/pacman.d/mirrorlist.tmp; mv /etc/pacman.d/mirrorlist.tmp /etc/pacman.d/mirrorlist')
# exec_chroot('sed', 's/#//g', '-i', '/etc/pacman.d/mirrorlist')
# exec_chroot('bash', '-c', 'grep "^Server =" /etc/pacman.d/mirrorlist > /etc/pacman.d/mirrorlist.tmp; mv /etc/pacman.d/mirrorlist.tmp /etc/pacman.d/mirrorlist')
with open('/.new_rootfs/etc/pacman.conf', 'r') as original: data = original.read()
with open('/.new_rootfs/etc/pacman.conf', 'w') as modified: modified.write(data.replace("[options]", "[options]\nParallelDownloads = 32\n"))
with open('/.new_rootfs/etc/pacman.conf', 'w') as modified: modified.write(data.replace("#[multilib]\n#Include = /etc/pacman.d/mirrorlist", "[multilib]\nInclude = /etc/pacman.d/mirrorlist"))
with open('/.new_rootfs/etc/pacman.conf', 'r') as original:
data = original.read()
with open('/.new_rootfs/etc/pacman.conf', 'w') as modified:
modified.write(data.replace(
"[options]", "[options]\nParallelDownloads = 32\n"))
with open('/.new_rootfs/etc/pacman.conf', 'w') as modified:
modified.write(data.replace(
"#[multilib]\n#Include = /etc/pacman.d/mirrorlist", "[multilib]\nInclude = /etc/pacman.d/mirrorlist"))
with open('/.new_rootfs/etc/pacman.conf', 'a') as pacman_conf:
pacman_conf.write(f'''
[breakfast]
SigLevel = Never
Server = {blend_release['repo']}
Server = {repo}
''')
if type(blend_release.get('package-repos')) == list:
for package_repo in blend_release.get('package-repos'):
if (type(package_repo.get('name')) == str and
type(package_repo.get('repo-url')) == str):
type(package_repo.get('repo-url')) == str):
pacman_conf.write(f'''
[{package_repo["name"]}]
SigLevel = Never
@ -300,12 +333,14 @@ Server = {package_repo["repo-url"]}
exit(50)
if return_val == 0:
break
counter = 0
if aur_packages != []:
while True:
exec_chroot('useradd', '-m', '-G', 'wheel', '-s', '/bin/bash', 'aur')
exec_chroot('bash', '-c', 'echo "aur ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/aur')
exec_chroot('useradd', '-m', '-G', 'wheel',
'-s', '/bin/bash', 'aur')
exec_chroot(
'bash', '-c', 'echo "aur ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/aur')
return_val = exec_chroot(
'runuser', '-u', 'aur', '--', 'paru', '-Sy', '--noconfirm', '--needed',
'--noprogressbar', '--skipreview', '--removemake', '--cleanafter', '--ask=4',
@ -377,7 +412,8 @@ Server = {package_repo["repo-url"]}
exec('cp', '-ax', '/var/lib', '/.new.var.lib')
var_lib_diff = filecmp.dircmp('/.new_rootfs/var/lib/', '/.new.var.lib/')
var_lib_diff = filecmp.dircmp(
'/.new_rootfs/var/lib/', '/.new.var.lib/')
dir_name = '/.new.var.lib/'
for name in var_lib_diff.left_only:
@ -458,10 +494,8 @@ command_map = {'help': 'help',
'daemon': daemon}
parser.add_argument('command', choices=command_map.keys(),
help=argparse.SUPPRESS)
parser.add_argument('pkg', action='store', type=str,
nargs='*', help=argparse.SUPPRESS)
parser.add_argument('--headless',
action='store_true', help=argparse.SUPPRESS)
parser.add_argument('--keep-files-on-error',
action='store_true', help="keep working files on error")
parser.add_argument('-v', '--version', action='version',
version=f'%(prog)s {__version}', help=argparse.SUPPRESS)
@ -484,11 +518,20 @@ try:
parser.parse_args(['--version'])
elif command == update_system:
exec('touch', '/var/lib/.akshara-system-lock')
system_lock = fasteners.InterProcessLock('/var/lib/.akshara-system-lock')
system_lock = fasteners.InterProcessLock(
'/var/lib/.akshara-system-lock')
info('attempting to acquire system lock')
with system_lock:
command()
else:
command()
except KeyboardInterrupt:
except:
error('aborting')
# remove update and akshara stuff if the program errors (either exited by the user or an error) and is updating
if command == update_system and not args.keep_files_on_error:
exec('umount', '-rf', '/.new_rootfs/')
exec('rmdir', '/.new_rootfs/')
exec('rm', '-rf', '/.update_rootfs')
exec('rm', '-f', '/.update')
else:
print("--keep-files-on-error specified, not deleting files (/.new_rootfs/, /.update_rootfs/, /.update)")

View file

@ -23,6 +23,12 @@ run_latehook() {
mv /new_root/.new.etc /new_root/etc
fi
# Same for /opt
if [[ -d /new_root/.update_rootfs/opt ]]; then
mv /new_root/opt /new_root/.old.opt
mv /new_root/.update_rootfs/opt /new_root/opt
fi
# Same for /var.
if [[ -d /new_root/.new.var.lib ]]; then
mv /new_root/var/lib /new_root/.old.var.lib