From 5f62b2f59ab20ada15ec1fa89ecb25a2df8695f8 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Sat, 6 May 2023 18:47:56 +0530 Subject: [PATCH 001/135] Initial commit --- akshara | 250 +++++++++++++++++++++++++++++++++++++++++++++++++++ akshara.hook | 27 ++++++ 2 files changed, 277 insertions(+) create mode 100755 akshara create mode 100755 akshara.hook diff --git a/akshara b/akshara new file mode 100755 index 0000000..51c5810 --- /dev/null +++ b/akshara @@ -0,0 +1,250 @@ +#!/usr/bin/env python3 +# Copyright (C) 2023 Rudra Saraswat +# +# This file is part of blend. +# +# blend is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# blend is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with blend. If not, see . + + +import os +import sys +import time +import yaml +import argparse +import platform +import subprocess + +__version = '1.0.0' + +with open('/etc/blend_release') as blend_release_file: + blend_release = yaml.load( + blend_release_file, Loader=yaml.FullLoader) + server_url = blend_release['server'] + +# Colors + + +class colors: + reset = '\033[0m' + bold = '\033[01m' + disable = '\033[02m' + underline = '\033[04m' + reverse = '\033[07m' + strikethrough = '\033[09m' + invisible = '\033[08m' + + class fg: + black = '\033[30m' + red = '\033[31m' + green = '\033[32m' + orange = '\033[33m' + blue = '\033[34m' + purple = '\033[35m' + cyan = '\033[36m' + lightgrey = '\033[37m' + darkgrey = '\033[90m' + lightred = '\033[91m' + lightgreen = '\033[92m' + yellow = '\033[93m' + lightblue = '\033[94m' + pink = '\033[95m' + lightcyan = '\033[96m' + + class bg: + black = '\033[40m' + red = '\033[41m' + green = '\033[42m' + orange = '\033[43m' + blue = '\033[44m' + purple = '\033[45m' + cyan = '\033[46m' + lightgrey = '\033[47m' + +# END + + +def exec(*cmd, **kwargs): + return subprocess.call(cmd, shell=False, stdout=sys.stdout, + stderr=sys.stderr, **kwargs) + + +def exec_chroot(*cmd, **kwargs): + return exec('systemd-nspawn', '-D', '/mnt/iso-update/squashfs-root', '--', *cmd, **kwargs) + + +def info(msg): + print(colors.bold + colors.fg.cyan + '>> i: ' + + colors.reset + colors.bold + msg + colors.reset) + + +def error(err): + print(colors.bold + colors.fg.red + '>> e: ' + + colors.reset + colors.bold + err + colors.reset) + + +def get_server_timestamp(): + with open('/etc/blend_release') as blend_release_file: + track = yaml.load(blend_release_file, Loader=yaml.FullLoader)['track'] + server_version_output = subprocess.run( + ['curl', '--silent', '--show-error', f'{server_url}/track/{track}/current'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if server_version_output.stderr.decode().strip() != '': + return 0 + elif server_version_output.stdout.decode().strip() != '' and server_version_output.stdout.decode().strip().isnumeric(): + return int(server_version_output.stdout.decode().strip()) + else: + return 0 + + +def update_system(): + os.chdir('/mnt') + exec('rm', '-rf', '/mnt/iso-update/iso') + exec('rm', '-rf', '/mnt/iso-update/squashfs-root') + exec('mkdir', '-p', '/mnt/iso-update') + + # Check if update is available + if os.path.isfile('/etc/blend_release'): + with open('/etc/blend_release') as blend_release_file: + blend_release = yaml.load( + blend_release_file, Loader=yaml.FullLoader) + current_timestamp = blend_release['current'] + track = blend_release['track'] + if get_server_timestamp() > current_timestamp: + # Update is available, let's download the latest ISO + exec('mkdir', '-p', '/mnt/iso-update') + if not os.path.isfile('/mnt/iso-update/update.iso'): + exec('wget', '-O', '/mnt/iso-update/update.iso', + f'{server_url}/track/{track}/download') + exec('rm', '-f', '/mnt/iso-update/update.iso.sha512sum') + exec('wget', '-O', '/mnt/iso-update/update.iso.sha512sum', + f'{server_url}/track/{track}/update-sha512sum') + if exec('bash', '-c', 'cd /mnt/iso-update; sha512sum --check --status /mnt/iso-update/update.iso.sha512sum') != 0: + exec('rm', '-f', '/mnt/iso-update/update.iso.sha512sum', + '/mnt/iso-update/update.iso.sha512sum') + exec('wget', '-O', '/mnt/iso-update/update.iso', + f'{server_url}/track/{track}/download') + exec('wget', '-O', '/mnt/iso-update/update.iso.sha512sum', + f'{server_url}/track/{track}/update-sha512sum') + if exec('sha512sum', '--check', '--status', 'update.iso.sha512sum', cwd='/mnt/iso-update') != 0: + exec('rm', '-f', '/mnt/iso-update/.download_lock') + return + exec('rm', '-f', '/mnt/iso-update/.download_lock') + + # Since the ISO has been downloaded, proceed to extracing it + # as well the rootfs it contains (single-core unsquashfs) + exec('rm', '-rf', '/mnt/iso-update/iso', + '/mnt/iso-update/squashfs-root') + exec('7z', '-oiso', 'x', 'update.iso', cwd='/mnt/iso-update') + if exec('unsquashfs', '-p', '1', f'iso/blend/{platform.machine()}/airootfs.sfs', cwd='/mnt/iso-update') != 0: + return + + ######################## + # Configure new rootfs # + ######################## + + # Enable services + exec_chroot('systemctl', 'enable', 'bluetooth') + exec_chroot('systemctl', 'enable', 'cups') + exec_chroot('systemctl', '--global', 'enable', 'blend-files') + + # Add akshara hook + exec_chroot( + 'bash', '-c', 'echo \'MODULES=""\' > /etc/mkinitcpio.conf') + exec_chroot( + 'bash', '-c', 'echo \'BINARIES=""\' >> /etc/mkinitcpio.conf') + exec_chroot( + 'bash', '-c', 'echo \'FILES=""\' >> /etc/mkinitcpio.conf') + exec_chroot( + 'bash', '-c', 'echo \'HOOKS="base udev akshara plymouth autodetect modconf block keyboard keymap consolefont filesystems fsck"\' >> /etc/mkinitcpio.conf') + exec_chroot( + 'bash', '-c', 'echo \'COMPRESSION="zstd"\' >> /etc/mkinitcpio.conf') + + # Refresh package lists, pacman-key --init + exec_chroot('pacman', '-Rn', '--noconfirm', + 'jade-gui', 'blend-inst-git') + exec_chroot('pacman-key', '--init') + exec_chroot('pacman-key', '--populate', 'archlinux', 'blend') + + # Disable auto-login for blend user + exec_chroot( + 'bash', '-c', 'echo "[Theme]" > /etc/sddm.conf.d/default.conf') + exec_chroot( + 'bash', '-c', 'echo "Current=breeze" >> /etc/sddm.conf.d/default.conf') + exec_chroot('rm', '-f', '/etc/gdm/custom.conf') + + # Note to self: since the hook only copies new files in /etc, configuring + # Note to self: locales and users isn't required + + # Mark as ready for update on boot + exec('touch', '/mnt/iso-update/.ready-for-update') + + # Unmount directories if not already unmounted + exec('umount', '-l', '/mnt/iso-update/squashfs-root/dev') + exec('umount', '-l', '/mnt/iso-update/squashfs-root/proc') + + +def update_daemon(): + while True: + if not os.path.isfile('/mnt/iso-update/.ready-for-update'): + update_system() + time.sleep(3600) + + +description = f''' +{colors.bold}{colors.fg.cyan}usage:{colors.reset} + {os.path.basename(sys.argv[0])} [command] [options] [arguments] + +{colors.bold}{colors.fg.cyan}version:{colors.reset} {__version}{colors.bold} + +This command is not meant to be used by regular users. + +{colors.bold}{colors.fg.cyan}available commands{colors.reset}: + {colors.bold}help{colors.reset} Show this help message and exit. + {colors.bold}version{colors.reset} Show version information and exit. + +{colors.bold}{colors.fg.cyan}options for commands{colors.reset}: + {colors.bold}-v, --version{colors.reset} show version information and exit +''' + +epilog = f''' +{colors.bold}Made with {colors.fg.red}\u2764{colors.reset}{colors.bold} by Rudra Saraswat.{colors.reset} +''' + +parser = argparse.ArgumentParser(description=description, usage=argparse.SUPPRESS, + epilog=epilog, formatter_class=argparse.RawTextHelpFormatter) +command_map = {'help': 'help', + 'version': 'version', + 'update-daemon': 'update_daemon'} +parser.add_argument('command', choices=command_map.keys(), + help=argparse.SUPPRESS) +parser.add_argument('-v', '--version', action='version', + version=f'%(prog)s {__version}', help=argparse.SUPPRESS) + +if len(sys.argv) == 1: + parser.print_help() + exit() + +if os.geteuid() != 0: + error('requires root') + exit(1) + +args = parser.parse_intermixed_args() + +command = command_map[args.command] + +if command == 'help': + parser.print_help() +elif command == 'version': + parser.parse_args(['--version']) +else: + globals()[command]() diff --git a/akshara.hook b/akshara.hook new file mode 100755 index 0000000..0724065 --- /dev/null +++ b/akshara.hook @@ -0,0 +1,27 @@ +#!/bin/bash + +run_latehook() { + echo + + # Detect if update downloaded. + if [[ -f /new_root/mnt/iso-update/.ready-for-update ]]; then + # Available, rename old /usr and move new /usr to /. + mv /new_root/usr /new_root/.old.usr + mv /new_root/mnt/iso-update/squashfs-root/usr /new_root/usr + + rm -f /new_root/mnt/iso-update/.ready-for-update + touch /new_root/mnt/iso-update/.etc-stage + fi + + # Detect if /etc stage is active. + if [[ -f /new_root/mnt/iso-update/.etc-stage ]]; then + # Rename existing /etc. + mv /new_root/etc /new_root/.old.etc &>/dev/null || : + + # Create new /etc. + cp -a /new_root/.old.etc /new_root/etc + + # Only copy non-existent files. + cp -a -n /new_root/mnt/iso-update/squashfs-root/etc/* /new_root/etc + fi +} From 038f5d2abfb2c509ffdacd45cf419501d613319a Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Sat, 6 May 2023 22:17:58 +0530 Subject: [PATCH 002/135] Add akshara.install, update akshara.hook --- akshara.hook | 18 ++++++++++++++++++ akshara.install | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 akshara.install diff --git a/akshara.hook b/akshara.hook index 0724065..a5afda8 100755 --- a/akshara.hook +++ b/akshara.hook @@ -9,6 +9,11 @@ run_latehook() { mv /new_root/usr /new_root/.old.usr mv /new_root/mnt/iso-update/squashfs-root/usr /new_root/usr + # Same for /var/lib. + mv /new_root/var/lib /new_root/.old.var.lib + mv /new_root/mnt/iso-update/squashfs-root/var/lib /new_root/var + + # Move to /etc stage. rm -f /new_root/mnt/iso-update/.ready-for-update touch /new_root/mnt/iso-update/.etc-stage fi @@ -23,5 +28,18 @@ run_latehook() { # Only copy non-existent files. cp -a -n /new_root/mnt/iso-update/squashfs-root/etc/* /new_root/etc + + # Update pacman config. + cp /new_root/mnt/iso-update/squashfs-root/etc/pacman.conf /new_root/etc + rm -rf /new_root/etc/pacman.d + cp -r /new_root/mnt/iso-update/squashfs-root/etc/pacman.d /new_root/etc + + # Successful update. + rm -f /new_root/mnt/iso-update/.etc-stage + touch /new_root/mnt/iso-update/.successful-update fi + + # Create overlay directories + rm -rf /new_root/.blend-overlays /new_root/.blendrw + mkdir -p /new_root/.blend-overlays/{usr,varlib,etcpacman} } diff --git a/akshara.install b/akshara.install new file mode 100644 index 0000000..16a2f51 --- /dev/null +++ b/akshara.install @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-3.0 + +build() { + add_module overlay + add_binary bash + add_binary findmnt + add_runscript +} + +help() { + cat < Date: Sun, 7 May 2023 11:46:13 +0530 Subject: [PATCH 003/135] Implement immutability --- akshara | 1 + akshara.hook | 42 +++++++++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/akshara b/akshara index 51c5810..722ff8a 100755 --- a/akshara +++ b/akshara @@ -209,6 +209,7 @@ description = f''' This command is not meant to be used by regular users. {colors.bold}{colors.fg.cyan}available commands{colors.reset}: + {colors.bold}help{colors.reset} Show this help message and exit. {colors.bold}help{colors.reset} Show this help message and exit. {colors.bold}version{colors.reset} Show version information and exit. diff --git a/akshara.hook b/akshara.hook index a5afda8..e0f509a 100755 --- a/akshara.hook +++ b/akshara.hook @@ -2,44 +2,64 @@ run_latehook() { echo - + # Detect if update downloaded. if [[ -f /new_root/mnt/iso-update/.ready-for-update ]]; then # Available, rename old /usr and move new /usr to /. mv /new_root/usr /new_root/.old.usr mv /new_root/mnt/iso-update/squashfs-root/usr /new_root/usr - + # Same for /var/lib. mv /new_root/var/lib /new_root/.old.var.lib mv /new_root/mnt/iso-update/squashfs-root/var/lib /new_root/var - + # Move to /etc stage. rm -f /new_root/mnt/iso-update/.ready-for-update touch /new_root/mnt/iso-update/.etc-stage fi - + # Detect if /etc stage is active. if [[ -f /new_root/mnt/iso-update/.etc-stage ]]; then # Rename existing /etc. mv /new_root/etc /new_root/.old.etc &>/dev/null || : - + # Create new /etc. cp -a /new_root/.old.etc /new_root/etc - + # Only copy non-existent files. cp -a -n /new_root/mnt/iso-update/squashfs-root/etc/* /new_root/etc - - # Update pacman config. + + # Update pacman config, and other system files that aren't + # supposed to be edited. cp /new_root/mnt/iso-update/squashfs-root/etc/pacman.conf /new_root/etc rm -rf /new_root/etc/pacman.d cp -r /new_root/mnt/iso-update/squashfs-root/etc/pacman.d /new_root/etc - + cp /new_root/mnt/iso-update/squashfs-root/etc/blend_release /new_root/etc + cp /new_root/mnt/iso-update/squashfs-root/etc/os-release /new_root/etc + cp /new_root/mnt/iso-update/squashfs-root/etc/lsb-release /new_root/etc + # Successful update. rm -f /new_root/mnt/iso-update/.etc-stage touch /new_root/mnt/iso-update/.successful-update fi - + # Create overlay directories rm -rf /new_root/.blend-overlays /new_root/.blendrw - mkdir -p /new_root/.blend-overlays/{usr,varlib,etcpacman} + + for i in usr varlibpacman; do + rm -rf /new_root/.blend-overlays/$i + mkdir -p /new_root/.blend-overlays/$i + mkdir -p /new_root/.blend-overlays/$i.workdir + done + + mount -t overlay overlay -o lowerdir=/new_root/usr:/new_root/.blend-overlays/usr /new_root/usr + mount -t overlay overlay -o lowerdir=/new_root/var/lib/pacman:/new_root/.blend-overlays/varlibpacman /new_root/var/lib/pacman + + mkdir -p /new_root/.blendrw + mount "$(findmnt /new_root)" /new_root/.blendrw + + mount -t overlay overlay -o lowerdir=/new_root/usr,upperdir=/new_root/.blend-overlays/usr,workdir=/new_root/.blend-overlays/usr.workdir + /new_root/.blendrw/usr + mount -t overlay overlay -o lowerdir=/new_root/var/lib/pacman,upperdir=/new_root/.blend-overlays/varlibpacman,workdir=/new_root/.blend-overlays/varlibpacman.workdir + /new_root/.blendrw/var/lib/pacman } From d158f6cf053be80614dd23c398694cd8f12bba30 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Sun, 7 May 2023 12:25:50 +0530 Subject: [PATCH 004/135] Replace /var/lib/pacman instead of /var/lib --- akshara.hook | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/akshara.hook b/akshara.hook index e0f509a..70720f8 100755 --- a/akshara.hook +++ b/akshara.hook @@ -9,9 +9,9 @@ run_latehook() { mv /new_root/usr /new_root/.old.usr mv /new_root/mnt/iso-update/squashfs-root/usr /new_root/usr - # Same for /var/lib. - mv /new_root/var/lib /new_root/.old.var.lib - mv /new_root/mnt/iso-update/squashfs-root/var/lib /new_root/var + # Same for /var/lib/pacman. + mv /new_root/var/lib/pacman /new_root/.old.var.lib.pacman + mv /new_root/mnt/iso-update/squashfs-root/var/lib/pacman /new_root/var/lib # Move to /etc stage. rm -f /new_root/mnt/iso-update/.ready-for-update From a5a683a1a464cdfd6c6460ae2dbdd6adc3e9070a Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Sun, 7 May 2023 13:15:06 +0530 Subject: [PATCH 005/135] Fix issues with mounting rw filesystem --- akshara.hook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara.hook b/akshara.hook index 70720f8..8d4aa48 100755 --- a/akshara.hook +++ b/akshara.hook @@ -56,7 +56,7 @@ run_latehook() { mount -t overlay overlay -o lowerdir=/new_root/var/lib/pacman:/new_root/.blend-overlays/varlibpacman /new_root/var/lib/pacman mkdir -p /new_root/.blendrw - mount "$(findmnt /new_root)" /new_root/.blendrw + mount "$(findmnt -n -o SOURCE /new_root)" /new_root/.blendrw mount -t overlay overlay -o lowerdir=/new_root/usr,upperdir=/new_root/.blend-overlays/usr,workdir=/new_root/.blend-overlays/usr.workdir /new_root/.blendrw/usr From 90a9c6542cdcc96fe54e0894576c951fd9789e0e Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Sun, 7 May 2023 20:48:07 +0530 Subject: [PATCH 006/135] Add akshara service --- akshara | 15 +++++++++------ akshara.hook | 37 ++++++++++++++++++++++++------------- akshara.install | 1 + akshara.service | 10 ++++++++++ 4 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 akshara.service diff --git a/akshara b/akshara index 722ff8a..049b3bc 100755 --- a/akshara +++ b/akshara @@ -21,6 +21,7 @@ import os import sys import time import yaml +import shutil import argparse import platform import subprocess @@ -193,7 +194,12 @@ def update_system(): exec('umount', '-l', '/mnt/iso-update/squashfs-root/proc') -def update_daemon(): +def daemon(): + exec('mkinitcpio', '-P') + exec('grub-mkconfig', '-o', '/boot/grub/grub.cfg') + for dir in os.listdir('/'): + if dir.startswith('.old.'): + shutil.rmtree('/' + dir) while True: if not os.path.isfile('/mnt/iso-update/.ready-for-update'): update_system() @@ -206,10 +212,7 @@ description = f''' {colors.bold}{colors.fg.cyan}version:{colors.reset} {__version}{colors.bold} -This command is not meant to be used by regular users. - {colors.bold}{colors.fg.cyan}available commands{colors.reset}: - {colors.bold}help{colors.reset} Show this help message and exit. {colors.bold}help{colors.reset} Show this help message and exit. {colors.bold}version{colors.reset} Show version information and exit. @@ -225,7 +228,7 @@ parser = argparse.ArgumentParser(description=description, usage=argparse.SUPPRES epilog=epilog, formatter_class=argparse.RawTextHelpFormatter) command_map = {'help': 'help', 'version': 'version', - 'update-daemon': 'update_daemon'} + 'daemon': daemon} parser.add_argument('command', choices=command_map.keys(), help=argparse.SUPPRESS) parser.add_argument('-v', '--version', action='version', @@ -248,4 +251,4 @@ if command == 'help': elif command == 'version': parser.parse_args(['--version']) else: - globals()[command]() + command() diff --git a/akshara.hook b/akshara.hook index 8d4aa48..cb6519e 100755 --- a/akshara.hook +++ b/akshara.hook @@ -8,11 +8,18 @@ run_latehook() { # Available, rename old /usr and move new /usr to /. mv /new_root/usr /new_root/.old.usr mv /new_root/mnt/iso-update/squashfs-root/usr /new_root/usr + + # Update /usr/lib/modules for current kernel version. + for kversion in /new_root/.old.usr/lib/modules/*; do + if [[ ! -d /new_root/usr/lib/modules/"$(basename "$kversion")" ]]; then + mv "$kversion" /new_root/usr/lib/modules/"$(basename "$kversion")" + fi + done # Same for /var/lib/pacman. mv /new_root/var/lib/pacman /new_root/.old.var.lib.pacman mv /new_root/mnt/iso-update/squashfs-root/var/lib/pacman /new_root/var/lib - + # Move to /etc stage. rm -f /new_root/mnt/iso-update/.ready-for-update touch /new_root/mnt/iso-update/.etc-stage @@ -37,29 +44,33 @@ run_latehook() { cp /new_root/mnt/iso-update/squashfs-root/etc/blend_release /new_root/etc cp /new_root/mnt/iso-update/squashfs-root/etc/os-release /new_root/etc cp /new_root/mnt/iso-update/squashfs-root/etc/lsb-release /new_root/etc + + # Replace kernel and microcode images. + mv /new_root/mnt/iso-update/iso/boot/initramfs-linux-zen.img /new_root/boot/initramfs-linux-zen.img + + if [[ -f /boot/amd-ucode.img ]]; then + mv /new_root/mnt/iso-update/iso/boot/amd-ucode.img /new_root/boot/amd-ucode.img + fi + if [[ -f /boot/intel-ucode.img ]]; then + mv /new_root/mnt/iso-update/iso/boot/intel-ucode.img /new_root/boot/intel-ucode.img + fi + # Successful update. rm -f /new_root/mnt/iso-update/.etc-stage touch /new_root/mnt/iso-update/.successful-update fi - # Create overlay directories + # Handle overlays. + rm -rf /new_root/.blend-overlays /new_root/.blendrw - for i in usr varlibpacman; do rm -rf /new_root/.blend-overlays/$i + rm -rf /new_root/.blend-overlays/$i.workdir mkdir -p /new_root/.blend-overlays/$i mkdir -p /new_root/.blend-overlays/$i.workdir done - mount -t overlay overlay -o lowerdir=/new_root/usr:/new_root/.blend-overlays/usr /new_root/usr - mount -t overlay overlay -o lowerdir=/new_root/var/lib/pacman:/new_root/.blend-overlays/varlibpacman /new_root/var/lib/pacman - - mkdir -p /new_root/.blendrw - mount "$(findmnt -n -o SOURCE /new_root)" /new_root/.blendrw - - mount -t overlay overlay -o lowerdir=/new_root/usr,upperdir=/new_root/.blend-overlays/usr,workdir=/new_root/.blend-overlays/usr.workdir - /new_root/.blendrw/usr - mount -t overlay overlay -o lowerdir=/new_root/var/lib/pacman,upperdir=/new_root/.blend-overlays/varlibpacman,workdir=/new_root/.blend-overlays/varlibpacman.workdir - /new_root/.blendrw/var/lib/pacman + mount -t overlay overlay -o ro,lowerdir=/new_root/usr,upperdir=/new_root/.blend-overlays/usr,workdir=/new_root/.blend-overlays/usr.workdir /new_root/usr + mount -t overlay overlay -o ro,lowerdir=/new_root/var/lib/pacman,upperdir=/new_root/.blend-overlays/varlibpacman,workdir=/new_root/.blend-overlays/varlibpacman.workdir /new_root/var/lib/pacman } diff --git a/akshara.install b/akshara.install index 16a2f51..7d9d6c3 100644 --- a/akshara.install +++ b/akshara.install @@ -5,6 +5,7 @@ build() { add_module overlay add_binary bash add_binary findmnt + add_binary uname add_runscript } diff --git a/akshara.service b/akshara.service new file mode 100644 index 0000000..60112af --- /dev/null +++ b/akshara.service @@ -0,0 +1,10 @@ +[Unit] +Description=Handle system operations + +[Service] +Type=simple +ExecStart=/usr/bin/akshara daemon +User=root + +[Install] +WantedBy=multi-user.target From e568585c4078aa775b4f16ca00c3a7196e76c123 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 22:17:54 +0530 Subject: [PATCH 007/135] Add initial code for system package installation support --- akshara | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/akshara b/akshara index 049b3bc..6f815cb 100755 --- a/akshara +++ b/akshara @@ -21,6 +21,7 @@ import os import sys import time import yaml +import psutil import shutil import argparse import platform @@ -76,8 +77,20 @@ class colors: def exec(*cmd, **kwargs): - return subprocess.call(cmd, shell=False, stdout=sys.stdout, - stderr=sys.stderr, **kwargs) + return subprocess.call(cmd, shell=False, **kwargs) + + +def is_running(): + instances = 0 + + for p in psutil.process_iter(): + if p.name() == 'python3': + if len(p.cmdline()) > 0 and 'akshara' in p.cmdline()[1]: + instances += 1 + if instances == 2: + return True + + return False def exec_chroot(*cmd, **kwargs): @@ -194,6 +207,37 @@ def update_system(): exec('umount', '-l', '/mnt/iso-update/squashfs-root/proc') +def install_system_package(): + if is_running(): + error('already running') + exit(1) + + exec('mkdir', '-p', '/.blendrw') + if exec('findmnt', '/.blendrw/usr') != 0: + exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + if exec('findmnt', '/.blendrw/var/lib/pacman') != 0: + exec('umount', '-l', '/.blendrw/var/lib/pacman', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + if exec('findmnt', '/.blendrw') != 0: + exec('umount', '-l', '/.blendrw', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + for old_overlay in os.listdir('/mnt'): + if old_overlay.startswith('.blend-tmp-overlay-'): + exec('rm', '-rf', f'/mnt/{old_overlay}') + usr_overlay = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode() + usr_overlay_workdir = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode() + varlibpacman_overlay = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode() + varlibpacman_overlay_workdir = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode() + if '' in (usr_overlay, usr_overlay_workdir, varlibpacman_overlay, varlibpacman_overlay_workdir): + for old_overlay in os.listdir('/mnt'): + if old_overlay.startswith('.blend-tmp-overlay-'): + exec('rm', '-rf', f'/mnt/{old_overlay}') + error('error during overlay creation') + exit(1) + exec('mkdir', '-p', '/.blend-rw') + exec('mount', subprocess.run(['findmnt', '-n', '-o', 'SOURCE', '/'], stdout=subprocess.PIPE).stdout.decode(), '/.blend-rw') + exec('mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/usr,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/.blend-rw/usr') + exec('mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/.blend-rw/var/lib/pacman') + + def daemon(): exec('mkinitcpio', '-P') exec('grub-mkconfig', '-o', '/boot/grub/grub.cfg') @@ -228,9 +272,12 @@ parser = argparse.ArgumentParser(description=description, usage=argparse.SUPPRES epilog=epilog, formatter_class=argparse.RawTextHelpFormatter) command_map = {'help': 'help', 'version': 'version', + 'install': install_system_package, 'daemon': daemon} parser.add_argument('command', choices=command_map.keys(), help=argparse.SUPPRESS) +parser.add_argument('-y', '--noconfirm', + action='store_true', help=argparse.SUPPRESS) parser.add_argument('-v', '--version', action='version', version=f'%(prog)s {__version}', help=argparse.SUPPRESS) @@ -238,7 +285,7 @@ if len(sys.argv) == 1: parser.print_help() exit() -if os.geteuid() != 0: +if os.geteuid() != 0 and not sys.argv[1] in ('help', 'version', '-v', '--version'): error('requires root') exit(1) From 46c90bfa71f89bf57d5b006250e686f98e8d5a0e Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 22:20:08 +0530 Subject: [PATCH 008/135] Trim decoded stdout --- akshara | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/akshara b/akshara index 6f815cb..ae9c68c 100755 --- a/akshara +++ b/akshara @@ -222,10 +222,10 @@ def install_system_package(): for old_overlay in os.listdir('/mnt'): if old_overlay.startswith('.blend-tmp-overlay-'): exec('rm', '-rf', f'/mnt/{old_overlay}') - usr_overlay = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode() - usr_overlay_workdir = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode() - varlibpacman_overlay = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode() - varlibpacman_overlay_workdir = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode() + usr_overlay = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().trim() + usr_overlay_workdir = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().trim() + varlibpacman_overlay = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().trim() + varlibpacman_overlay_workdir = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().trim() if '' in (usr_overlay, usr_overlay_workdir, varlibpacman_overlay, varlibpacman_overlay_workdir): for old_overlay in os.listdir('/mnt'): if old_overlay.startswith('.blend-tmp-overlay-'): @@ -233,7 +233,7 @@ def install_system_package(): error('error during overlay creation') exit(1) exec('mkdir', '-p', '/.blend-rw') - exec('mount', subprocess.run(['findmnt', '-n', '-o', 'SOURCE', '/'], stdout=subprocess.PIPE).stdout.decode(), '/.blend-rw') + exec('mount', subprocess.run(['findmnt', '-n', '-o', 'SOURCE', '/'], stdout=subprocess.PIPE).stdout.decode().trim(), '/.blend-rw') exec('mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/usr,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/.blend-rw/usr') exec('mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/.blend-rw/var/lib/pacman') From 955db5b17ac1ee7b88f52883d2053ddb493cea94 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 22:20:53 +0530 Subject: [PATCH 009/135] trim() -> strip() --- akshara | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/akshara b/akshara index ae9c68c..9eec4cf 100755 --- a/akshara +++ b/akshara @@ -222,10 +222,10 @@ def install_system_package(): for old_overlay in os.listdir('/mnt'): if old_overlay.startswith('.blend-tmp-overlay-'): exec('rm', '-rf', f'/mnt/{old_overlay}') - usr_overlay = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().trim() - usr_overlay_workdir = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().trim() - varlibpacman_overlay = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().trim() - varlibpacman_overlay_workdir = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().trim() + usr_overlay = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + usr_overlay_workdir = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + varlibpacman_overlay = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + varlibpacman_overlay_workdir = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() if '' in (usr_overlay, usr_overlay_workdir, varlibpacman_overlay, varlibpacman_overlay_workdir): for old_overlay in os.listdir('/mnt'): if old_overlay.startswith('.blend-tmp-overlay-'): @@ -233,7 +233,7 @@ def install_system_package(): error('error during overlay creation') exit(1) exec('mkdir', '-p', '/.blend-rw') - exec('mount', subprocess.run(['findmnt', '-n', '-o', 'SOURCE', '/'], stdout=subprocess.PIPE).stdout.decode().trim(), '/.blend-rw') + exec('mount', subprocess.run(['findmnt', '-n', '-o', 'SOURCE', '/'], stdout=subprocess.PIPE).stdout.decode().strip(), '/.blend-rw') exec('mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/usr,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/.blend-rw/usr') exec('mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/.blend-rw/var/lib/pacman') From d016275a71a8ab2de3d37bde719fc7cf5feb7950 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 22:21:58 +0530 Subject: [PATCH 010/135] blend-rw -> blendrw --- akshara | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/akshara b/akshara index 9eec4cf..8587e64 100755 --- a/akshara +++ b/akshara @@ -232,10 +232,10 @@ def install_system_package(): exec('rm', '-rf', f'/mnt/{old_overlay}') error('error during overlay creation') exit(1) - exec('mkdir', '-p', '/.blend-rw') - exec('mount', subprocess.run(['findmnt', '-n', '-o', 'SOURCE', '/'], stdout=subprocess.PIPE).stdout.decode().strip(), '/.blend-rw') - exec('mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/usr,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/.blend-rw/usr') - exec('mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/.blend-rw/var/lib/pacman') + exec('mkdir', '-p', '/.blendrw') + exec('mount', subprocess.run(['findmnt', '-n', '-o', 'SOURCE', '/'], stdout=subprocess.PIPE).stdout.decode().strip(), '/.blendrw') + exec('mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/usr,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/.blendrw/usr') + exec('mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/.blendrw/var/lib/pacman') def daemon(): From 6ef4c3e19784f462686e43d21dc310f65f5f19fb Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 22:28:09 +0530 Subject: [PATCH 011/135] Update overlay unmount code --- akshara | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/akshara b/akshara index 8587e64..df81956 100755 --- a/akshara +++ b/akshara @@ -213,12 +213,12 @@ def install_system_package(): exit(1) exec('mkdir', '-p', '/.blendrw') - if exec('findmnt', '/.blendrw/usr') != 0: - exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - if exec('findmnt', '/.blendrw/var/lib/pacman') != 0: - exec('umount', '-l', '/.blendrw/var/lib/pacman', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - if exec('findmnt', '/.blendrw') != 0: - exec('umount', '-l', '/.blendrw', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: + pass + while exec('umount', '-l', '/.blendrw/var/lib/pacman', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: + pass + while exec('umount', '-l', '/.blendrw', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: + pass for old_overlay in os.listdir('/mnt'): if old_overlay.startswith('.blend-tmp-overlay-'): exec('rm', '-rf', f'/mnt/{old_overlay}') From eb2eef08e59ce31b2c8990d8abfb85d6a189d935 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 22:55:14 +0530 Subject: [PATCH 012/135] Preliminary support for overlayed packages --- akshara | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 8 deletions(-) diff --git a/akshara b/akshara index df81956..6d861c5 100755 --- a/akshara +++ b/akshara @@ -207,7 +207,7 @@ def update_system(): exec('umount', '-l', '/mnt/iso-update/squashfs-root/proc') -def install_system_package(): +def handle_system_packages(install): if is_running(): error('already running') exit(1) @@ -237,6 +237,54 @@ def install_system_package(): exec('mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/usr,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/.blendrw/usr') exec('mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/.blendrw/var/lib/pacman') + if install == 'install': + operation = ['-Sy'] + if args.noconfirm: + operation.append('--noconfirm') + elif install == 'remove': + operation = '-Rn' + if args.noconfirm: + operation.append('--noconfirm') + + if exec('systemd-nspawn', 'pacman', *operation, '--', *args.pkg) != 0: + error('error occurred during installation, abandoning changes') + while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: + pass + while exec('umount', '-l', '/.blendrw/var/lib/pacman', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: + pass + while exec('umount', '-l', '/.blendrw', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: + pass + for old_overlay in os.listdir('/mnt'): + if old_overlay.startswith('.blend-tmp-overlay-'): + exec('rm', '-rf', f'/mnt/{old_overlay}') + elif args.headless: + while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: + pass + while exec('umount', '-l', '/.blendrw/var/lib/pacman', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: + pass + while exec('umount', '-l', '/.blendrw', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: + pass + exec('mv', usr_overlay, '/.blend-overlays/future-usr') + exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') + exec('rm', '-rf', usr_overlay_workdir, varlibpacman_overlay_workdir) + else: + info("you are requested to review the operation's output") + info("press ENTER to proceed with making overlay permanent, or ^C to abort") + try: + input() + except EOFError: + exit() + + while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: + pass + while exec('umount', '-l', '/.blendrw/var/lib/pacman', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: + pass + while exec('umount', '-l', '/.blendrw', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: + pass + exec('mv', usr_overlay, '/.blend-overlays/future-usr') + exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') + exec('rm', '-rf', usr_overlay_workdir, varlibpacman_overlay_workdir) + def daemon(): exec('mkinitcpio', '-P') @@ -272,12 +320,15 @@ parser = argparse.ArgumentParser(description=description, usage=argparse.SUPPRES epilog=epilog, formatter_class=argparse.RawTextHelpFormatter) command_map = {'help': 'help', 'version': 'version', - 'install': install_system_package, + 'install': handle_system_packages, + 'remove': handle_system_packages, 'daemon': daemon} parser.add_argument('command', choices=command_map.keys(), help=argparse.SUPPRESS) parser.add_argument('-y', '--noconfirm', action='store_true', help=argparse.SUPPRESS) +parser.add_argument('--headless', + action='store_true', help=argparse.SUPPRESS) parser.add_argument('-v', '--version', action='version', version=f'%(prog)s {__version}', help=argparse.SUPPRESS) @@ -293,9 +344,14 @@ args = parser.parse_intermixed_args() command = command_map[args.command] -if command == 'help': - parser.print_help() -elif command == 'version': - parser.parse_args(['--version']) -else: - command() +try: + if command == 'help': + parser.print_help() + elif command == 'version': + parser.parse_args(['--version']) + elif command == handle_system_packages: + command(args.command) + else: + command() +except: + error('aborting') \ No newline at end of file From 9423959ea1d0fe9b59e9d861b2180c08d42a4576 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 22:59:45 +0530 Subject: [PATCH 013/135] Add packages argument to argparse --- akshara | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/akshara b/akshara index 6d861c5..6d06521 100755 --- a/akshara +++ b/akshara @@ -208,6 +208,10 @@ def update_system(): def handle_system_packages(install): + if len(args.pkgs) == 0: + error('no packages specified') + exit(1) + if is_running(): error('already running') exit(1) @@ -222,10 +226,14 @@ def handle_system_packages(install): for old_overlay in os.listdir('/mnt'): if old_overlay.startswith('.blend-tmp-overlay-'): exec('rm', '-rf', f'/mnt/{old_overlay}') - usr_overlay = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - usr_overlay_workdir = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - varlibpacman_overlay = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - varlibpacman_overlay_workdir = subprocess.run(['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + usr_overlay = subprocess.run( + ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + usr_overlay_workdir = subprocess.run( + ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + varlibpacman_overlay = subprocess.run( + ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + varlibpacman_overlay_workdir = subprocess.run( + ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() if '' in (usr_overlay, usr_overlay_workdir, varlibpacman_overlay, varlibpacman_overlay_workdir): for old_overlay in os.listdir('/mnt'): if old_overlay.startswith('.blend-tmp-overlay-'): @@ -233,9 +241,12 @@ def handle_system_packages(install): error('error during overlay creation') exit(1) exec('mkdir', '-p', '/.blendrw') - exec('mount', subprocess.run(['findmnt', '-n', '-o', 'SOURCE', '/'], stdout=subprocess.PIPE).stdout.decode().strip(), '/.blendrw') - exec('mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/usr,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/.blendrw/usr') - exec('mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/.blendrw/var/lib/pacman') + exec('mount', subprocess.run(['findmnt', '-n', '-o', 'SOURCE', '/'], + stdout=subprocess.PIPE).stdout.decode().strip(), '/.blendrw') + exec('mount', '-t', 'overlay', 'overlay', '-o', + f'lowerdir=/usr,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/.blendrw/usr') + exec('mount', '-t', 'overlay', 'overlay', '-o', + f'lowerdir=/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/.blendrw/var/lib/pacman') if install == 'install': operation = ['-Sy'] @@ -325,6 +336,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('-y', '--noconfirm', action='store_true', help=argparse.SUPPRESS) parser.add_argument('--headless', @@ -354,4 +367,4 @@ try: else: command() except: - error('aborting') \ No newline at end of file + error('aborting') From 3b3f9866326b90807124c3a58f32aff3dfac467d Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 23:00:22 +0530 Subject: [PATCH 014/135] Do not use generic except: --- akshara | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara b/akshara index 6d06521..64e4f0b 100755 --- a/akshara +++ b/akshara @@ -366,5 +366,5 @@ try: command(args.command) else: command() -except: +except KeyboardInterrupt: error('aborting') From b161e5631f97768a8ab43b20b4a7ab25e52f1d4d Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 23:00:47 +0530 Subject: [PATCH 015/135] args.pkgs -> args.pkg --- akshara | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara b/akshara index 64e4f0b..217deb6 100755 --- a/akshara +++ b/akshara @@ -208,7 +208,7 @@ def update_system(): def handle_system_packages(install): - if len(args.pkgs) == 0: + if len(args.pkg) == 0: error('no packages specified') exit(1) From a3c5a7ffd4f1c4c8161480913ff6fb3ded166bff Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 23:03:00 +0530 Subject: [PATCH 016/135] Pass dir to systemd-nspawn --- akshara | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara b/akshara index 217deb6..1584860 100755 --- a/akshara +++ b/akshara @@ -257,7 +257,7 @@ def handle_system_packages(install): if args.noconfirm: operation.append('--noconfirm') - if exec('systemd-nspawn', 'pacman', *operation, '--', *args.pkg) != 0: + if exec('systemd-nspawn', '-D', '/.blendrw', '--', 'pacman', *operation, '--', *args.pkg) != 0: error('error occurred during installation, abandoning changes') while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: pass From ef78a2cb6be8bb48c9cc02a12547f7f74c35b4d5 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 23:04:31 +0530 Subject: [PATCH 017/135] Pass to sys.stdout and sys.stderr --- akshara | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara b/akshara index 1584860..8a23780 100755 --- a/akshara +++ b/akshara @@ -257,7 +257,7 @@ def handle_system_packages(install): if args.noconfirm: operation.append('--noconfirm') - if exec('systemd-nspawn', '-D', '/.blendrw', '--', 'pacman', *operation, '--', *args.pkg) != 0: + if exec('systemd-nspawn', '-D', '/.blendrw', '--', 'pacman', *operation, '--', *args.pkg, stdout=sys.stdout, stderr=sys.stderr) != 0: error('error occurred during installation, abandoning changes') while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: pass From 08ec032b4183f9e5f5ecdeb4f4fbcc20984f779a Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 23:06:58 +0530 Subject: [PATCH 018/135] != -> == --- akshara | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/akshara b/akshara index 8a23780..7c52211 100755 --- a/akshara +++ b/akshara @@ -217,11 +217,11 @@ def handle_system_packages(install): exit(1) exec('mkdir', '-p', '/.blendrw') - while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: + while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0: pass - while exec('umount', '-l', '/.blendrw/var/lib/pacman', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: + while exec('umount', '-l', '/.blendrw/var/lib/pacman', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0: pass - while exec('umount', '-l', '/.blendrw', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: + while exec('umount', '-l', '/.blendrw', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0: pass for old_overlay in os.listdir('/mnt'): if old_overlay.startswith('.blend-tmp-overlay-'): From 083a1e29d5d8f588ae55e304f3b1320993d569b4 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 23:11:45 +0530 Subject: [PATCH 019/135] Open up permissions for temp overlays --- akshara | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/akshara b/akshara index 7c52211..1bd7140 100755 --- a/akshara +++ b/akshara @@ -228,12 +228,16 @@ def handle_system_packages(install): exec('rm', '-rf', f'/mnt/{old_overlay}') usr_overlay = subprocess.run( ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + exec('chmod', '=rw', usr_overlay) usr_overlay_workdir = subprocess.run( ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + exec('chmod', '=rw', usr_overlay_workdir) varlibpacman_overlay = subprocess.run( ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + exec('chmod', '=rw', varlibpacman_overlay) varlibpacman_overlay_workdir = subprocess.run( ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + exec('chmod', '=rw', varlibpacman_overlay_workdir) if '' in (usr_overlay, usr_overlay_workdir, varlibpacman_overlay, varlibpacman_overlay_workdir): for old_overlay in os.listdir('/mnt'): if old_overlay.startswith('.blend-tmp-overlay-'): From a276c0020ef440130a13e7d7911225d8c5f6c49c Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 23:16:04 +0530 Subject: [PATCH 020/135] add warnings --- akshara | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/akshara b/akshara index 1bd7140..7184472 100755 --- a/akshara +++ b/akshara @@ -216,6 +216,12 @@ def handle_system_packages(install): error('already running') exit(1) + info('this command will discard any system packages installed') + info("previously if you didn't reboot after instlling them") + print() + info('this should __only__ be used for the installation of drivers') + info('blendOS is __not__ responsible for any system breakage') + exec('mkdir', '-p', '/.blendrw') while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0: pass @@ -282,6 +288,7 @@ def handle_system_packages(install): exec('mv', usr_overlay, '/.blend-overlays/future-usr') exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') exec('rm', '-rf', usr_overlay_workdir, varlibpacman_overlay_workdir) + info('reboot to apply changes') else: info("you are requested to review the operation's output") info("press ENTER to proceed with making overlay permanent, or ^C to abort") @@ -299,6 +306,7 @@ def handle_system_packages(install): exec('mv', usr_overlay, '/.blend-overlays/future-usr') exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') exec('rm', '-rf', usr_overlay_workdir, varlibpacman_overlay_workdir) + info('reboot to apply changes') def daemon(): From 3735588e935d1a6e935fb6f6cc97cca078c9b991 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 23:21:33 +0530 Subject: [PATCH 021/135] Reuse old future overlay --- akshara | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/akshara b/akshara index 7184472..6d94360 100755 --- a/akshara +++ b/akshara @@ -216,10 +216,10 @@ def handle_system_packages(install): error('already running') exit(1) - info('this command will discard any system packages installed') - info("previously if you didn't reboot after instlling them") + info("if this operation fails, any system packages installed previously") + info('without rebooting shall be removed') print() - info('this should __only__ be used for the installation of drivers') + info('this command should __only__ be used for the installation of drivers') info('blendOS is __not__ responsible for any system breakage') exec('mkdir', '-p', '/.blendrw') @@ -235,12 +235,20 @@ def handle_system_packages(install): usr_overlay = subprocess.run( ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() exec('chmod', '=rw', usr_overlay) + if os.path.isdir('/.blend-overlays/future-usr'): + exec('rm', '-f', '/.blend-overlays/future-usr/.okay') + exec('rm', '-rf', usr_overlay) + exec('mv', '/.blend-overlays/future-usr', usr_overlay) usr_overlay_workdir = subprocess.run( ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() exec('chmod', '=rw', usr_overlay_workdir) varlibpacman_overlay = subprocess.run( ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() exec('chmod', '=rw', varlibpacman_overlay) + if os.path.isdir('/.blend-overlays/future-varlibpacman'): + exec('rm', '-f', '/.blend-overlays/future-varlibpacman/.okay') + exec('rm', '-rf', varlibpacman_overlay) + exec('mv', '/.blend-overlays/future-varlibpacman', usr_overlay) varlibpacman_overlay_workdir = subprocess.run( ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() exec('chmod', '=rw', varlibpacman_overlay_workdir) @@ -306,6 +314,8 @@ def handle_system_packages(install): exec('mv', usr_overlay, '/.blend-overlays/future-usr') exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') exec('rm', '-rf', usr_overlay_workdir, varlibpacman_overlay_workdir) + exec('touch', '/.blend-overlays/future-usr/.okay') + exec('touch', '/.blend-overlays/future-varlibpacman/.okay') info('reboot to apply changes') From 966f0b06aafd21e45f26b541ef2056355da55922 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 23:23:42 +0530 Subject: [PATCH 022/135] Check if package name is invalid --- akshara | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/akshara b/akshara index 6d94360..2143807 100755 --- a/akshara +++ b/akshara @@ -212,6 +212,11 @@ def handle_system_packages(install): error('no packages specified') exit(1) + for pkg in args.pkg: + if pkg.startswith('-'): + error(f'invalid package {pkg}') + exit(1) + if is_running(): error('already running') exit(1) @@ -275,7 +280,7 @@ def handle_system_packages(install): if args.noconfirm: operation.append('--noconfirm') - if exec('systemd-nspawn', '-D', '/.blendrw', '--', 'pacman', *operation, '--', *args.pkg, stdout=sys.stdout, stderr=sys.stderr) != 0: + if exec('systemd-nspawn', '-D', '/.blendrw', 'pacman', *operation, *args.pkg, stdout=sys.stdout, stderr=sys.stderr) != 0: error('error occurred during installation, abandoning changes') while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: pass From e56db5778e940583fcffdf24b824257f63c59494 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 23:24:54 +0530 Subject: [PATCH 023/135] Add -- back --- akshara | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/akshara b/akshara index 2143807..190adf4 100755 --- a/akshara +++ b/akshara @@ -276,11 +276,11 @@ def handle_system_packages(install): if args.noconfirm: operation.append('--noconfirm') elif install == 'remove': - operation = '-Rn' + operation = ['-Rn'] if args.noconfirm: operation.append('--noconfirm') - if exec('systemd-nspawn', '-D', '/.blendrw', 'pacman', *operation, *args.pkg, stdout=sys.stdout, stderr=sys.stderr) != 0: + if exec('systemd-nspawn', '-D', '/.blendrw', '--', 'pacman', '--', *operation, *args.pkg, stdout=sys.stdout, stderr=sys.stderr) != 0: error('error occurred during installation, abandoning changes') while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: pass From 92d73bb16189cd03f9e501ddade2cd20b5a3a5a1 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 23:25:24 +0530 Subject: [PATCH 024/135] Update position of -- --- akshara | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara b/akshara index 190adf4..8bb580d 100755 --- a/akshara +++ b/akshara @@ -280,7 +280,7 @@ def handle_system_packages(install): if args.noconfirm: operation.append('--noconfirm') - if exec('systemd-nspawn', '-D', '/.blendrw', '--', 'pacman', '--', *operation, *args.pkg, stdout=sys.stdout, stderr=sys.stderr) != 0: + if exec('systemd-nspawn', '-D', '/.blendrw', '--', 'pacman', *operation, '--', *args.pkg, stdout=sys.stdout, stderr=sys.stderr) != 0: error('error occurred during installation, abandoning changes') while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: pass From a1253ba02d76b3ca0c5d9dc3021f59c33cc7b3fd Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 23:27:03 +0530 Subject: [PATCH 025/135] Fix typo --- akshara | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara b/akshara index 8bb580d..c9fcc16 100755 --- a/akshara +++ b/akshara @@ -253,7 +253,7 @@ def handle_system_packages(install): if os.path.isdir('/.blend-overlays/future-varlibpacman'): exec('rm', '-f', '/.blend-overlays/future-varlibpacman/.okay') exec('rm', '-rf', varlibpacman_overlay) - exec('mv', '/.blend-overlays/future-varlibpacman', usr_overlay) + exec('mv', '/.blend-overlays/future-varlibpacman', varlibpacman_overlay) varlibpacman_overlay_workdir = subprocess.run( ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() exec('chmod', '=rw', varlibpacman_overlay_workdir) From 958e1bc7382e7437d1268c8941bc5f3d2336e7b3 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 8 May 2023 23:31:36 +0530 Subject: [PATCH 026/135] Add warnings to help message --- akshara | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/akshara b/akshara index c9fcc16..1e60cf3 100755 --- a/akshara +++ b/akshara @@ -305,6 +305,7 @@ def handle_system_packages(install): else: info("you are requested to review the operation's output") info("press ENTER to proceed with making overlay permanent, or ^C to abort") + info("(aborting will also remove any packages installed previously without rebooting)") try: input() except EOFError: @@ -342,8 +343,14 @@ description = f''' {colors.bold}{colors.fg.cyan}version:{colors.reset} {__version}{colors.bold} +This CLI is only meant for developers familiar with blendOS and the akshara codebase. + +blendOS is not responsible for any system breakage. + {colors.bold}{colors.fg.cyan}available commands{colors.reset}: {colors.bold}help{colors.reset} Show this help message and exit. + {colors.bold}install{colors.reset} Install system drivers/packages. + {colors.bold}remove{colors.reset} Remove system drivers/packages. {colors.bold}version{colors.reset} Show version information and exit. {colors.bold}{colors.fg.cyan}options for commands{colors.reset}: From ad66b4e6a707c487b0c5ba604fc4a210e6aaabf0 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Tue, 9 May 2023 11:51:59 +0530 Subject: [PATCH 027/135] Handle future overlays --- akshara | 66 ++++++++++++++++++++++++---------------------------- akshara.hook | 21 +++++++++++++---- 2 files changed, 48 insertions(+), 39 deletions(-) diff --git a/akshara b/akshara index 1e60cf3..5a46531 100755 --- a/akshara +++ b/akshara @@ -21,12 +21,13 @@ import os import sys import time import yaml -import psutil import shutil import argparse import platform import subprocess +from lockfile import LockFile + __version = '1.0.0' with open('/etc/blend_release') as blend_release_file: @@ -80,19 +81,6 @@ def exec(*cmd, **kwargs): return subprocess.call(cmd, shell=False, **kwargs) -def is_running(): - instances = 0 - - for p in psutil.process_iter(): - if p.name() == 'python3': - if len(p.cmdline()) > 0 and 'akshara' in p.cmdline()[1]: - instances += 1 - if instances == 2: - return True - - return False - - def exec_chroot(*cmd, **kwargs): return exec('systemd-nspawn', '-D', '/mnt/iso-update/squashfs-root', '--', *cmd, **kwargs) @@ -207,25 +195,24 @@ def update_system(): exec('umount', '-l', '/mnt/iso-update/squashfs-root/proc') -def handle_system_packages(install): +def handle_system_packages(operation): if len(args.pkg) == 0: error('no packages specified') exit(1) - for pkg in args.pkg: - if pkg.startswith('-'): - error(f'invalid package {pkg}') - exit(1) - - if is_running(): - error('already running') - exit(1) - - info("if this operation fails, any system packages installed previously") - info('without rebooting shall be removed') + if operation == 'set-custom-packages': + info('this operation will replace the current overlay on the next boot') + info('(any custom system packages/drivers installed earlier will be removed)') + print() + info('this command should __only__ be used for the installation of drivers') + info('blendOS is __not__ responsible for any system breakage') + elif operation == 'drop-packages': + info('any installed packages will be removed') + else: + error('unsupported operation') print() - info('this command should __only__ be used for the installation of drivers') - info('blendOS is __not__ responsible for any system breakage') + + time.sleep(2) exec('mkdir', '-p', '/.blendrw') while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0: @@ -271,14 +258,14 @@ def handle_system_packages(install): exec('mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/.blendrw/var/lib/pacman') - if install == 'install': + if operation == 'set-custom-packages': operation = ['-Sy'] if args.noconfirm: operation.append('--noconfirm') - elif install == 'remove': - operation = ['-Rn'] - if args.noconfirm: - operation.append('--noconfirm') + elif operation == 'drop-overlay': + exec('rm', '-f', '/.blend-overlays/future-usr/.okay') + exec('rm', '-f', '/.blend-overlays/future-varlibpacman/.okay') + exit() if exec('systemd-nspawn', '-D', '/.blendrw', '--', 'pacman', *operation, '--', *args.pkg, stdout=sys.stdout, stderr=sys.stderr) != 0: error('error occurred during installation, abandoning changes') @@ -301,6 +288,8 @@ def handle_system_packages(install): exec('mv', usr_overlay, '/.blend-overlays/future-usr') exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') exec('rm', '-rf', usr_overlay_workdir, varlibpacman_overlay_workdir) + exec('touch', '/.blend-overlays/future-usr/.okay') + exec('touch', '/.blend-overlays/future-varlibpacman/.okay') info('reboot to apply changes') else: info("you are requested to review the operation's output") @@ -365,8 +354,8 @@ parser = argparse.ArgumentParser(description=description, usage=argparse.SUPPRES epilog=epilog, formatter_class=argparse.RawTextHelpFormatter) command_map = {'help': 'help', 'version': 'version', - 'install': handle_system_packages, - 'remove': handle_system_packages, + 'set-custom-packages': handle_system_packages, + 'drop-overlay': handle_system_packages, 'daemon': daemon} parser.add_argument('command', choices=command_map.keys(), help=argparse.SUPPRESS) @@ -397,6 +386,13 @@ try: elif command == 'version': parser.parse_args(['--version']) elif command == handle_system_packages: + exec('touch', '/var/lib/.akshara-system-lock') + system_lock = LockFile('/var/lib/.akshara-system-lock') + if not system_lock.is_locked(): + system_lock.acquire() + else: + error('system operation already in progress') + exit(1) command(args.command) else: command() diff --git a/akshara.hook b/akshara.hook index cb6519e..cdba8e3 100755 --- a/akshara.hook +++ b/akshara.hook @@ -2,7 +2,10 @@ run_latehook() { echo - + + # Remove /new_root/mnt/iso-update/.successful-update if exists + rm -f /new_root/mnt/iso-update/.successful-update + # Detect if update downloaded. if [[ -f /new_root/mnt/iso-update/.ready-for-update ]]; then # Available, rename old /usr and move new /usr to /. @@ -63,10 +66,20 @@ run_latehook() { # Handle overlays. - rm -rf /new_root/.blend-overlays /new_root/.blendrw + if [[ ! -f /new_root/mnt/iso-update/.successful-update ]]; then + if [[ -f '/new_root/.blend-overlays/future-usr/.okay' ]] && [[ -f '/new_root/.blend-overlays/future-varlibpacman/.okay' ]]; then + for i in usr varlibpacman; do + rm -rf /new_root/.blend-overlays/$i + mv /new_root/.blend-overlays/future-$i /new_root/.blend-overlays/$i + done + else + rm -rf /new_root/.blend-overlays /new_root/.blendrw + fi + else + rm -rf /new_root/.blend-overlays /new_root/.blendrw + fi + for i in usr varlibpacman; do - rm -rf /new_root/.blend-overlays/$i - rm -rf /new_root/.blend-overlays/$i.workdir mkdir -p /new_root/.blend-overlays/$i mkdir -p /new_root/.blend-overlays/$i.workdir done From de08a1553bbd3a14f82dcf6348acfd33ec1282dd Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Tue, 9 May 2023 11:56:45 +0530 Subject: [PATCH 028/135] Remove --noconfirm --- akshara | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/akshara b/akshara index 5a46531..bf2e9cc 100755 --- a/akshara +++ b/akshara @@ -259,9 +259,7 @@ def handle_system_packages(operation): f'lowerdir=/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/.blendrw/var/lib/pacman') if operation == 'set-custom-packages': - operation = ['-Sy'] - if args.noconfirm: - operation.append('--noconfirm') + operation = ['-Sy', '--needed'] elif operation == 'drop-overlay': exec('rm', '-f', '/.blend-overlays/future-usr/.okay') exec('rm', '-f', '/.blend-overlays/future-varlibpacman/.okay') @@ -361,8 +359,6 @@ 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('-y', '--noconfirm', - action='store_true', help=argparse.SUPPRESS) parser.add_argument('--headless', action='store_true', help=argparse.SUPPRESS) parser.add_argument('-v', '--version', action='version', From a91757d2677ab96471efbff17b43bf1e5f6fb218 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Tue, 9 May 2023 11:58:22 +0530 Subject: [PATCH 029/135] Update pacman argument list --- akshara | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara b/akshara index bf2e9cc..76cf5f1 100755 --- a/akshara +++ b/akshara @@ -259,7 +259,7 @@ def handle_system_packages(operation): f'lowerdir=/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/.blendrw/var/lib/pacman') if operation == 'set-custom-packages': - operation = ['-Sy', '--needed'] + operation = ['-Sy', '--needed', '--noconfirm'] elif operation == 'drop-overlay': exec('rm', '-f', '/.blend-overlays/future-usr/.okay') exec('rm', '-f', '/.blend-overlays/future-varlibpacman/.okay') From 5e4d2103a45a63b94da275b5ac3cddb522f31015 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Tue, 9 May 2023 12:06:00 +0530 Subject: [PATCH 030/135] Use fasteners instead of pylockfile --- akshara | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/akshara b/akshara index 76cf5f1..49f227f 100755 --- a/akshara +++ b/akshara @@ -24,10 +24,9 @@ import yaml import shutil import argparse import platform +import fasteners import subprocess -from lockfile import LockFile - __version = '1.0.0' with open('/etc/blend_release') as blend_release_file: @@ -383,13 +382,9 @@ try: parser.parse_args(['--version']) elif command == handle_system_packages: exec('touch', '/var/lib/.akshara-system-lock') - system_lock = LockFile('/var/lib/.akshara-system-lock') - if not system_lock.is_locked(): - system_lock.acquire() - else: - error('system operation already in progress') - exit(1) - command(args.command) + system_lock = fasteners.InterProcessLock('/var/lib/.akshara-system-lock') + with system_lock: + command(args.command) else: command() except KeyboardInterrupt: From 85e8fe838603b1a878dbfa970ec0d1beb2474e1a Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Tue, 9 May 2023 12:14:28 +0530 Subject: [PATCH 031/135] Update perms for future overlays --- akshara | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/akshara b/akshara index 49f227f..9de7555 100755 --- a/akshara +++ b/akshara @@ -225,24 +225,24 @@ def handle_system_packages(operation): exec('rm', '-rf', f'/mnt/{old_overlay}') usr_overlay = subprocess.run( ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - exec('chmod', '=rw', usr_overlay) + exec('chmod', '-R', '755', usr_overlay) if os.path.isdir('/.blend-overlays/future-usr'): exec('rm', '-f', '/.blend-overlays/future-usr/.okay') exec('rm', '-rf', usr_overlay) exec('mv', '/.blend-overlays/future-usr', usr_overlay) usr_overlay_workdir = subprocess.run( ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - exec('chmod', '=rw', usr_overlay_workdir) + exec('chmod', '-R', '755', usr_overlay_workdir) varlibpacman_overlay = subprocess.run( ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - exec('chmod', '=rw', varlibpacman_overlay) + exec('chmod', '-R', '755', varlibpacman_overlay) if os.path.isdir('/.blend-overlays/future-varlibpacman'): exec('rm', '-f', '/.blend-overlays/future-varlibpacman/.okay') exec('rm', '-rf', varlibpacman_overlay) exec('mv', '/.blend-overlays/future-varlibpacman', varlibpacman_overlay) varlibpacman_overlay_workdir = subprocess.run( ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - exec('chmod', '=rw', varlibpacman_overlay_workdir) + exec('chmod', '-R', '755', varlibpacman_overlay_workdir) if '' in (usr_overlay, usr_overlay_workdir, varlibpacman_overlay, varlibpacman_overlay_workdir): for old_overlay in os.listdir('/mnt'): if old_overlay.startswith('.blend-tmp-overlay-'): From 7102e813d42539c385eb91ec5f3316957d2c3f79 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Tue, 9 May 2023 12:20:30 +0530 Subject: [PATCH 032/135] disable index and metacopy for overlayfs mounts --- akshara.hook | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/akshara.hook b/akshara.hook index cdba8e3..d19a3d5 100755 --- a/akshara.hook +++ b/akshara.hook @@ -84,6 +84,6 @@ run_latehook() { mkdir -p /new_root/.blend-overlays/$i.workdir done - mount -t overlay overlay -o ro,lowerdir=/new_root/usr,upperdir=/new_root/.blend-overlays/usr,workdir=/new_root/.blend-overlays/usr.workdir /new_root/usr - mount -t overlay overlay -o ro,lowerdir=/new_root/var/lib/pacman,upperdir=/new_root/.blend-overlays/varlibpacman,workdir=/new_root/.blend-overlays/varlibpacman.workdir /new_root/var/lib/pacman + mount -t overlay overlay -o index=off -o metacopy=off -o ro,lowerdir=/new_root/usr,upperdir=/new_root/.blend-overlays/usr,workdir=/new_root/.blend-overlays/usr.workdir /new_root/usr + mount -t overlay overlay -o index=off -o metacopy=off -o ro,lowerdir=/new_root/var/lib/pacman,upperdir=/new_root/.blend-overlays/varlibpacman,workdir=/new_root/.blend-overlays/varlibpacman.workdir /new_root/var/lib/pacman } From e380b80559cb319372219096b54bb370678cbb33 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Fri, 12 May 2023 12:42:46 +0530 Subject: [PATCH 033/135] Add support for package lists --- akshara | 25 ++++++++++++++++++++++++- akshara.hook | 5 +++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/akshara b/akshara index 9de7555..2bd9103 100755 --- a/akshara +++ b/akshara @@ -183,6 +183,16 @@ def update_system(): 'bash', '-c', 'echo "Current=breeze" >> /etc/sddm.conf.d/default.conf') exec_chroot('rm', '-f', '/etc/gdm/custom.conf') + # Install custom system packages + exec('touch', '/.custom_pkg_list') + exec('cp', '/.custom_pkg_list', '/mnt/iso-update/squashfs-root') + with open('/.custom_pkg_list') as custompkglist_file: + custompkglist = [] + while line := custompkglist_file.readline(): + if line.strip() != '': + custompkglist.append(line.strip()) + exec_chroot('pacman', '-Sy', '--needed', '--noconfirm', *custompkglist) + # Note to self: since the hook only copies new files in /etc, configuring # Note to self: locales and users isn't required @@ -199,13 +209,18 @@ def handle_system_packages(operation): error('no packages specified') exit(1) + for pkg in args.pkg: + if pkg.startswith('linux'): + error('you may not install linux* packages') + exit(1) + if operation == 'set-custom-packages': info('this operation will replace the current overlay on the next boot') info('(any custom system packages/drivers installed earlier will be removed)') print() info('this command should __only__ be used for the installation of drivers') info('blendOS is __not__ responsible for any system breakage') - elif operation == 'drop-packages': + elif operation == 'drop-overlay': info('any installed packages will be removed') else: error('unsupported operation') @@ -262,6 +277,8 @@ def handle_system_packages(operation): elif operation == 'drop-overlay': exec('rm', '-f', '/.blend-overlays/future-usr/.okay') exec('rm', '-f', '/.blend-overlays/future-varlibpacman/.okay') + exec('rm', '-f', '/.custom_pkg_list') + exec('touch', '/.custom_pkg_list') exit() if exec('systemd-nspawn', '-D', '/.blendrw', '--', 'pacman', *operation, '--', *args.pkg, stdout=sys.stdout, stderr=sys.stderr) != 0: @@ -285,6 +302,9 @@ def handle_system_packages(operation): exec('mv', usr_overlay, '/.blend-overlays/future-usr') exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') exec('rm', '-rf', usr_overlay_workdir, varlibpacman_overlay_workdir) + exec('bash', '-c', "printf > /.custom_pkg_list") + for pkg in args.pkg: + exec('bash', '-c', f"echo '{pkg}' >> /.custom_pkg_list") exec('touch', '/.blend-overlays/future-usr/.okay') exec('touch', '/.blend-overlays/future-varlibpacman/.okay') info('reboot to apply changes') @@ -306,6 +326,9 @@ def handle_system_packages(operation): exec('mv', usr_overlay, '/.blend-overlays/future-usr') exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') exec('rm', '-rf', usr_overlay_workdir, varlibpacman_overlay_workdir) + exec('bash', '-c', "printf > /.custom_pkg_list") + for pkg in args.pkg: + exec('bash', '-c', f"echo '{pkg}' >> /.custom_pkg_list") exec('touch', '/.blend-overlays/future-usr/.okay') exec('touch', '/.blend-overlays/future-varlibpacman/.okay') info('reboot to apply changes') diff --git a/akshara.hook b/akshara.hook index d19a3d5..67a83ee 100755 --- a/akshara.hook +++ b/akshara.hook @@ -3,6 +3,8 @@ run_latehook() { echo + touch /new_root/.custom_pkg_list + # Remove /new_root/mnt/iso-update/.successful-update if exists rm -f /new_root/mnt/iso-update/.successful-update @@ -12,6 +14,9 @@ run_latehook() { mv /new_root/usr /new_root/.old.usr mv /new_root/mnt/iso-update/squashfs-root/usr /new_root/usr + # Copy package list + mv /new_root/mnt/iso-update/squashfs-root/.custom_pkg_list /new_root + # Update /usr/lib/modules for current kernel version. for kversion in /new_root/.old.usr/lib/modules/*; do if [[ ! -d /new_root/usr/lib/modules/"$(basename "$kversion")" ]]; then From 2da77160981f150ec920da87c6d9f1444ed2dd53 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Fri, 12 May 2023 12:59:45 +0530 Subject: [PATCH 034/135] Initial commit --- .gitignore | 5 +++++ PKGBUILD | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 .gitignore create mode 100644 PKGBUILD diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6a9b95 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +* + +!.gitignore +!PKGBUILD +!.SRCINFO diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..a306667 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,34 @@ +# Maintainer: Rudra Saraswat + +pkgname='akshara-git' +pkgver=r33.e380b80 +pkgrel=1 +pkgdesc="A package manager for blendOS" +arch=('x86_64' 'i686') +url="https://github.com/blend-os/blend" +license=('GPL3') +makedepends=("electron${_electronversion}" 'git' 'npm' 'base-devel') +source=('git+https://github.com/blend-os/akshara.git') +sha256sums=('SKIP') + +depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'squashfs-tools' 'p7zip' 'zsync') +provides=("${pkgname%-git}") +conflicts=("${pkgname%-git}") + +pkgver() { + cd "${srcdir}/${pkgbase%-git}" + printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" +} + +package() { + cd "${srcdir}/${pkgbase%-git}" + install -Dm755 \ + "${pkgname%-git}" \ + -t "${pkgdir}"/usr/bin/ + install -Dm644 "${pkgname%-git}.service" -t \ + "${pkgdir}"/usr/lib/systemd/user/ + install -Dm644 "${pkgname%-git}.hook" \ + "${pkgdir}/usr/lib/initcpio/hooks/${pkgname%-git}" + install -Dm644 "${pkgname%-git}.install" \ + "${pkgdir}/usr/lib/initcpio/install/${pkgname%-git}" +} From 0bda14d5e34c6ac7ea3591d85c43feff2fbb300c Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Fri, 12 May 2023 13:02:16 +0530 Subject: [PATCH 035/135] Update pkgdesc --- PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKGBUILD b/PKGBUILD index a306667..85e2d1f 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -3,7 +3,7 @@ pkgname='akshara-git' pkgver=r33.e380b80 pkgrel=1 -pkgdesc="A package manager for blendOS" +pkgdesc="An update system for operating systems" arch=('x86_64' 'i686') url="https://github.com/blend-os/blend" license=('GPL3') From e075e4fbd5337c81a48684c108f70e4e27dff6fb Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Fri, 12 May 2023 13:12:04 +0530 Subject: [PATCH 036/135] Update copyright header --- akshara | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/akshara b/akshara index 2bd9103..2c6b195 100755 --- a/akshara +++ b/akshara @@ -1,20 +1,20 @@ #!/usr/bin/env python3 # Copyright (C) 2023 Rudra Saraswat # -# This file is part of blend. +# This file is part of akshara. # -# blend is free software: you can redistribute it and/or modify +# akshara is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # -# blend is distributed in the hope that it will be useful, +# akshara is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with blend. If not, see . +# along with akshara. If not, see . import os From 754a7ddfff3b5319b8ce759c55c5faa2c2eee754 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 15 May 2023 12:43:15 +0530 Subject: [PATCH 037/135] feat: fix minor bugs --- akshara | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/akshara b/akshara index 2c6b195..6b7557e 100755 --- a/akshara +++ b/akshara @@ -205,7 +205,7 @@ def update_system(): def handle_system_packages(operation): - if len(args.pkg) == 0: + if len(args.pkg) == 0 and operation != 'drop-overlay': error('no packages specified') exit(1) @@ -302,7 +302,7 @@ def handle_system_packages(operation): exec('mv', usr_overlay, '/.blend-overlays/future-usr') exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') exec('rm', '-rf', usr_overlay_workdir, varlibpacman_overlay_workdir) - exec('bash', '-c', "printf > /.custom_pkg_list") + exec('bash', '-c', "printf '' > /.custom_pkg_list") for pkg in args.pkg: exec('bash', '-c', f"echo '{pkg}' >> /.custom_pkg_list") exec('touch', '/.blend-overlays/future-usr/.okay') From 49cfd6021eb3d0efc16bc135d69cdc55f4343cfa Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 15 May 2023 21:10:22 +0530 Subject: [PATCH 038/135] Install as system service, not user --- PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKGBUILD b/PKGBUILD index 85e2d1f..272b1bb 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -26,7 +26,7 @@ package() { "${pkgname%-git}" \ -t "${pkgdir}"/usr/bin/ install -Dm644 "${pkgname%-git}.service" -t \ - "${pkgdir}"/usr/lib/systemd/user/ + "${pkgdir}"/usr/lib/systemd/system/ install -Dm644 "${pkgname%-git}.hook" \ "${pkgdir}/usr/lib/initcpio/hooks/${pkgname%-git}" install -Dm644 "${pkgname%-git}.install" \ From eeb5148d3582d8a871c51a7ee0650eaff0ee8ae9 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Tue, 16 May 2023 18:07:56 +0530 Subject: [PATCH 039/135] Add python-fasteners as dep --- PKGBUILD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index 272b1bb..f013888 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -2,7 +2,7 @@ pkgname='akshara-git' pkgver=r33.e380b80 -pkgrel=1 +pkgrel=2 pkgdesc="An update system for operating systems" arch=('x86_64' 'i686') url="https://github.com/blend-os/blend" @@ -11,7 +11,7 @@ makedepends=("electron${_electronversion}" 'git' 'npm' 'base-devel') source=('git+https://github.com/blend-os/akshara.git') sha256sums=('SKIP') -depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'squashfs-tools' 'p7zip' 'zsync') +depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'python-fasteners' 'squashfs-tools' 'p7zip' 'zsync') provides=("${pkgname%-git}") conflicts=("${pkgname%-git}") From 5dc1713698ffe9e3a8cbdda75a98493a05c50018 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Tue, 16 May 2023 23:44:18 +0530 Subject: [PATCH 040/135] chore: remove .okay after update --- akshara | 14 ++++++++++++-- akshara.hook | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/akshara b/akshara index 6b7557e..a58263c 100755 --- a/akshara +++ b/akshara @@ -154,6 +154,7 @@ def update_system(): ######################## # Enable services + exec_chroot('systemctl', 'enable', 'akshara') exec_chroot('systemctl', 'enable', 'bluetooth') exec_chroot('systemctl', 'enable', 'cups') exec_chroot('systemctl', '--global', 'enable', 'blend-files') @@ -214,6 +215,10 @@ def handle_system_packages(operation): error('you may not install linux* packages') exit(1) + if os.path.isfile('/mnt/iso-update/.ready-for-update'): + error('an update was downloaded in the background, you') + error('must reboot before installing any system packages') + if operation == 'set-custom-packages': info('this operation will replace the current overlay on the next boot') info('(any custom system packages/drivers installed earlier will be removed)') @@ -342,8 +347,11 @@ def daemon(): shutil.rmtree('/' + dir) while True: if not os.path.isfile('/mnt/iso-update/.ready-for-update'): - update_system() - time.sleep(3600) + exec('touch', '/var/lib/.akshara-system-lock') + system_lock = fasteners.InterProcessLock('/var/lib/.akshara-system-lock') + with system_lock: + update_system() + time.sleep(300) description = f''' @@ -406,6 +414,8 @@ try: elif command == handle_system_packages: exec('touch', '/var/lib/.akshara-system-lock') system_lock = fasteners.InterProcessLock('/var/lib/.akshara-system-lock') + info('attempting to acquire system lock') + print() with system_lock: command(args.command) else: diff --git a/akshara.hook b/akshara.hook index 67a83ee..6fe9844 100755 --- a/akshara.hook +++ b/akshara.hook @@ -76,6 +76,7 @@ run_latehook() { for i in usr varlibpacman; do rm -rf /new_root/.blend-overlays/$i mv /new_root/.blend-overlays/future-$i /new_root/.blend-overlays/$i + rm -f /new_root/.blend-overlays/$i/.okay done else rm -rf /new_root/.blend-overlays /new_root/.blendrw From 8b5d0efcf473f3ee637570f5dbb72eda5d82c3f4 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Tue, 16 May 2023 23:44:46 +0530 Subject: [PATCH 041/135] chore: remove unneeded lines from hook --- akshara.hook | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/akshara.hook b/akshara.hook index 6fe9844..f81fc70 100755 --- a/akshara.hook +++ b/akshara.hook @@ -64,6 +64,10 @@ run_latehook() { mv /new_root/mnt/iso-update/iso/boot/intel-ucode.img /new_root/boot/intel-ucode.img fi + for i in usr varlibpacman; do + rm -f /new_root/.blend-overlays/$i/.okay + done + # Successful update. rm -f /new_root/mnt/iso-update/.etc-stage touch /new_root/mnt/iso-update/.successful-update From cd422cfebfed97a88bb9ec28e7bddcf39e62aceb Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Tue, 16 May 2023 23:46:11 +0530 Subject: [PATCH 042/135] chore: remove .okay from future-* --- akshara.hook | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/akshara.hook b/akshara.hook index f81fc70..c0b2599 100755 --- a/akshara.hook +++ b/akshara.hook @@ -65,7 +65,7 @@ run_latehook() { fi for i in usr varlibpacman; do - rm -f /new_root/.blend-overlays/$i/.okay + rm -f /new_root/.blend-overlays/future-$i/.okay done # Successful update. @@ -80,7 +80,6 @@ run_latehook() { for i in usr varlibpacman; do rm -rf /new_root/.blend-overlays/$i mv /new_root/.blend-overlays/future-$i /new_root/.blend-overlays/$i - rm -f /new_root/.blend-overlays/$i/.okay done else rm -rf /new_root/.blend-overlays /new_root/.blendrw From 2618d6dc854f49d984e25a688755daefacecb96f Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Wed, 24 May 2023 15:47:51 +0530 Subject: [PATCH 043/135] feat: make packaging compatible with build tools --- PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKGBUILD b/PKGBUILD index f013888..7f80cbc 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -8,7 +8,7 @@ arch=('x86_64' 'i686') url="https://github.com/blend-os/blend" license=('GPL3') makedepends=("electron${_electronversion}" 'git' 'npm' 'base-devel') -source=('git+https://github.com/blend-os/akshara.git') +source=('git+file://[BASE_ASSEMBLE_PATH]/projects/akshara') sha256sums=('SKIP') depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'python-fasteners' 'squashfs-tools' 'p7zip' 'zsync') From 1f35f9b2e41be54a1e69593cd6201e80674feb75 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Wed, 31 May 2023 15:05:20 +0530 Subject: [PATCH 044/135] feat: install packages to overlay during updates --- akshara | 2 +- akshara.hook | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/akshara b/akshara index a58263c..916a879 100755 --- a/akshara +++ b/akshara @@ -307,7 +307,7 @@ def handle_system_packages(operation): exec('mv', usr_overlay, '/.blend-overlays/future-usr') exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') exec('rm', '-rf', usr_overlay_workdir, varlibpacman_overlay_workdir) - exec('bash', '-c', "printf '' > /.custom_pkg_list") + exec('bash', '-c', "echo -n > /.custom_pkg_list") for pkg in args.pkg: exec('bash', '-c', f"echo '{pkg}' >> /.custom_pkg_list") exec('touch', '/.blend-overlays/future-usr/.okay') diff --git a/akshara.hook b/akshara.hook index c0b2599..2f0adaa 100755 --- a/akshara.hook +++ b/akshara.hook @@ -82,10 +82,10 @@ run_latehook() { mv /new_root/.blend-overlays/future-$i /new_root/.blend-overlays/$i done else - rm -rf /new_root/.blend-overlays /new_root/.blendrw + rm -rf /new_root/.blend-overlays/usr.workdir /new_root/.blend-overlays/varlibpacman.workdir fi else - rm -rf /new_root/.blend-overlays /new_root/.blendrw + rm -rf /new_root/.blend-overlays fi for i in usr varlibpacman; do From f452b75e1a2689fbe009fe4f24104f25bd84f97d Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Wed, 31 May 2023 16:18:02 +0530 Subject: [PATCH 045/135] chore: follow redirects when fetching server timestamp --- akshara | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/akshara b/akshara index 916a879..624f65f 100755 --- a/akshara +++ b/akshara @@ -98,7 +98,7 @@ def get_server_timestamp(): with open('/etc/blend_release') as blend_release_file: track = yaml.load(blend_release_file, Loader=yaml.FullLoader)['track'] server_version_output = subprocess.run( - ['curl', '--silent', '--show-error', f'{server_url}/track/{track}/current'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + ['curl', '--silent', '-L', '--show-error', f'{server_url}/track/{track}/current'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) if server_version_output.stderr.decode().strip() != '': return 0 elif server_version_output.stdout.decode().strip() != '' and server_version_output.stdout.decode().strip().isnumeric(): @@ -184,6 +184,31 @@ def update_system(): 'bash', '-c', 'echo "Current=breeze" >> /etc/sddm.conf.d/default.conf') exec_chroot('rm', '-f', '/etc/gdm/custom.conf') + usr_overlay = subprocess.run( + ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + exec('chmod', '-R', '755', usr_overlay) + if os.path.isdir('/.blend-overlays/future-usr'): + exec('rm', '-f', '/.blend-overlays/future-usr/.okay') + exec('rm', '-rf', usr_overlay) + usr_overlay_workdir = subprocess.run( + ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + exec('chmod', '-R', '755', usr_overlay_workdir) + varlibpacman_overlay = subprocess.run( + ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + exec('chmod', '-R', '755', varlibpacman_overlay) + if os.path.isdir('/.blend-overlays/future-varlibpacman'): + exec('rm', '-f', '/.blend-overlays/future-varlibpacman/.okay') + exec('rm', '-rf', varlibpacman_overlay) + varlibpacman_overlay_workdir = subprocess.run( + ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + exec('chmod', '-R', '755', varlibpacman_overlay_workdir) + + exec('mount', '-t', 'overlay', 'overlay', '-o', + f'lowerdir=/var/lib/pacman,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/mnt/iso-update/squashfs-root/usr') + + exec('mount', '-t', 'overlay', 'overlay', '-o', + f'lowerdir=/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/mnt/iso-update/squashfs-root/var/lib/pacman') + # Install custom system packages exec('touch', '/.custom_pkg_list') exec('cp', '/.custom_pkg_list', '/mnt/iso-update/squashfs-root') @@ -197,13 +222,17 @@ def update_system(): # Note to self: since the hook only copies new files in /etc, configuring # Note to self: locales and users isn't required + # Unmount and rename overlays + exec('umount', '-l', '/mnt/iso-update/squashfs-root/usr') + exec('umount', '-l', '/mnt/iso-update/squashfs-root/var/lib/pacman') + exec('mv', usr_overlay, '/mnt/iso-update/future-usr') + exec('mv', varlibpacman_overlay, '/mnt/iso-update/future-varlibpacman') + exec('touch', '/mnt/iso-update/future-usr/.okay') + exec('touch', '/mnt/iso-update/future-varlibpacman/.okay') + # Mark as ready for update on boot exec('touch', '/mnt/iso-update/.ready-for-update') - # Unmount directories if not already unmounted - exec('umount', '-l', '/mnt/iso-update/squashfs-root/dev') - exec('umount', '-l', '/mnt/iso-update/squashfs-root/proc') - def handle_system_packages(operation): if len(args.pkg) == 0 and operation != 'drop-overlay': From 339518860e58f721cb090cc83435e254e1892d12 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Wed, 31 May 2023 17:13:03 +0530 Subject: [PATCH 046/135] chore: correct overlay lowerdir --- akshara | 4 ++-- akshara.hook | 16 ++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/akshara b/akshara index 624f65f..e352bf2 100755 --- a/akshara +++ b/akshara @@ -204,10 +204,10 @@ def update_system(): exec('chmod', '-R', '755', varlibpacman_overlay_workdir) exec('mount', '-t', 'overlay', 'overlay', '-o', - f'lowerdir=/var/lib/pacman,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/mnt/iso-update/squashfs-root/usr') + f'lowerdir=/mnt/iso-update/squashfs-root/,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/mnt/iso-update/squashfs-root/usr') exec('mount', '-t', 'overlay', 'overlay', '-o', - f'lowerdir=/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/mnt/iso-update/squashfs-root/var/lib/pacman') + f'lowerdir=/mnt/iso-update/squashfs-root/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/mnt/iso-update/squashfs-root/var/lib/pacman') # Install custom system packages exec('touch', '/.custom_pkg_list') diff --git a/akshara.hook b/akshara.hook index 2f0adaa..203121b 100755 --- a/akshara.hook +++ b/akshara.hook @@ -75,17 +75,13 @@ run_latehook() { # Handle overlays. - if [[ ! -f /new_root/mnt/iso-update/.successful-update ]]; then - if [[ -f '/new_root/.blend-overlays/future-usr/.okay' ]] && [[ -f '/new_root/.blend-overlays/future-varlibpacman/.okay' ]]; then - for i in usr varlibpacman; do - rm -rf /new_root/.blend-overlays/$i - mv /new_root/.blend-overlays/future-$i /new_root/.blend-overlays/$i - done - else - rm -rf /new_root/.blend-overlays/usr.workdir /new_root/.blend-overlays/varlibpacman.workdir - fi + if [[ -f '/new_root/.blend-overlays/future-usr/.okay' ]] && [[ -f '/new_root/.blend-overlays/future-varlibpacman/.okay' ]]; then + for i in usr varlibpacman; do + rm -rf /new_root/.blend-overlays/$i + mv /new_root/.blend-overlays/future-$i /new_root/.blend-overlays/$i + done else - rm -rf /new_root/.blend-overlays + rm -rf /new_root/.blend-overlays/usr.workdir /new_root/.blend-overlays/varlibpacman.workdir fi for i in usr varlibpacman; do From c91e3cec074d135c9416ea72d2a0dcb75a7cfe6f Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Wed, 31 May 2023 21:11:29 +0530 Subject: [PATCH 047/135] chore: correct a typo --- akshara | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/akshara b/akshara index e352bf2..cdb949d 100755 --- a/akshara +++ b/akshara @@ -204,7 +204,7 @@ def update_system(): exec('chmod', '-R', '755', varlibpacman_overlay_workdir) exec('mount', '-t', 'overlay', 'overlay', '-o', - f'lowerdir=/mnt/iso-update/squashfs-root/,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/mnt/iso-update/squashfs-root/usr') + f'lowerdir=/mnt/iso-update/squashfs-root/usr,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/mnt/iso-update/squashfs-root/usr') exec('mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/mnt/iso-update/squashfs-root/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/mnt/iso-update/squashfs-root/var/lib/pacman') @@ -225,10 +225,10 @@ def update_system(): # Unmount and rename overlays exec('umount', '-l', '/mnt/iso-update/squashfs-root/usr') exec('umount', '-l', '/mnt/iso-update/squashfs-root/var/lib/pacman') - exec('mv', usr_overlay, '/mnt/iso-update/future-usr') - exec('mv', varlibpacman_overlay, '/mnt/iso-update/future-varlibpacman') - exec('touch', '/mnt/iso-update/future-usr/.okay') - exec('touch', '/mnt/iso-update/future-varlibpacman/.okay') + exec('mv', usr_overlay, '/.blend-overlays/future-usr') + exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') + exec('touch', '/.blend-overlays/future-usr/.okay') + exec('touch', '/.blend-overlays/future-varlibpacman/.okay') # Mark as ready for update on boot exec('touch', '/mnt/iso-update/.ready-for-update') From 0b438336a708b8d4cd188f54a81be5068ba6f81f Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Sun, 4 Jun 2023 23:14:49 +0530 Subject: [PATCH 048/135] chore (fix): do not remove tmp overlays --- akshara | 8 ++++---- akshara.hook | 4 ---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/akshara b/akshara index cdb949d..e2b0100 100755 --- a/akshara +++ b/akshara @@ -189,7 +189,7 @@ def update_system(): exec('chmod', '-R', '755', usr_overlay) if os.path.isdir('/.blend-overlays/future-usr'): exec('rm', '-f', '/.blend-overlays/future-usr/.okay') - exec('rm', '-rf', usr_overlay) + exec('rm', '-rf', '/.blend-overlays/future-usr') usr_overlay_workdir = subprocess.run( ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() exec('chmod', '-R', '755', usr_overlay_workdir) @@ -198,7 +198,7 @@ def update_system(): exec('chmod', '-R', '755', varlibpacman_overlay) if os.path.isdir('/.blend-overlays/future-varlibpacman'): exec('rm', '-f', '/.blend-overlays/future-varlibpacman/.okay') - exec('rm', '-rf', varlibpacman_overlay) + exec('rm', '-rf', '/.blend-overlays/future-varlibpacman') varlibpacman_overlay_workdir = subprocess.run( ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() exec('chmod', '-R', '755', varlibpacman_overlay_workdir) @@ -395,8 +395,8 @@ blendOS is not responsible for any system breakage. {colors.bold}{colors.fg.cyan}available commands{colors.reset}: {colors.bold}help{colors.reset} Show this help message and exit. - {colors.bold}install{colors.reset} Install system drivers/packages. - {colors.bold}remove{colors.reset} Remove system drivers/packages. + {colors.bold}set-custom-packages{colors.reset} Set the custom system packages to be included in the overlay. + {colors.bold}drop-overlay{colors.reset} Drop an overlay created previously using set-custom-packages. {colors.bold}version{colors.reset} Show version information and exit. {colors.bold}{colors.fg.cyan}options for commands{colors.reset}: diff --git a/akshara.hook b/akshara.hook index 203121b..253ece2 100755 --- a/akshara.hook +++ b/akshara.hook @@ -64,10 +64,6 @@ run_latehook() { mv /new_root/mnt/iso-update/iso/boot/intel-ucode.img /new_root/boot/intel-ucode.img fi - for i in usr varlibpacman; do - rm -f /new_root/.blend-overlays/future-$i/.okay - done - # Successful update. rm -f /new_root/mnt/iso-update/.etc-stage touch /new_root/mnt/iso-update/.successful-update From 449a7da8ae9b55c7eb6fbbc0ad8d8034a579fb64 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Thu, 8 Jun 2023 04:30:57 +0530 Subject: [PATCH 049/135] chore: correct lowerdir, use echo to avoid error --- akshara | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/akshara b/akshara index e2b0100..de94b23 100755 --- a/akshara +++ b/akshara @@ -302,9 +302,9 @@ def handle_system_packages(operation): exec('mount', subprocess.run(['findmnt', '-n', '-o', 'SOURCE', '/'], stdout=subprocess.PIPE).stdout.decode().strip(), '/.blendrw') exec('mount', '-t', 'overlay', 'overlay', '-o', - f'lowerdir=/usr,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/.blendrw/usr') + f'lowerdir=/.blendrw/usr,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/.blendrw/usr') exec('mount', '-t', 'overlay', 'overlay', '-o', - f'lowerdir=/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/.blendrw/var/lib/pacman') + f'lowerdir=/.blendrw/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/.blendrw/var/lib/pacman') if operation == 'set-custom-packages': operation = ['-Sy', '--needed', '--noconfirm'] @@ -360,7 +360,7 @@ def handle_system_packages(operation): exec('mv', usr_overlay, '/.blend-overlays/future-usr') exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') exec('rm', '-rf', usr_overlay_workdir, varlibpacman_overlay_workdir) - exec('bash', '-c', "printf > /.custom_pkg_list") + exec('bash', '-c', "echo -n > /.custom_pkg_list") for pkg in args.pkg: exec('bash', '-c', f"echo '{pkg}' >> /.custom_pkg_list") exec('touch', '/.blend-overlays/future-usr/.okay') From 9bf1cf1aa780fa15305e48f8e4f721dea8652505 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Thu, 8 Jun 2023 05:53:23 +0530 Subject: [PATCH 050/135] chore: fix drop-overlay functionality --- akshara | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/akshara b/akshara index de94b23..19f9334 100755 --- a/akshara +++ b/akshara @@ -309,10 +309,17 @@ def handle_system_packages(operation): if operation == 'set-custom-packages': operation = ['-Sy', '--needed', '--noconfirm'] elif operation == 'drop-overlay': - exec('rm', '-f', '/.blend-overlays/future-usr/.okay') - exec('rm', '-f', '/.blend-overlays/future-varlibpacman/.okay') + exec('rm', '-rf', '/.blend-overlays/future-usr') + exec('rm', '-rf', '/.blend-overlays/future-varlibpacman') + + exec('mkdir', '-p', '/.blend-overlays/future-usr') + exec('mkdir', '-p', '/.blend-overlays/future-varlibpacman') + exec('rm', '-f', '/.custom_pkg_list') exec('touch', '/.custom_pkg_list') + + exec('touch', '/.blend-overlays/future-usr/.okay') + exec('touch', '/.blend-overlays/future-varlibpacman/.okay') exit() if exec('systemd-nspawn', '-D', '/.blendrw', '--', 'pacman', *operation, '--', *args.pkg, stdout=sys.stdout, stderr=sys.stderr) != 0: From a77f631c432cca0a1392b6b460ae0c181441cd56 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Sat, 10 Jun 2023 23:17:45 +1000 Subject: [PATCH 051/135] feat: replace /etc on update --- akshara.hook | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/akshara.hook b/akshara.hook index 253ece2..d51a3b0 100755 --- a/akshara.hook +++ b/akshara.hook @@ -23,7 +23,7 @@ run_latehook() { mv "$kversion" /new_root/usr/lib/modules/"$(basename "$kversion")" fi done - + # Same for /var/lib/pacman. mv /new_root/var/lib/pacman /new_root/.old.var.lib.pacman mv /new_root/mnt/iso-update/squashfs-root/var/lib/pacman /new_root/var/lib @@ -35,23 +35,19 @@ run_latehook() { # Detect if /etc stage is active. if [[ -f /new_root/mnt/iso-update/.etc-stage ]]; then + # Create new /etc. + cp -a /new_root/mnt/iso-update/squashfs-root/etc /new_root/.new.etc + + # Replace editable /etc files. + for i in sudoers crypttab fstab group gshadow hosts passwd resolv.conf shadow shells subgid subuid; do + cp "/new_root/etc/${i}" /new_root/.new.etc + done + # Rename existing /etc. mv /new_root/etc /new_root/.old.etc &>/dev/null || : - - # Create new /etc. - cp -a /new_root/.old.etc /new_root/etc - - # Only copy non-existent files. - cp -a -n /new_root/mnt/iso-update/squashfs-root/etc/* /new_root/etc - - # Update pacman config, and other system files that aren't - # supposed to be edited. - cp /new_root/mnt/iso-update/squashfs-root/etc/pacman.conf /new_root/etc - rm -rf /new_root/etc/pacman.d - cp -r /new_root/mnt/iso-update/squashfs-root/etc/pacman.d /new_root/etc - cp /new_root/mnt/iso-update/squashfs-root/etc/blend_release /new_root/etc - cp /new_root/mnt/iso-update/squashfs-root/etc/os-release /new_root/etc - cp /new_root/mnt/iso-update/squashfs-root/etc/lsb-release /new_root/etc + + # Rename new /etc. + mv /new_root/.new.etc /new_root/etc &>/dev/null || : # Replace kernel and microcode images. mv /new_root/mnt/iso-update/iso/boot/initramfs-linux-zen.img /new_root/boot/initramfs-linux-zen.img @@ -59,7 +55,7 @@ run_latehook() { if [[ -f /boot/amd-ucode.img ]]; then mv /new_root/mnt/iso-update/iso/boot/amd-ucode.img /new_root/boot/amd-ucode.img fi - + if [[ -f /boot/intel-ucode.img ]]; then mv /new_root/mnt/iso-update/iso/boot/intel-ucode.img /new_root/boot/intel-ucode.img fi @@ -68,7 +64,7 @@ run_latehook() { rm -f /new_root/mnt/iso-update/.etc-stage touch /new_root/mnt/iso-update/.successful-update fi - + # Handle overlays. if [[ -f '/new_root/.blend-overlays/future-usr/.okay' ]] && [[ -f '/new_root/.blend-overlays/future-varlibpacman/.okay' ]]; then @@ -84,7 +80,7 @@ run_latehook() { mkdir -p /new_root/.blend-overlays/$i mkdir -p /new_root/.blend-overlays/$i.workdir done - + mount -t overlay overlay -o index=off -o metacopy=off -o ro,lowerdir=/new_root/usr,upperdir=/new_root/.blend-overlays/usr,workdir=/new_root/.blend-overlays/usr.workdir /new_root/usr mount -t overlay overlay -o index=off -o metacopy=off -o ro,lowerdir=/new_root/var/lib/pacman,upperdir=/new_root/.blend-overlays/varlibpacman,workdir=/new_root/.blend-overlays/varlibpacman.workdir /new_root/var/lib/pacman } From b33942bd3bb61a84725f4fb0231d435d1029043c Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Sun, 11 Jun 2023 09:28:14 +1000 Subject: [PATCH 052/135] chore: do not overwrite /etc/default/grub --- akshara.hook | 1 + 1 file changed, 1 insertion(+) diff --git a/akshara.hook b/akshara.hook index d51a3b0..76f78b4 100755 --- a/akshara.hook +++ b/akshara.hook @@ -42,6 +42,7 @@ run_latehook() { for i in sudoers crypttab fstab group gshadow hosts passwd resolv.conf shadow shells subgid subuid; do cp "/new_root/etc/${i}" /new_root/.new.etc done + cp "/new_root/etc/default/grub" /new_root/.new.etc # Rename existing /etc. mv /new_root/etc /new_root/.old.etc &>/dev/null || : From a05b970d1d2d235c4c2d5489b1375babd950955c Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Sun, 11 Jun 2023 11:15:32 +1000 Subject: [PATCH 053/135] chore: do not copy initramfs during update --- akshara.hook | 3 --- 1 file changed, 3 deletions(-) diff --git a/akshara.hook b/akshara.hook index 76f78b4..837ce33 100755 --- a/akshara.hook +++ b/akshara.hook @@ -50,9 +50,6 @@ run_latehook() { # Rename new /etc. mv /new_root/.new.etc /new_root/etc &>/dev/null || : - # Replace kernel and microcode images. - mv /new_root/mnt/iso-update/iso/boot/initramfs-linux-zen.img /new_root/boot/initramfs-linux-zen.img - if [[ -f /boot/amd-ucode.img ]]; then mv /new_root/mnt/iso-update/iso/boot/amd-ucode.img /new_root/boot/amd-ucode.img fi From 19812e9ef3003e866c7c2c32797e808e99e28e04 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 12 Jun 2023 09:55:37 +1000 Subject: [PATCH 054/135] chore: make modifications for new system utility --- akshara | 18 +++++++++--------- akshara.hook | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/akshara b/akshara index 19f9334..32aa0b7 100755 --- a/akshara +++ b/akshara @@ -170,6 +170,13 @@ def update_system(): 'bash', '-c', 'echo \'HOOKS="base udev akshara plymouth autodetect modconf block keyboard keymap consolefont filesystems fsck"\' >> /etc/mkinitcpio.conf') exec_chroot( 'bash', '-c', 'echo \'COMPRESSION="zstd"\' >> /etc/mkinitcpio.conf') + + if 'NVIDIA' in subprocess.check_output(['lspci']).decode('utf-8'): + exec_chroot( + 'bash', '-c', 'echo -e \'\\nGRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_DEFAULT} vt.global_cursor_default=0 nvidia_drm.modeset=1 splash"\' >> /etc/default/grub') + exec_chroot('mkdir', '-p', '/etc/udev/rules.d') + exec_chroot('ln', '-s', '/dev/null', + '/etc/udev/rules.d/61-gdm.rules') # Refresh package lists, pacman-key --init exec_chroot('pacman', '-Rn', '--noconfirm', @@ -250,12 +257,6 @@ def handle_system_packages(operation): if operation == 'set-custom-packages': info('this operation will replace the current overlay on the next boot') - info('(any custom system packages/drivers installed earlier will be removed)') - print() - info('this command should __only__ be used for the installation of drivers') - info('blendOS is __not__ responsible for any system breakage') - elif operation == 'drop-overlay': - info('any installed packages will be removed') else: error('unsupported operation') print() @@ -368,7 +369,7 @@ def handle_system_packages(operation): exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') exec('rm', '-rf', usr_overlay_workdir, varlibpacman_overlay_workdir) exec('bash', '-c', "echo -n > /.custom_pkg_list") - for pkg in args.pkg: + for pkg in list(set(args.pkg)): exec('bash', '-c', f"echo '{pkg}' >> /.custom_pkg_list") exec('touch', '/.blend-overlays/future-usr/.okay') exec('touch', '/.blend-overlays/future-varlibpacman/.okay') @@ -387,7 +388,7 @@ def daemon(): system_lock = fasteners.InterProcessLock('/var/lib/.akshara-system-lock') with system_lock: update_system() - time.sleep(300) + time.sleep(60) description = f''' @@ -451,7 +452,6 @@ try: exec('touch', '/var/lib/.akshara-system-lock') system_lock = fasteners.InterProcessLock('/var/lib/.akshara-system-lock') info('attempting to acquire system lock') - print() with system_lock: command(args.command) else: diff --git a/akshara.hook b/akshara.hook index 837ce33..3fb29d4 100755 --- a/akshara.hook +++ b/akshara.hook @@ -39,7 +39,7 @@ run_latehook() { cp -a /new_root/mnt/iso-update/squashfs-root/etc /new_root/.new.etc # Replace editable /etc files. - for i in sudoers crypttab fstab group gshadow hosts passwd resolv.conf shadow shells subgid subuid; do + for i in sudoers crypttab fstab group gshadow hostname hosts passwd resolv.conf shadow shells subgid subuid; do cp "/new_root/etc/${i}" /new_root/.new.etc done cp "/new_root/etc/default/grub" /new_root/.new.etc From d1bd93a98051d38f3a3d5803532af705f82900a0 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Sat, 17 Jun 2023 01:58:00 +1000 Subject: [PATCH 055/135] feat: some major changes --- akshara | 25 +++++++------------------ akshara.hook | 8 ++++++-- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/akshara b/akshara index 32aa0b7..6046974 100755 --- a/akshara +++ b/akshara @@ -109,9 +109,9 @@ def get_server_timestamp(): def update_system(): os.chdir('/mnt') - exec('rm', '-rf', '/mnt/iso-update/iso') - exec('rm', '-rf', '/mnt/iso-update/squashfs-root') - exec('mkdir', '-p', '/mnt/iso-update') + for f in os.listdir('/mnt/iso-update'): + if f != 'update.iso': + exec('rm', '-f', f) # Check if update is available if os.path.isfile('/etc/blend_release'): @@ -124,22 +124,11 @@ def update_system(): # Update is available, let's download the latest ISO exec('mkdir', '-p', '/mnt/iso-update') if not os.path.isfile('/mnt/iso-update/update.iso'): - exec('wget', '-O', '/mnt/iso-update/update.iso', - f'{server_url}/track/{track}/download') - exec('rm', '-f', '/mnt/iso-update/update.iso.sha512sum') - exec('wget', '-O', '/mnt/iso-update/update.iso.sha512sum', - f'{server_url}/track/{track}/update-sha512sum') - if exec('bash', '-c', 'cd /mnt/iso-update; sha512sum --check --status /mnt/iso-update/update.iso.sha512sum') != 0: - exec('rm', '-f', '/mnt/iso-update/update.iso.sha512sum', - '/mnt/iso-update/update.iso.sha512sum') - exec('wget', '-O', '/mnt/iso-update/update.iso', - f'{server_url}/track/{track}/download') - exec('wget', '-O', '/mnt/iso-update/update.iso.sha512sum', - f'{server_url}/track/{track}/update-sha512sum') - if exec('sha512sum', '--check', '--status', 'update.iso.sha512sum', cwd='/mnt/iso-update') != 0: - exec('rm', '-f', '/mnt/iso-update/.download_lock') + if exec('zsync2', f'https://updates.blendos.co/{track}/{get_server_timestamp()}/update.iso.zsync', '-o', '/mnt/iso-update/update.iso') != 0: + return + else: + if exec('zsync2', f'https://updates.blendos.co/{track}/{get_server_timestamp()}/update.iso.zsync', '-i', '/mnt/iso-update/update.iso', '-o', '/mnt/iso-update/update.iso') != 0: return - exec('rm', '-f', '/mnt/iso-update/.download_lock') # Since the ISO has been downloaded, proceed to extracing it # as well the rootfs it contains (single-core unsquashfs) diff --git a/akshara.hook b/akshara.hook index 3fb29d4..bd6162b 100755 --- a/akshara.hook +++ b/akshara.hook @@ -40,9 +40,13 @@ run_latehook() { # Replace editable /etc files. for i in sudoers crypttab fstab group gshadow hostname hosts passwd resolv.conf shadow shells subgid subuid; do - cp "/new_root/etc/${i}" /new_root/.new.etc + mv "/new_root/etc/${i}" "/new_root/.new.etc/${i}" done - cp "/new_root/etc/default/grub" /new_root/.new.etc + mv "/new_root/etc/default/grub" "/new_root/.new.etc/default/grub" + [[ -d /new_root/etc/NetworkManager/system-connections ]] && ( + rm -rf /new_root/.new.etc/NetworkManager/system-connections; + mv /new_root/etc/NetworkManager/system-connections /new_root/.new.etc/NetworkManager/system-connections + ) # Rename existing /etc. mv /new_root/etc /new_root/.old.etc &>/dev/null || : From d4107f2ad912ae27b4ecce5d862330b57f29de2f Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Tue, 20 Jun 2023 04:14:13 +1000 Subject: [PATCH 056/135] chore: add zsync2 to deps --- PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKGBUILD b/PKGBUILD index 7f80cbc..b4abc3c 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -11,7 +11,7 @@ makedepends=("electron${_electronversion}" 'git' 'npm' 'base-devel') source=('git+file://[BASE_ASSEMBLE_PATH]/projects/akshara') sha256sums=('SKIP') -depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'python-fasteners' 'squashfs-tools' 'p7zip' 'zsync') +depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'python-fasteners' 'squashfs-tools' 'p7zip' 'zsync2') provides=("${pkgname%-git}") conflicts=("${pkgname%-git}") From e9e570df48b3e6dbb064f33fac4dc86d474c03ee Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Sat, 24 Jun 2023 21:28:12 +1000 Subject: [PATCH 057/135] chore: check if iso-update dir exists --- akshara | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/akshara b/akshara index 6046974..18eae0c 100755 --- a/akshara +++ b/akshara @@ -109,9 +109,10 @@ def get_server_timestamp(): def update_system(): os.chdir('/mnt') - for f in os.listdir('/mnt/iso-update'): - if f != 'update.iso': - exec('rm', '-f', f) + if os.path.isdir('/mnt/iso-update'): + for f in os.listdir('/mnt/iso-update'): + if f != 'update.iso': + exec('rm', '-f', f) # Check if update is available if os.path.isfile('/etc/blend_release'): From e3e48931ccc114e8c4000102e81ef5f21ffe4a35 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Fri, 30 Jun 2023 09:15:04 +1000 Subject: [PATCH 058/135] chore: fic drop-overlay --- akshara | 2 -- 1 file changed, 2 deletions(-) diff --git a/akshara b/akshara index 18eae0c..04296c4 100755 --- a/akshara +++ b/akshara @@ -247,8 +247,6 @@ def handle_system_packages(operation): if operation == 'set-custom-packages': info('this operation will replace the current overlay on the next boot') - else: - error('unsupported operation') print() time.sleep(2) From f0306bd49debd2e60b98aaa5183a01805c01143c Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Fri, 30 Jun 2023 09:17:36 +1000 Subject: [PATCH 059/135] chore: fix old file removal behavior --- akshara | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara b/akshara index 04296c4..77a9edf 100755 --- a/akshara +++ b/akshara @@ -112,7 +112,7 @@ def update_system(): if os.path.isdir('/mnt/iso-update'): for f in os.listdir('/mnt/iso-update'): if f != 'update.iso': - exec('rm', '-f', f) + exec('rm', '-f', f'/mnt/iso-update/{f}') # Check if update is available if os.path.isfile('/etc/blend_release'): From 359e9ade5005f9a9bb391600616dd9c2fdf6fdd9 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Tue, 4 Jul 2023 07:50:47 +1000 Subject: [PATCH 060/135] chore: fix typo --- akshara | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara b/akshara index 77a9edf..ec9f532 100755 --- a/akshara +++ b/akshara @@ -112,7 +112,7 @@ def update_system(): if os.path.isdir('/mnt/iso-update'): for f in os.listdir('/mnt/iso-update'): if f != 'update.iso': - exec('rm', '-f', f'/mnt/iso-update/{f}') + exec('rm', '-rf', f'/mnt/iso-update/{f}') # Check if update is available if os.path.isfile('/etc/blend_release'): From 7ff1e6d1967000822284725c78404a78c30825e5 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Fri, 21 Jul 2023 18:43:37 +1000 Subject: [PATCH 061/135] feat: add support for Apex --- akshara | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++- akshara.hook | 3 ++ 2 files changed, 128 insertions(+), 1 deletion(-) diff --git a/akshara b/akshara index ec9f532..295bad3 100755 --- a/akshara +++ b/akshara @@ -231,6 +231,129 @@ def update_system(): exec('touch', '/mnt/iso-update/.ready-for-update') +def apex_update(): + try: + apex_iso = sys.argv[2] + except IndexError: + error('you must pass a valid ISO as an argument') + exit(1) + + exec('mkdir', '-p', '/mnt/iso-update') + + if os.path.isfile(apex_iso): + exec('cp', apex_iso, f'/mnt/iso-update/update.iso') + else: + error('you must pass a valid ISO as an argument') + exit(1) + + if os.path.isdir('/mnt/iso-update'): + for f in os.listdir('/mnt/iso-update'): + if f != 'update.iso': + exec('rm', '-rf', f'/mnt/iso-update/{f}') + + # Since the ISO is present, proceed to extracing it + # as well the rootfs it contains (single-core unsquashfs) + exec('rm', '-rf', '/mnt/iso-update/iso', + '/mnt/iso-update/squashfs-root') + exec('7z', '-oiso', 'x', 'update.iso', cwd='/mnt/iso-update') + if exec('unsquashfs', '-p', '1', f'iso/blend/{platform.machine()}/airootfs.sfs', cwd='/mnt/iso-update') != 0: + return + + ######################## + # Configure new rootfs # + ######################## + + # Enable services + exec_chroot('systemctl', 'enable', 'akshara') + exec_chroot('systemctl', 'enable', 'bluetooth') + exec_chroot('systemctl', 'enable', 'cups') + exec_chroot('systemctl', '--global', 'enable', 'blend-files') + + # Add akshara hook + exec_chroot( + 'bash', '-c', 'echo \'MODULES=""\' > /etc/mkinitcpio.conf') + exec_chroot( + 'bash', '-c', 'echo \'BINARIES=""\' >> /etc/mkinitcpio.conf') + exec_chroot( + 'bash', '-c', 'echo \'FILES=""\' >> /etc/mkinitcpio.conf') + exec_chroot( + 'bash', '-c', 'echo \'HOOKS="base udev akshara plymouth autodetect modconf block keyboard keymap consolefont filesystems fsck"\' >> /etc/mkinitcpio.conf') + exec_chroot( + 'bash', '-c', 'echo \'COMPRESSION="zstd"\' >> /etc/mkinitcpio.conf') + + if 'NVIDIA' in subprocess.check_output(['lspci']).decode('utf-8'): + exec_chroot( + 'bash', '-c', 'echo -e \'\\nGRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_DEFAULT} vt.global_cursor_default=0 nvidia_drm.modeset=1 splash"\' >> /etc/default/grub') + exec_chroot('mkdir', '-p', '/etc/udev/rules.d') + exec_chroot('ln', '-s', '/dev/null', + '/etc/udev/rules.d/61-gdm.rules') + + # Refresh package lists, pacman-key --init + exec_chroot('pacman', '-Rn', '--noconfirm', + 'jade-gui', 'blend-inst-git') + exec_chroot('pacman-key', '--init') + exec_chroot('pacman-key', '--populate', 'archlinux', 'blend') + + # Disable auto-login for blend user + exec_chroot( + 'bash', '-c', 'echo "[Theme]" > /etc/sddm.conf.d/default.conf') + exec_chroot( + 'bash', '-c', 'echo "Current=breeze" >> /etc/sddm.conf.d/default.conf') + exec_chroot('rm', '-f', '/etc/gdm/custom.conf') + + usr_overlay = subprocess.run( + ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + exec('chmod', '-R', '755', usr_overlay) + if os.path.isdir('/.blend-overlays/future-usr'): + exec('rm', '-f', '/.blend-overlays/future-usr/.okay') + exec('rm', '-rf', '/.blend-overlays/future-usr') + usr_overlay_workdir = subprocess.run( + ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + exec('chmod', '-R', '755', usr_overlay_workdir) + varlibpacman_overlay = subprocess.run( + ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + exec('chmod', '-R', '755', varlibpacman_overlay) + if os.path.isdir('/.blend-overlays/future-varlibpacman'): + exec('rm', '-f', '/.blend-overlays/future-varlibpacman/.okay') + exec('rm', '-rf', '/.blend-overlays/future-varlibpacman') + varlibpacman_overlay_workdir = subprocess.run( + ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() + exec('chmod', '-R', '755', varlibpacman_overlay_workdir) + + exec('mount', '-t', 'overlay', 'overlay', '-o', + f'lowerdir=/mnt/iso-update/squashfs-root/usr,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/mnt/iso-update/squashfs-root/usr') + + exec('mount', '-t', 'overlay', 'overlay', '-o', + f'lowerdir=/mnt/iso-update/squashfs-root/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/mnt/iso-update/squashfs-root/var/lib/pacman') + + # Install custom system packages + exec('touch', '/.custom_pkg_list') + exec('cp', '/.custom_pkg_list', '/mnt/iso-update/squashfs-root') + with open('/.custom_pkg_list') as custompkglist_file: + custompkglist = [] + while line := custompkglist_file.readline(): + if line.strip() != '': + custompkglist.append(line.strip()) + exec_chroot('pacman', '-Sy', '--needed', '--noconfirm', *custompkglist) + + # Note to self: since the hook only copies new files in /etc, configuring + # Note to self: locales and users isn't required + + # Unmount and rename overlays + exec('umount', '-l', '/mnt/iso-update/squashfs-root/usr') + exec('umount', '-l', '/mnt/iso-update/squashfs-root/var/lib/pacman') + exec('mv', usr_overlay, '/.blend-overlays/future-usr') + exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') + exec('touch', '/.blend-overlays/future-usr/.okay') + exec('touch', '/.blend-overlays/future-varlibpacman/.okay') + + # Mark as ready for update on boot + exec('touch', '/mnt/iso-update/.ready-for-update') + + print() + info('Update complete, reboot to apply.') + + def handle_system_packages(operation): if len(args.pkg) == 0 and operation != 'drop-overlay': error('no packages specified') @@ -371,7 +494,7 @@ def daemon(): if dir.startswith('.old.'): shutil.rmtree('/' + dir) while True: - if not os.path.isfile('/mnt/iso-update/.ready-for-update'): + if (not os.path.isfile('/mnt/iso-update/.ready-for-update')) and (not server_url == 'apex'): exec('touch', '/var/lib/.akshara-system-lock') system_lock = fasteners.InterProcessLock('/var/lib/.akshara-system-lock') with system_lock: @@ -407,6 +530,7 @@ parser = argparse.ArgumentParser(description=description, usage=argparse.SUPPRES epilog=epilog, formatter_class=argparse.RawTextHelpFormatter) command_map = {'help': 'help', 'version': 'version', + 'apex-update': apex_update, 'set-custom-packages': handle_system_packages, 'drop-overlay': handle_system_packages, 'daemon': daemon} diff --git a/akshara.hook b/akshara.hook index bd6162b..9321e27 100755 --- a/akshara.hook +++ b/akshara.hook @@ -16,6 +16,9 @@ run_latehook() { # Copy package list mv /new_root/mnt/iso-update/squashfs-root/.custom_pkg_list /new_root + if [[ -f /new_root/mnt/iso-update/squashfs-root/.base_packages ]]; then + mv /new_root/mnt/iso-update/squashfs-root/.base_packages /new_root + fi # Update /usr/lib/modules for current kernel version. for kversion in /new_root/.old.usr/lib/modules/*; do From 88b57afc847f5307f2b719cc8e08c39e30e12ae9 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Sat, 18 Nov 2023 01:40:19 +0530 Subject: [PATCH 062/135] chore: update pkgbuild source --- PKGBUILD | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index b4abc3c..d481d26 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -7,11 +7,11 @@ pkgdesc="An update system for operating systems" arch=('x86_64' 'i686') url="https://github.com/blend-os/blend" license=('GPL3') -makedepends=("electron${_electronversion}" 'git' 'npm' 'base-devel') -source=('git+file://[BASE_ASSEMBLE_PATH]/projects/akshara') +makedepends=('git' 'base-devel') +source=('git+https://git.blendos.co/blendOS/system-tools/akshara') sha256sums=('SKIP') -depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'python-fasteners' 'squashfs-tools' 'p7zip' 'zsync2') +depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'python-fasteners' 'python-yaml' 'squashfs-tools' 'p7zip' 'zsync2') provides=("${pkgname%-git}") conflicts=("${pkgname%-git}") From 9cc86eb24d581f68905a9a78c18136ce7426ae8e Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Sat, 18 Nov 2023 01:51:53 +0530 Subject: [PATCH 063/135] fix: add akshara to default package list --- akshara | 546 +++++++++++++++------------------------------------ akshara.hook | 88 ++------- 2 files changed, 175 insertions(+), 459 deletions(-) diff --git a/akshara b/akshara index 295bad3..da64e6d 100755 --- a/akshara +++ b/akshara @@ -25,14 +25,11 @@ import shutil import argparse import platform import fasteners +import threading import subprocess __version = '1.0.0' -with open('/etc/blend_release') as blend_release_file: - blend_release = yaml.load( - blend_release_file, Loader=yaml.FullLoader) - server_url = blend_release['server'] # Colors @@ -77,429 +74,203 @@ class colors: def exec(*cmd, **kwargs): - return subprocess.call(cmd, shell=False, **kwargs) + return subprocess.call(cmd, shell=False, stdout=sys.stdout, stderr=sys.stderr, **kwargs) def exec_chroot(*cmd, **kwargs): - return exec('systemd-nspawn', '-D', '/mnt/iso-update/squashfs-root', '--', *cmd, **kwargs) + return exec('systemd-nspawn', '-D', '/.new_rootfs', '--', *cmd, **kwargs) + + +fg = colors.fg() def info(msg): - print(colors.bold + colors.fg.cyan + '>> i: ' + - colors.reset + colors.bold + msg + colors.reset) + print(colors.bold + fg.cyan + '[INFO] ' + + colors.reset + msg + colors.reset) + + +def warn(warning): + print(colors.bold + fg.yellow + '[WARNING] ' + + colors.reset + warning + colors.reset) def error(err): - print(colors.bold + colors.fg.red + '>> e: ' + - colors.reset + colors.bold + err + colors.reset) - - -def get_server_timestamp(): - with open('/etc/blend_release') as blend_release_file: - track = yaml.load(blend_release_file, Loader=yaml.FullLoader)['track'] - server_version_output = subprocess.run( - ['curl', '--silent', '-L', '--show-error', f'{server_url}/track/{track}/current'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - if server_version_output.stderr.decode().strip() != '': - return 0 - elif server_version_output.stdout.decode().strip() != '' and server_version_output.stdout.decode().strip().isnumeric(): - return int(server_version_output.stdout.decode().strip()) - else: - return 0 + print(colors.bold + fg.red + '[ERROR] ' + + colors.reset + err + colors.reset) def update_system(): - os.chdir('/mnt') - if os.path.isdir('/mnt/iso-update'): - for f in os.listdir('/mnt/iso-update'): - if f != 'update.iso': - exec('rm', '-rf', f'/mnt/iso-update/{f}') + if os.path.isdir('/.update_rootfs'): + error('update already downloaded, you must reboot first') + sys.exit(75) + + os.chdir('/') + + if os.path.isdir('/.new_rootfs'): + exec('rm', '-rf', '/.new_rootfs') # Check if update is available - if os.path.isfile('/etc/blend_release'): - with open('/etc/blend_release') as blend_release_file: - blend_release = yaml.load( - blend_release_file, Loader=yaml.FullLoader) - current_timestamp = blend_release['current'] - track = blend_release['track'] - if get_server_timestamp() > current_timestamp: - # Update is available, let's download the latest ISO - exec('mkdir', '-p', '/mnt/iso-update') - if not os.path.isfile('/mnt/iso-update/update.iso'): - if exec('zsync2', f'https://updates.blendos.co/{track}/{get_server_timestamp()}/update.iso.zsync', '-o', '/mnt/iso-update/update.iso') != 0: - return - else: - if exec('zsync2', f'https://updates.blendos.co/{track}/{get_server_timestamp()}/update.iso.zsync', '-i', '/mnt/iso-update/update.iso', '-o', '/mnt/iso-update/update.iso') != 0: - return + if not os.path.isfile('/system.yaml'): + error('system.yaml does not exist in /') + sys.exit(100) - # Since the ISO has been downloaded, proceed to extracing it - # as well the rootfs it contains (single-core unsquashfs) - exec('rm', '-rf', '/mnt/iso-update/iso', - '/mnt/iso-update/squashfs-root') - exec('7z', '-oiso', 'x', 'update.iso', cwd='/mnt/iso-update') - if exec('unsquashfs', '-p', '1', f'iso/blend/{platform.machine()}/airootfs.sfs', cwd='/mnt/iso-update') != 0: - return + with open('/system.yaml') as blend_release_file: + blend_release = yaml.load( + blend_release_file, Loader=yaml.FullLoader) - ######################## - # Configure new rootfs # - ######################## + info('downloading Arch tarball...') - # Enable services - exec_chroot('systemctl', 'enable', 'akshara') - exec_chroot('systemctl', 'enable', 'bluetooth') - exec_chroot('systemctl', 'enable', 'cups') - exec_chroot('systemctl', '--global', 'enable', 'blend-files') + if not os.path.isfile('/.update.tar.gz'): + if exec('wget', '-q', '--show-progress', 'https://geo.mirror.pkgbuild.com/iso/latest/archlinux-bootstrap-x86_64.tar.gz', '-O', '/.update.tar.gz') != 0: + warn('failed download') + print() + info('trying download again...') + print() + exec('rm', '-f', '/.update.tar.gz') + if exec('wget', '-q', '--show-progress', 'https://geo.mirror.pkgbuild.com/iso/latest/archlinux-bootstrap-x86_64.tar.gz', '-O', '/.update.tar.gz') != 0: + error('failed download') + print() + error('update failed') + sys.exit(50) - # Add akshara hook - exec_chroot( - 'bash', '-c', 'echo \'MODULES=""\' > /etc/mkinitcpio.conf') - exec_chroot( - 'bash', '-c', 'echo \'BINARIES=""\' >> /etc/mkinitcpio.conf') - exec_chroot( - 'bash', '-c', 'echo \'FILES=""\' >> /etc/mkinitcpio.conf') - exec_chroot( - 'bash', '-c', 'echo \'HOOKS="base udev akshara plymouth autodetect modconf block keyboard keymap consolefont filesystems fsck"\' >> /etc/mkinitcpio.conf') - exec_chroot( - 'bash', '-c', 'echo \'COMPRESSION="zstd"\' >> /etc/mkinitcpio.conf') - - if 'NVIDIA' in subprocess.check_output(['lspci']).decode('utf-8'): - exec_chroot( - 'bash', '-c', 'echo -e \'\\nGRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_DEFAULT} vt.global_cursor_default=0 nvidia_drm.modeset=1 splash"\' >> /etc/default/grub') - exec_chroot('mkdir', '-p', '/etc/udev/rules.d') - exec_chroot('ln', '-s', '/dev/null', - '/etc/udev/rules.d/61-gdm.rules') + 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\.gz/.update.tar.gz/g") 2>/dev/null') != 0: + error('failed checksum verification') + print() + info('trying download again...') + exec('rm', '-f', '/.update.tar.gz') + if exec('wget', '-q', '--show-progress', 'https://geo.mirror.pkgbuild.com/iso/latest/archlinux-bootstrap-x86_64.tar.gz', '-O', '/.update.tar.gz') != 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\.gz/.update.tar.gz/g") 2>/dev/null') != 0: + error('failed checksum verification') + print() + error('update failed') + sys.exit(25) + return - # Refresh package lists, pacman-key --init - exec_chroot('pacman', '-Rn', '--noconfirm', - 'jade-gui', 'blend-inst-git') - exec_chroot('pacman-key', '--init') - exec_chroot('pacman-key', '--populate', 'archlinux', 'blend') + info('checksum verification was successful') - # Disable auto-login for blend user - exec_chroot( - 'bash', '-c', 'echo "[Theme]" > /etc/sddm.conf.d/default.conf') - exec_chroot( - 'bash', '-c', 'echo "Current=breeze" >> /etc/sddm.conf.d/default.conf') - exec_chroot('rm', '-f', '/etc/gdm/custom.conf') + print() - usr_overlay = subprocess.run( - ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - exec('chmod', '-R', '755', usr_overlay) - if os.path.isdir('/.blend-overlays/future-usr'): - exec('rm', '-f', '/.blend-overlays/future-usr/.okay') - exec('rm', '-rf', '/.blend-overlays/future-usr') - usr_overlay_workdir = subprocess.run( - ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - exec('chmod', '-R', '755', usr_overlay_workdir) - varlibpacman_overlay = subprocess.run( - ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - exec('chmod', '-R', '755', varlibpacman_overlay) - if os.path.isdir('/.blend-overlays/future-varlibpacman'): - exec('rm', '-f', '/.blend-overlays/future-varlibpacman/.okay') - exec('rm', '-rf', '/.blend-overlays/future-varlibpacman') - varlibpacman_overlay_workdir = subprocess.run( - ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - exec('chmod', '-R', '755', varlibpacman_overlay_workdir) + info('generating new system...') - exec('mount', '-t', 'overlay', 'overlay', '-o', - f'lowerdir=/mnt/iso-update/squashfs-root/usr,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/mnt/iso-update/squashfs-root/usr') + exec('tar', '--acls', '--xattrs', '-xf', '.update.tar.gz') + exec('mv', 'root.x86_64', '.new_rootfs') + exec('rm', '-f', '/.new_rootfs/pkglist.x86_64.txt') + exec('rm', '-f', '/.new_rootfs/version') - exec('mount', '-t', 'overlay', 'overlay', '-o', - f'lowerdir=/mnt/iso-update/squashfs-root/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/mnt/iso-update/squashfs-root/var/lib/pacman') + packages = [ + 'akshara', + 'blend' + ] - # Install custom system packages - exec('touch', '/.custom_pkg_list') - exec('cp', '/.custom_pkg_list', '/mnt/iso-update/squashfs-root') - with open('/.custom_pkg_list') as custompkglist_file: - custompkglist = [] - while line := custompkglist_file.readline(): - if line.strip() != '': - custompkglist.append(line.strip()) - exec_chroot('pacman', '-Sy', '--needed', '--noconfirm', *custompkglist) + services = [ + 'akshara' + ] - # Note to self: since the hook only copies new files in /etc, configuring - # Note to self: locales and users isn't required + user_services = [ + 'blend-files' + ] - # Unmount and rename overlays - exec('umount', '-l', '/mnt/iso-update/squashfs-root/usr') - exec('umount', '-l', '/mnt/iso-update/squashfs-root/var/lib/pacman') - exec('mv', usr_overlay, '/.blend-overlays/future-usr') - exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') - exec('touch', '/.blend-overlays/future-usr/.okay') - exec('touch', '/.blend-overlays/future-varlibpacman/.okay') + if type(blend_release.get('packages')) == list: + packages += blend_release.get('packages') - # Mark as ready for update on boot - exec('touch', '/mnt/iso-update/.ready-for-update') + if type(blend_release.get('services')) == list: + services += blend_release.get('services') + + if type(blend_release.get('user-services')) == list: + user_services += blend_release.get('user-services') + + with open('/.new_rootfs/etc/pacman.d/mirrorlist', 'w') as pacman_mirrorlist_conf: + pacman_mirrorlist_conf.write('Server = https://cloudflaremirrors.com/archlinux/$repo/os/$arch\n') + + #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', 'a') as pacman_conf: + pacman_conf.write(f''' +[breakfast] +SigLevel = Never +Server = {blend_release['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): + pacman_conf.write(f''' +[{package_repo["name"]}] +SigLevel = Never +Server = {package_repo["repo-url"]} +''') -def apex_update(): - try: - apex_iso = sys.argv[2] - except IndexError: - error('you must pass a valid ISO as an argument') - exit(1) + 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('mkdir', '-p', '/mnt/iso-update') + # update packages + exec_chroot('pacman-key', '--init') + exec_chroot('pacman-key', '--populate') - if os.path.isfile(apex_iso): - exec('cp', apex_iso, f'/mnt/iso-update/update.iso') - else: - error('you must pass a valid ISO as an argument') - exit(1) + if exec_chroot('pacman', '-Syu', '--noconfirm') != 0: + if exec_chroot('pacman', '-Syu', '--noconfirm') != 0: + if exec_chroot('pacman', '-Syu', '--noconfirm') != 0: + if exec_chroot('pacman', '-Syu', '--noconfirm') != 0: + error('update failed due to unsuccessful package downloads') + sys.exit(50) - if os.path.isdir('/mnt/iso-update'): - for f in os.listdir('/mnt/iso-update'): - if f != 'update.iso': - exec('rm', '-rf', f'/mnt/iso-update/{f}') + if exec_chroot('pacman', '-S', '--ask=4', *packages) != 0: + if exec_chroot('pacman', '-S', '--ask=4', *packages) != 0: + if exec_chroot('pacman', '-S', '--ask=4', *packages) != 0: + if exec_chroot('pacman', '-S', '--ask=4', *packages) != 0: + error('update failed due to unsuccessful package downloads') + sys.exit(50) - # Since the ISO is present, proceed to extracing it - # as well the rootfs it contains (single-core unsquashfs) - exec('rm', '-rf', '/mnt/iso-update/iso', - '/mnt/iso-update/squashfs-root') - exec('7z', '-oiso', 'x', 'update.iso', cwd='/mnt/iso-update') - if exec('unsquashfs', '-p', '1', f'iso/blend/{platform.machine()}/airootfs.sfs', cwd='/mnt/iso-update') != 0: - return + kernel_exists = False - ######################## - # Configure new rootfs # - ######################## + for f in os.listdir('/.new_rootfs/boot'): + if f.startswith('vmlinuz'): + kernel_exists = True + break - # Enable services - exec_chroot('systemctl', 'enable', 'akshara') - exec_chroot('systemctl', 'enable', 'bluetooth') - exec_chroot('systemctl', 'enable', 'cups') - exec_chroot('systemctl', '--global', 'enable', 'blend-files') + if not kernel_exists: + error('no Linux kernel found in new system') + error('cancelling update so as not to render the system unbootable') + sys.exit(10) - # Add akshara hook - exec_chroot( - 'bash', '-c', 'echo \'MODULES=""\' > /etc/mkinitcpio.conf') - exec_chroot( - 'bash', '-c', 'echo \'BINARIES=""\' >> /etc/mkinitcpio.conf') - exec_chroot( - 'bash', '-c', 'echo \'FILES=""\' >> /etc/mkinitcpio.conf') - exec_chroot( - 'bash', '-c', 'echo \'HOOKS="base udev akshara plymouth autodetect modconf block keyboard keymap consolefont filesystems fsck"\' >> /etc/mkinitcpio.conf') - exec_chroot( - 'bash', '-c', 'echo \'COMPRESSION="zstd"\' >> /etc/mkinitcpio.conf') - - if 'NVIDIA' in subprocess.check_output(['lspci']).decode('utf-8'): - exec_chroot( - 'bash', '-c', 'echo -e \'\\nGRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_DEFAULT} vt.global_cursor_default=0 nvidia_drm.modeset=1 splash"\' >> /etc/default/grub') - exec_chroot('mkdir', '-p', '/etc/udev/rules.d') - exec_chroot('ln', '-s', '/dev/null', - '/etc/udev/rules.d/61-gdm.rules') + exec('mv', '.new_rootfs', '.update_rootfs') - # Refresh package lists, pacman-key --init - exec_chroot('pacman', '-Rn', '--noconfirm', - 'jade-gui', 'blend-inst-git') - exec_chroot('pacman-key', '--init') - exec_chroot('pacman-key', '--populate', 'archlinux', 'blend') + new_boot_files = [] - # Disable auto-login for blend user - exec_chroot( - 'bash', '-c', 'echo "[Theme]" > /etc/sddm.conf.d/default.conf') - exec_chroot( - 'bash', '-c', 'echo "Current=breeze" >> /etc/sddm.conf.d/default.conf') - exec_chroot('rm', '-f', '/etc/gdm/custom.conf') + # for f in os.listdir('/.update_rootfs/boot'): + # if not os.path.isdir(f'/.update_rootfs/boot/{f}'): + # exec('mv', f'/.update_rootfs/boot/{f}', '/boot') + # new_boot_files.append(f) - usr_overlay = subprocess.run( - ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - exec('chmod', '-R', '755', usr_overlay) - if os.path.isdir('/.blend-overlays/future-usr'): - exec('rm', '-f', '/.blend-overlays/future-usr/.okay') - exec('rm', '-rf', '/.blend-overlays/future-usr') - usr_overlay_workdir = subprocess.run( - ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - exec('chmod', '-R', '755', usr_overlay_workdir) - varlibpacman_overlay = subprocess.run( - ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - exec('chmod', '-R', '755', varlibpacman_overlay) - if os.path.isdir('/.blend-overlays/future-varlibpacman'): - exec('rm', '-f', '/.blend-overlays/future-varlibpacman/.okay') - exec('rm', '-rf', '/.blend-overlays/future-varlibpacman') - varlibpacman_overlay_workdir = subprocess.run( - ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - exec('chmod', '-R', '755', varlibpacman_overlay_workdir) + # for f in os.listdir('/boot'): + # if not os.path.isdir(f'/boot/{f}'): + # if f not in new_boot_files: + # exec('rm', '-f', f'/boot/{f}') - exec('mount', '-t', 'overlay', 'overlay', '-o', - f'lowerdir=/mnt/iso-update/squashfs-root/usr,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/mnt/iso-update/squashfs-root/usr') + # exec('grub-mkconfig', '-o', '/boot/grub/grub.cfg') - exec('mount', '-t', 'overlay', 'overlay', '-o', - f'lowerdir=/mnt/iso-update/squashfs-root/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/mnt/iso-update/squashfs-root/var/lib/pacman') - - # Install custom system packages - exec('touch', '/.custom_pkg_list') - exec('cp', '/.custom_pkg_list', '/mnt/iso-update/squashfs-root') - with open('/.custom_pkg_list') as custompkglist_file: - custompkglist = [] - while line := custompkglist_file.readline(): - if line.strip() != '': - custompkglist.append(line.strip()) - exec_chroot('pacman', '-Sy', '--needed', '--noconfirm', *custompkglist) - - # Note to self: since the hook only copies new files in /etc, configuring - # Note to self: locales and users isn't required - - # Unmount and rename overlays - exec('umount', '-l', '/mnt/iso-update/squashfs-root/usr') - exec('umount', '-l', '/mnt/iso-update/squashfs-root/var/lib/pacman') - exec('mv', usr_overlay, '/.blend-overlays/future-usr') - exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') - exec('touch', '/.blend-overlays/future-usr/.okay') - exec('touch', '/.blend-overlays/future-varlibpacman/.okay') - - # Mark as ready for update on boot - exec('touch', '/mnt/iso-update/.ready-for-update') - - print() - info('Update complete, reboot to apply.') - - -def handle_system_packages(operation): - if len(args.pkg) == 0 and operation != 'drop-overlay': - error('no packages specified') - exit(1) - - for pkg in args.pkg: - if pkg.startswith('linux'): - error('you may not install linux* packages') - exit(1) - - if os.path.isfile('/mnt/iso-update/.ready-for-update'): - error('an update was downloaded in the background, you') - error('must reboot before installing any system packages') - - if operation == 'set-custom-packages': - info('this operation will replace the current overlay on the next boot') - print() - - time.sleep(2) - - exec('mkdir', '-p', '/.blendrw') - while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0: - pass - while exec('umount', '-l', '/.blendrw/var/lib/pacman', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0: - pass - while exec('umount', '-l', '/.blendrw', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0: - pass - for old_overlay in os.listdir('/mnt'): - if old_overlay.startswith('.blend-tmp-overlay-'): - exec('rm', '-rf', f'/mnt/{old_overlay}') - usr_overlay = subprocess.run( - ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - exec('chmod', '-R', '755', usr_overlay) - if os.path.isdir('/.blend-overlays/future-usr'): - exec('rm', '-f', '/.blend-overlays/future-usr/.okay') - exec('rm', '-rf', usr_overlay) - exec('mv', '/.blend-overlays/future-usr', usr_overlay) - usr_overlay_workdir = subprocess.run( - ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - exec('chmod', '-R', '755', usr_overlay_workdir) - varlibpacman_overlay = subprocess.run( - ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - exec('chmod', '-R', '755', varlibpacman_overlay) - if os.path.isdir('/.blend-overlays/future-varlibpacman'): - exec('rm', '-f', '/.blend-overlays/future-varlibpacman/.okay') - exec('rm', '-rf', varlibpacman_overlay) - exec('mv', '/.blend-overlays/future-varlibpacman', varlibpacman_overlay) - varlibpacman_overlay_workdir = subprocess.run( - ['mktemp', '-d', '/mnt/.blend-tmp-overlay-XXXXXXXXXXXXX'], stdout=subprocess.PIPE).stdout.decode().strip() - exec('chmod', '-R', '755', varlibpacman_overlay_workdir) - if '' in (usr_overlay, usr_overlay_workdir, varlibpacman_overlay, varlibpacman_overlay_workdir): - for old_overlay in os.listdir('/mnt'): - if old_overlay.startswith('.blend-tmp-overlay-'): - exec('rm', '-rf', f'/mnt/{old_overlay}') - error('error during overlay creation') - exit(1) - exec('mkdir', '-p', '/.blendrw') - exec('mount', subprocess.run(['findmnt', '-n', '-o', 'SOURCE', '/'], - stdout=subprocess.PIPE).stdout.decode().strip(), '/.blendrw') - exec('mount', '-t', 'overlay', 'overlay', '-o', - f'lowerdir=/.blendrw/usr,upperdir={usr_overlay},workdir={usr_overlay_workdir}', '/.blendrw/usr') - exec('mount', '-t', 'overlay', 'overlay', '-o', - f'lowerdir=/.blendrw/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/.blendrw/var/lib/pacman') - - if operation == 'set-custom-packages': - operation = ['-Sy', '--needed', '--noconfirm'] - elif operation == 'drop-overlay': - exec('rm', '-rf', '/.blend-overlays/future-usr') - exec('rm', '-rf', '/.blend-overlays/future-varlibpacman') - - exec('mkdir', '-p', '/.blend-overlays/future-usr') - exec('mkdir', '-p', '/.blend-overlays/future-varlibpacman') - - exec('rm', '-f', '/.custom_pkg_list') - exec('touch', '/.custom_pkg_list') - - exec('touch', '/.blend-overlays/future-usr/.okay') - exec('touch', '/.blend-overlays/future-varlibpacman/.okay') - exit() - - if exec('systemd-nspawn', '-D', '/.blendrw', '--', 'pacman', *operation, '--', *args.pkg, stdout=sys.stdout, stderr=sys.stderr) != 0: - error('error occurred during installation, abandoning changes') - while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: - pass - while exec('umount', '-l', '/.blendrw/var/lib/pacman', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: - pass - while exec('umount', '-l', '/.blendrw', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: - pass - for old_overlay in os.listdir('/mnt'): - if old_overlay.startswith('.blend-tmp-overlay-'): - exec('rm', '-rf', f'/mnt/{old_overlay}') - elif args.headless: - while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: - pass - while exec('umount', '-l', '/.blendrw/var/lib/pacman', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: - pass - while exec('umount', '-l', '/.blendrw', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: - pass - exec('mv', usr_overlay, '/.blend-overlays/future-usr') - exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') - exec('rm', '-rf', usr_overlay_workdir, varlibpacman_overlay_workdir) - exec('bash', '-c', "echo -n > /.custom_pkg_list") - for pkg in args.pkg: - exec('bash', '-c', f"echo '{pkg}' >> /.custom_pkg_list") - exec('touch', '/.blend-overlays/future-usr/.okay') - exec('touch', '/.blend-overlays/future-varlibpacman/.okay') - info('reboot to apply changes') - else: - info("you are requested to review the operation's output") - info("press ENTER to proceed with making overlay permanent, or ^C to abort") - info("(aborting will also remove any packages installed previously without rebooting)") - try: - input() - except EOFError: - exit() - - while exec('umount', '-l', '/.blendrw/usr', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: - pass - while exec('umount', '-l', '/.blendrw/var/lib/pacman', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: - pass - while exec('umount', '-l', '/.blendrw', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: - pass - exec('mv', usr_overlay, '/.blend-overlays/future-usr') - exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman') - exec('rm', '-rf', usr_overlay_workdir, varlibpacman_overlay_workdir) - exec('bash', '-c', "echo -n > /.custom_pkg_list") - for pkg in list(set(args.pkg)): - exec('bash', '-c', f"echo '{pkg}' >> /.custom_pkg_list") - exec('touch', '/.blend-overlays/future-usr/.okay') - exec('touch', '/.blend-overlays/future-varlibpacman/.okay') - info('reboot to apply changes') + info('downloaded update and generated new rootfs') + info('you may reboot now') def daemon(): - exec('mkinitcpio', '-P') - exec('grub-mkconfig', '-o', '/boot/grub/grub.cfg') for dir in os.listdir('/'): if dir.startswith('.old.'): shutil.rmtree('/' + dir) - while True: - if (not os.path.isfile('/mnt/iso-update/.ready-for-update')) and (not server_url == 'apex'): - exec('touch', '/var/lib/.akshara-system-lock') - system_lock = fasteners.InterProcessLock('/var/lib/.akshara-system-lock') - with system_lock: - update_system() - time.sleep(60) + + Event().wait() description = f''' @@ -508,14 +279,9 @@ description = f''' {colors.bold}{colors.fg.cyan}version:{colors.reset} {__version}{colors.bold} -This CLI is only meant for developers familiar with blendOS and the akshara codebase. - -blendOS is not responsible for any system breakage. - {colors.bold}{colors.fg.cyan}available commands{colors.reset}: {colors.bold}help{colors.reset} Show this help message and exit. - {colors.bold}set-custom-packages{colors.reset} Set the custom system packages to be included in the overlay. - {colors.bold}drop-overlay{colors.reset} Drop an overlay created previously using set-custom-packages. + {colors.bold}update{colors.reset} Update your blendOS system. {colors.bold}version{colors.reset} Show version information and exit. {colors.bold}{colors.fg.cyan}options for commands{colors.reset}: @@ -530,9 +296,7 @@ parser = argparse.ArgumentParser(description=description, usage=argparse.SUPPRES epilog=epilog, formatter_class=argparse.RawTextHelpFormatter) command_map = {'help': 'help', 'version': 'version', - 'apex-update': apex_update, - 'set-custom-packages': handle_system_packages, - 'drop-overlay': handle_system_packages, + 'update': update_system, 'daemon': daemon} parser.add_argument('command', choices=command_map.keys(), help=argparse.SUPPRESS) @@ -560,12 +324,12 @@ try: parser.print_help() elif command == 'version': parser.parse_args(['--version']) - elif command == handle_system_packages: + elif command == update_system: exec('touch', '/var/lib/.akshara-system-lock') system_lock = fasteners.InterProcessLock('/var/lib/.akshara-system-lock') info('attempting to acquire system lock') with system_lock: - command(args.command) + command() else: command() except KeyboardInterrupt: diff --git a/akshara.hook b/akshara.hook index 9321e27..9cd6817 100755 --- a/akshara.hook +++ b/akshara.hook @@ -3,89 +3,41 @@ run_latehook() { echo - touch /new_root/.custom_pkg_list - - # Remove /new_root/mnt/iso-update/.successful-update if exists - rm -f /new_root/mnt/iso-update/.successful-update + # Remove /new_root/.successful-update if exists + rm -f /new_root/.successful-update # Detect if update downloaded. - if [[ -f /new_root/mnt/iso-update/.ready-for-update ]]; then + if [[ -d /new_root/.update_rootfs ]]; then # Available, rename old /usr and move new /usr to /. mv /new_root/usr /new_root/.old.usr - mv /new_root/mnt/iso-update/squashfs-root/usr /new_root/usr + mv /new_root/.update_rootfs/usr /new_root/usr - # Copy package list - mv /new_root/mnt/iso-update/squashfs-root/.custom_pkg_list /new_root - if [[ -f /new_root/mnt/iso-update/squashfs-root/.base_packages ]]; then - mv /new_root/mnt/iso-update/squashfs-root/.base_packages /new_root - fi - - # Update /usr/lib/modules for current kernel version. - for kversion in /new_root/.old.usr/lib/modules/*; do - if [[ ! -d /new_root/usr/lib/modules/"$(basename "$kversion")" ]]; then - mv "$kversion" /new_root/usr/lib/modules/"$(basename "$kversion")" - fi - done + # Same for /var/cache/pacman. + mv /new_root/var/cache/pacman /new_root/.old.pacmancache + mv /new_root/.update_rootfs/var/cache/pacman /new_root/var/cache # Same for /var/lib/pacman. mv /new_root/var/lib/pacman /new_root/.old.var.lib.pacman - mv /new_root/mnt/iso-update/squashfs-root/var/lib/pacman /new_root/var/lib + mv /new_root/.update_rootfs/var/lib/pacman /new_root/var/lib # Move to /etc stage. - rm -f /new_root/mnt/iso-update/.ready-for-update - touch /new_root/mnt/iso-update/.etc-stage + touch /new_root/.etc-stage fi # Detect if /etc stage is active. - if [[ -f /new_root/mnt/iso-update/.etc-stage ]]; then + if [[ -f /new_root/.etc-stage ]]; then # Create new /etc. - cp -a /new_root/mnt/iso-update/squashfs-root/etc /new_root/.new.etc - - # Replace editable /etc files. - for i in sudoers crypttab fstab group gshadow hostname hosts passwd resolv.conf shadow shells subgid subuid; do - mv "/new_root/etc/${i}" "/new_root/.new.etc/${i}" - done - mv "/new_root/etc/default/grub" "/new_root/.new.etc/default/grub" - [[ -d /new_root/etc/NetworkManager/system-connections ]] && ( - rm -rf /new_root/.new.etc/NetworkManager/system-connections; - mv /new_root/etc/NetworkManager/system-connections /new_root/.new.etc/NetworkManager/system-connections - ) - - # Rename existing /etc. - mv /new_root/etc /new_root/.old.etc &>/dev/null || : - - # Rename new /etc. - mv /new_root/.new.etc /new_root/etc &>/dev/null || : - - if [[ -f /boot/amd-ucode.img ]]; then - mv /new_root/mnt/iso-update/iso/boot/amd-ucode.img /new_root/boot/amd-ucode.img - fi - - if [[ -f /boot/intel-ucode.img ]]; then - mv /new_root/mnt/iso-update/iso/boot/intel-ucode.img /new_root/boot/intel-ucode.img - fi + rm -rf /new_root/.new_etc + cp -a /new_root/etc /new_root/.new_etc + cp /new_root/.update_rootfs/etc/pacman.conf /new_root/.new_etc/pacman.conf + rm -rf /new_root/.new_etc/pacman.d + cp -a /new_root/.update_rootfs/etc/pacman.d /new_root/.new_etc/pacman.d + cp -an /new_root/.update_rootfs/etc/* /new_root/.new_etc + mv /new_root/etc /new_root/.old.etc || : + mv /new_root/.new_etc /new_root/etc # Successful update. - rm -f /new_root/mnt/iso-update/.etc-stage - touch /new_root/mnt/iso-update/.successful-update + rm -f /new_root/.etc-stage + touch /new_root/.successful-update fi - - # Handle overlays. - - if [[ -f '/new_root/.blend-overlays/future-usr/.okay' ]] && [[ -f '/new_root/.blend-overlays/future-varlibpacman/.okay' ]]; then - for i in usr varlibpacman; do - rm -rf /new_root/.blend-overlays/$i - mv /new_root/.blend-overlays/future-$i /new_root/.blend-overlays/$i - done - else - rm -rf /new_root/.blend-overlays/usr.workdir /new_root/.blend-overlays/varlibpacman.workdir - fi - - for i in usr varlibpacman; do - mkdir -p /new_root/.blend-overlays/$i - mkdir -p /new_root/.blend-overlays/$i.workdir - done - - mount -t overlay overlay -o index=off -o metacopy=off -o ro,lowerdir=/new_root/usr,upperdir=/new_root/.blend-overlays/usr,workdir=/new_root/.blend-overlays/usr.workdir /new_root/usr - mount -t overlay overlay -o index=off -o metacopy=off -o ro,lowerdir=/new_root/var/lib/pacman,upperdir=/new_root/.blend-overlays/varlibpacman,workdir=/new_root/.blend-overlays/varlibpacman.workdir /new_root/var/lib/pacman } From dff86ece7551b7c73bb9794a8c302d84c45a8bae Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Sat, 18 Nov 2023 18:28:09 +0530 Subject: [PATCH 064/135] chore: remove zsync2 dep --- PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKGBUILD b/PKGBUILD index d481d26..14b2ab3 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -11,7 +11,7 @@ makedepends=('git' 'base-devel') source=('git+https://git.blendos.co/blendOS/system-tools/akshara') sha256sums=('SKIP') -depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'python-fasteners' 'python-yaml' 'squashfs-tools' 'p7zip' 'zsync2') +depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'python-fasteners' 'python-yaml' 'squashfs-tools') provides=("${pkgname%-git}") conflicts=("${pkgname%-git}") From 2b0c29fb02e59bbac1fce25399b6ea82b1934322 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Sat, 18 Nov 2023 18:49:42 +0530 Subject: [PATCH 065/135] chore: add wget dep --- PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKGBUILD b/PKGBUILD index 14b2ab3..a024bf3 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -11,7 +11,7 @@ makedepends=('git' 'base-devel') source=('git+https://git.blendos.co/blendOS/system-tools/akshara') sha256sums=('SKIP') -depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'python-fasteners' 'python-yaml' 'squashfs-tools') +depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'python-fasteners' 'python-yaml' 'squashfs-tools' 'wget') provides=("${pkgname%-git}") conflicts=("${pkgname%-git}") From 58882feaac0ae16dfa211b29d0680fb50a1a3bf1 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Mon, 20 Nov 2023 12:25:24 +0530 Subject: [PATCH 066/135] feat: implement pulling tracks from repos, add a sample /system.yaml --- akshara | 47 ++++++++++++++++++++++++++++++++++++++-------- akshara.hook | 3 +++ akshara.install | 3 +++ system.yaml.sample | 16 ++++++++++++++++ 4 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 system.yaml.sample diff --git a/akshara b/akshara index da64e6d..ab8ff4d 100755 --- a/akshara +++ b/akshara @@ -23,9 +23,10 @@ import time import yaml import shutil import argparse +import requests import platform import fasteners -import threading +from threading import Event import subprocess __version = '1.0.0' @@ -99,6 +100,21 @@ def error(err): colors.reset + err + colors.reset) +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()) + + if (type(result.get('impl')) == str and + type(result.get('track')) != 'custom'): + res = interpret_track(result) + + for i in res.keys(): + if type(res[i]) is list: + if type(result.get(i)) is list: + result[i] = res[i] + result[i] + + return result + + def update_system(): if os.path.isdir('/.update_rootfs'): error('update already downloaded, you must reboot first') @@ -163,17 +179,21 @@ def update_system(): exec('rm', '-f', '/.new_rootfs/version') packages = [ - 'akshara', - 'blend' + 'akshara' ] services = [ 'akshara' ] - user_services = [ - 'blend-files' - ] + if (type(blend_release.get('impl')) == str and + type(blend_release.get('track')) != 'custom'): + res = interpret_track(blend_release) + + for i in res.keys(): + if type(res[i]) is list: + if type(blend_release.get(i)) is list: + blend_release[i] += res[i] if type(blend_release.get('packages')) == list: packages += blend_release.get('packages') @@ -184,6 +204,10 @@ def update_system(): if type(blend_release.get('user-services')) == list: user_services += blend_release.get('user-services') + print(blend_release) + + exit(5) + with open('/.new_rootfs/etc/pacman.d/mirrorlist', 'w') as pacman_mirrorlist_conf: pacman_mirrorlist_conf.write('Server = https://cloudflaremirrors.com/archlinux/$repo/os/$arch\n') @@ -233,6 +257,13 @@ Server = {package_repo["repo-url"]} error('update failed due to unsuccessful package downloads') sys.exit(50) + if type(blend_release.get('commands')) == list: + for command in blend_release.get('commands'): + if type(command) == str: + exec_chroot('bash', '-c', command) + elif type(command) == list: + exec_chroot(*command) + kernel_exists = False for f in os.listdir('/.new_rootfs/boot'): @@ -268,9 +299,9 @@ Server = {package_repo["repo-url"]} def daemon(): for dir in os.listdir('/'): if dir.startswith('.old.'): - shutil.rmtree('/' + dir) + exec('rm', '-rf', '/' + dir) - Event().wait() + Event.wait() description = f''' diff --git a/akshara.hook b/akshara.hook index 9cd6817..9b1ef2c 100755 --- a/akshara.hook +++ b/akshara.hook @@ -29,6 +29,7 @@ run_latehook() { # Create new /etc. rm -rf /new_root/.new_etc cp -a /new_root/etc /new_root/.new_etc + (cd /new_root/etc && find . -type f -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type f) | xargs -0 rm -rf) cp /new_root/.update_rootfs/etc/pacman.conf /new_root/.new_etc/pacman.conf rm -rf /new_root/.new_etc/pacman.d cp -a /new_root/.update_rootfs/etc/pacman.d /new_root/.new_etc/pacman.d @@ -38,6 +39,8 @@ run_latehook() { # Successful update. rm -f /new_root/.etc-stage + + mv /new_root/.update_rootfs /new_root/.old.update_rootfs touch /new_root/.successful-update fi } diff --git a/akshara.install b/akshara.install index 7d9d6c3..0ba292a 100644 --- a/akshara.install +++ b/akshara.install @@ -4,6 +4,9 @@ build() { add_module overlay add_binary bash + add_binary xargs + add_binary find + add_binary grep add_binary findmnt add_binary uname add_runscript diff --git a/system.yaml.sample b/system.yaml.sample new file mode 100644 index 0000000..6ef12ff --- /dev/null +++ b/system.yaml.sample @@ -0,0 +1,16 @@ +repo: 'https://pkg-repo.blendos.co/' + +impl: 'https://github.com/blend-os/tracks/raw/main' + +track: 'gnome' + +packages: + - 'micro' + - 'caddy' + +services: + - 'caddy' + +package-repos: + - name: 'chaotic-aur' + repo-url: 'https://cdn-mirror.chaotic.cx/$repo/$arch' \ No newline at end of file From c68c26f72c4326b9aa288bd29aca33d52316a5a4 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Mon, 20 Nov 2023 12:33:21 +0530 Subject: [PATCH 067/135] chore: add python-requests as dep --- PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKGBUILD b/PKGBUILD index a024bf3..1eb3194 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -11,7 +11,7 @@ makedepends=('git' 'base-devel') source=('git+https://git.blendos.co/blendOS/system-tools/akshara') sha256sums=('SKIP') -depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'python-fasteners' 'python-yaml' 'squashfs-tools' 'wget') +depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'python-fasteners' 'python-yaml' 'squashfs-tools' 'wget' 'python-requests') provides=("${pkgname%-git}") conflicts=("${pkgname%-git}") From a3ad96fc65988329a9ef9d0c88b6b9fbfb9a6a58 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Mon, 20 Nov 2023 12:42:38 +0530 Subject: [PATCH 068/135] fix: remove line used for debugging --- akshara | 2 -- 1 file changed, 2 deletions(-) diff --git a/akshara b/akshara index ab8ff4d..13cc36d 100755 --- a/akshara +++ b/akshara @@ -206,8 +206,6 @@ def update_system(): print(blend_release) - exit(5) - with open('/.new_rootfs/etc/pacman.d/mirrorlist', 'w') as pacman_mirrorlist_conf: pacman_mirrorlist_conf.write('Server = https://cloudflaremirrors.com/archlinux/$repo/os/$arch\n') From 9f2f25b037bc1c207d1fddfdbca8c0797f8c9037 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Mon, 20 Nov 2023 13:06:25 +0530 Subject: [PATCH 069/135] chore: make akshara retry package downloads 30 times before failing --- akshara | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/akshara b/akshara index 13cc36d..0ab558a 100755 --- a/akshara +++ b/akshara @@ -241,19 +241,25 @@ Server = {package_repo["repo-url"]} exec_chroot('pacman-key', '--init') exec_chroot('pacman-key', '--populate') - if exec_chroot('pacman', '-Syu', '--noconfirm') != 0: - if exec_chroot('pacman', '-Syu', '--noconfirm') != 0: - if exec_chroot('pacman', '-Syu', '--noconfirm') != 0: - if exec_chroot('pacman', '-Syu', '--noconfirm') != 0: - error('update failed due to unsuccessful package downloads') - sys.exit(50) + counter = 0 + while True: + return_val = exec_chroot('pacman', '-Syu', '--noconfirm') + counter += 1 + if counter > 30: + error('failed to download packages') + exit(50) + if return_val == 0: + break - if exec_chroot('pacman', '-S', '--ask=4', *packages) != 0: - if exec_chroot('pacman', '-S', '--ask=4', *packages) != 0: - if exec_chroot('pacman', '-S', '--ask=4', *packages) != 0: - if exec_chroot('pacman', '-S', '--ask=4', *packages) != 0: - error('update failed due to unsuccessful package downloads') - sys.exit(50) + counter = 0 + while True: + return_val = exec_chroot('pacman', '-S', '--ask=4', *packages) + counter += 1 + if counter > 30: + error('failed to download packages') + exit(50) + if return_val == 0: + break if type(blend_release.get('commands')) == list: for command in blend_release.get('commands'): From 68e3cb67a4678436e1210f8e26d3cba1077f5ec0 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Mon, 20 Nov 2023 13:51:49 +0530 Subject: [PATCH 070/135] chore: handle /etc/systemd/system as well --- akshara.hook | 3 +++ 1 file changed, 3 insertions(+) diff --git a/akshara.hook b/akshara.hook index 9b1ef2c..6cd9f30 100755 --- a/akshara.hook +++ b/akshara.hook @@ -37,6 +37,9 @@ run_latehook() { mv /new_root/etc /new_root/.old.etc || : mv /new_root/.new_etc /new_root/etc + mv /new_root/etc/systemd/system /new_root/.old.etc.systemd.system + mv /new_root/.update_rootfs/etc/systemd/system /new_root/etc/systemd + # Successful update. rm -f /new_root/.etc-stage From 2fc74367c9a19e4554ed0c7bad7406f93f25c4c9 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Mon, 20 Nov 2023 15:25:28 +0530 Subject: [PATCH 071/135] fix: handle services during updates --- akshara | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/akshara b/akshara index 0ab558a..f03ac48 100755 --- a/akshara +++ b/akshara @@ -179,13 +179,18 @@ def update_system(): exec('rm', '-f', '/.new_rootfs/version') packages = [ - 'akshara' + 'akshara', + 'blend' ] services = [ 'akshara' ] + user_services = [ + 'blend-files' + ] + if (type(blend_release.get('impl')) == str and type(blend_release.get('track')) != 'custom'): res = interpret_track(blend_release) @@ -261,6 +266,14 @@ Server = {package_repo["repo-url"]} if return_val == 0: break + for service in services: + if type(service) is str: + exec_chroot('systemctl', 'enable', service) + + for user_service in user_services: + if type(user_service) is str: + exec_chroot('systemctl', 'enable', '--global', user_service) + if type(blend_release.get('commands')) == list: for command in blend_release.get('commands'): if type(command) == str: @@ -284,17 +297,17 @@ Server = {package_repo["repo-url"]} new_boot_files = [] - # for f in os.listdir('/.update_rootfs/boot'): - # if not os.path.isdir(f'/.update_rootfs/boot/{f}'): - # exec('mv', f'/.update_rootfs/boot/{f}', '/boot') - # new_boot_files.append(f) + for f in os.listdir('/.update_rootfs/boot'): + if not os.path.isdir(f'/.update_rootfs/boot/{f}'): + exec('mv', f'/.update_rootfs/boot/{f}', '/boot') + new_boot_files.append(f) - # for f in os.listdir('/boot'): - # if not os.path.isdir(f'/boot/{f}'): - # if f not in new_boot_files: - # exec('rm', '-f', f'/boot/{f}') + for f in os.listdir('/boot'): + if not os.path.isdir(f'/boot/{f}'): + if f not in new_boot_files: + exec('rm', '-f', f'/boot/{f}') - # exec('grub-mkconfig', '-o', '/boot/grub/grub.cfg') + exec('grub-mkconfig', '-o', '/boot/grub/grub.cfg') info('downloaded update and generated new rootfs') info('you may reboot now') From 70ad8b5df745c4a086120748efa6df3209cf715b Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Mon, 20 Nov 2023 16:59:57 +0530 Subject: [PATCH 072/135] fix: handle missing /system.yaml lists better --- akshara | 2 ++ 1 file changed, 2 insertions(+) diff --git a/akshara b/akshara index f03ac48..1d9d3c1 100755 --- a/akshara +++ b/akshara @@ -199,6 +199,8 @@ def update_system(): if type(res[i]) is list: if type(blend_release.get(i)) is list: blend_release[i] += res[i] + else: + blend_release[i] = res[i] if type(blend_release.get('packages')) == list: packages += blend_release.get('packages') From 63e20638cfdb6441ac4295056eff4c39f41abcd8 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Mon, 20 Nov 2023 18:37:35 +0530 Subject: [PATCH 073/135] fix: remove no longer existent /etc files from the right dir --- akshara | 2 ++ akshara.hook | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/akshara b/akshara index 1d9d3c1..91e105e 100755 --- a/akshara +++ b/akshara @@ -258,6 +258,8 @@ Server = {package_repo["repo-url"]} if return_val == 0: break + exec('cp', '/etc/mkinitcpio.conf', '/.new_rootfs/etc/mkinitcpio.conf') + counter = 0 while True: return_val = exec_chroot('pacman', '-S', '--ask=4', *packages) diff --git a/akshara.hook b/akshara.hook index 6cd9f30..294441f 100755 --- a/akshara.hook +++ b/akshara.hook @@ -29,7 +29,8 @@ run_latehook() { # Create new /etc. rm -rf /new_root/.new_etc cp -a /new_root/etc /new_root/.new_etc - (cd /new_root/etc && find . -type f -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type f) | xargs -0 rm -rf) + (cd /new_root/.new_etc && find . -type f -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type f) | xargs -0 rm -f) + (cd /new_root/.new_etc && find . -type l -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type l) | xargs -0 rm -f) cp /new_root/.update_rootfs/etc/pacman.conf /new_root/.new_etc/pacman.conf rm -rf /new_root/.new_etc/pacman.d cp -a /new_root/.update_rootfs/etc/pacman.d /new_root/.new_etc/pacman.d From 5d28f203cf756df55316755455ea613e4fa9b8b0 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Mon, 20 Nov 2023 20:12:51 +0530 Subject: [PATCH 074/135] feat: use reflector --- akshara | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/akshara b/akshara index 91e105e..3ab4ab2 100755 --- a/akshara +++ b/akshara @@ -213,9 +213,33 @@ def update_system(): print(blend_release) + exec_chroot('cp', '/.new_rootfs/etc/pacman.d/mirrorlist', '/.new_rootfs/etc/pacman.d/mirrorlist.bkp') + with open('/.new_rootfs/etc/pacman.d/mirrorlist', 'w') as pacman_mirrorlist_conf: pacman_mirrorlist_conf.write('Server = https://cloudflaremirrors.com/archlinux/$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') + + # update packages + exec_chroot('pacman-key', '--init') + exec_chroot('pacman-key', '--populate') + + counter = 0 + while True: + return_val = exec_chroot('pacman', '-Sy', '--ask=4', 'reflector') + counter += 1 + if counter > 30: + error('failed to download packages') + exit(50) + if return_val == 0: + break + + exec_chroot('mv', '/.new_rootfs/etc/pacman.d/mirrorlist.bkp', '/.new_rootfs/etc/pacman.d/mirrorlist') + + exec_chroot('reflector', '--latest', '20', '--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') @@ -239,15 +263,6 @@ SigLevel = Never Server = {package_repo["repo-url"]} ''') - - 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') - - # update packages - exec_chroot('pacman-key', '--init') - exec_chroot('pacman-key', '--populate') - counter = 0 while True: return_val = exec_chroot('pacman', '-Syu', '--noconfirm') From 952bcd738c7b5aee51bca4624adb37da7bf38b5f Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Mon, 20 Nov 2023 20:32:14 +0530 Subject: [PATCH 075/135] fix: overwrite pacman mirrorlist directly --- akshara | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/akshara b/akshara index 3ab4ab2..b79414f 100755 --- a/akshara +++ b/akshara @@ -213,8 +213,6 @@ def update_system(): print(blend_release) - exec_chroot('cp', '/.new_rootfs/etc/pacman.d/mirrorlist', '/.new_rootfs/etc/pacman.d/mirrorlist.bkp') - with open('/.new_rootfs/etc/pacman.d/mirrorlist', 'w') as pacman_mirrorlist_conf: pacman_mirrorlist_conf.write('Server = https://cloudflaremirrors.com/archlinux/$repo/os/$arch\n') @@ -236,9 +234,7 @@ def update_system(): if return_val == 0: break - exec_chroot('mv', '/.new_rootfs/etc/pacman.d/mirrorlist.bkp', '/.new_rootfs/etc/pacman.d/mirrorlist') - - exec_chroot('reflector', '--latest', '20', '--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') From 3d28788708dd67a0c772b42c72fad5127f70330c Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Mon, 20 Nov 2023 20:54:02 +0530 Subject: [PATCH 076/135] fix: add akshara as init hook --- akshara | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/akshara b/akshara index b79414f..eae61e2 100755 --- a/akshara +++ b/akshara @@ -308,6 +308,13 @@ Server = {package_repo["repo-url"]} error('cancelling update so as not to render the system unbootable') sys.exit(10) + exec_chroot('bash', '-c', 'echo "MODULES=()" > /etc/mkinitcpio.conf') + exec_chroot('bash', '-c', 'echo "BINARIES=()" >> /etc/mkinitcpio.conf') + exec_chroot('bash', '-c', 'echo "FILES=()" >> /etc/mkinitcpio.conf') + exec_chroot('bash', '-c', 'echo "HOOKS=(base udev akshara autodetect keyboard keymap modconf block encrypt filesystems fsck)" >> /etc/mkinitcpio.conf') + + exec_chroot('mkinitcpio', '-P') + exec('mv', '.new_rootfs', '.update_rootfs') new_boot_files = [] From b3c2cf919240767805c33ffd54c1ca72d0f26d16 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Mon, 20 Nov 2023 21:02:22 +0530 Subject: [PATCH 077/135] fix: remove encrypt init hook --- akshara | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara b/akshara index eae61e2..12ea79f 100755 --- a/akshara +++ b/akshara @@ -311,7 +311,7 @@ Server = {package_repo["repo-url"]} exec_chroot('bash', '-c', 'echo "MODULES=()" > /etc/mkinitcpio.conf') exec_chroot('bash', '-c', 'echo "BINARIES=()" >> /etc/mkinitcpio.conf') exec_chroot('bash', '-c', 'echo "FILES=()" >> /etc/mkinitcpio.conf') - exec_chroot('bash', '-c', 'echo "HOOKS=(base udev akshara autodetect keyboard keymap modconf block encrypt filesystems fsck)" >> /etc/mkinitcpio.conf') + exec_chroot('bash', '-c', 'echo "HOOKS=(base udev akshara autodetect keyboard keymap modconf block filesystems fsck)" >> /etc/mkinitcpio.conf') exec_chroot('mkinitcpio', '-P') From 249c91693c041ee0f2112509d0f7237875fd7354 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Mon, 20 Nov 2023 22:11:33 +0530 Subject: [PATCH 078/135] feat: handle directories under /var/lib too --- akshara.hook | 1 + 1 file changed, 1 insertion(+) diff --git a/akshara.hook b/akshara.hook index 294441f..987939f 100755 --- a/akshara.hook +++ b/akshara.hook @@ -31,6 +31,7 @@ run_latehook() { cp -a /new_root/etc /new_root/.new_etc (cd /new_root/.new_etc && find . -type f -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type f) | xargs -0 rm -f) (cd /new_root/.new_etc && find . -type l -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type l) | xargs -0 rm -f) + (cd /new_root/var/lib && find . -maxdepth 1 -type d -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/var/lib" && find . -maxdepth 1 -type d) | xargs -0 rm -rf) cp /new_root/.update_rootfs/etc/pacman.conf /new_root/.new_etc/pacman.conf rm -rf /new_root/.new_etc/pacman.d cp -a /new_root/.update_rootfs/etc/pacman.d /new_root/.new_etc/pacman.d From f42afc571eda6b12451cb2cfe3241440e82070d0 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Tue, 21 Nov 2023 15:43:21 +0530 Subject: [PATCH 079/135] feat: handle /var/lib better --- akshara.hook | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/akshara.hook b/akshara.hook index 987939f..5104ee6 100755 --- a/akshara.hook +++ b/akshara.hook @@ -31,7 +31,8 @@ run_latehook() { cp -a /new_root/etc /new_root/.new_etc (cd /new_root/.new_etc && find . -type f -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type f) | xargs -0 rm -f) (cd /new_root/.new_etc && find . -type l -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type l) | xargs -0 rm -f) - (cd /new_root/var/lib && find . -maxdepth 1 -type d -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/var/lib" && find . -maxdepth 1 -type d) | xargs -0 rm -rf) + (cd /new_root/var/lib && find . -maxdepth 1 -type d -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/var/lib" && find . -maxdepth 1 -type d) | xargs -0 -n 2 rm -rf)/ + (cd /new_root/.update_rootfs/var/lib && find . -maxdepth 1 -type d -print0 | grep -Fxvz -f <(cd "/new_root/var/lib" && find . -maxdepth 1 -type d) | xargs -0 -n 2 sh -c 'cp -r "$@" /new_root/var/lib' sh) cp /new_root/.update_rootfs/etc/pacman.conf /new_root/.new_etc/pacman.conf rm -rf /new_root/.new_etc/pacman.d cp -a /new_root/.update_rootfs/etc/pacman.d /new_root/.new_etc/pacman.d From 1323bb68f739878ee74b0229d11df9524bf61a67 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Tue, 21 Nov 2023 15:59:47 +0530 Subject: [PATCH 080/135] feat: make /var/lib operations atomic --- akshara.hook | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/akshara.hook b/akshara.hook index 5104ee6..20f4acb 100755 --- a/akshara.hook +++ b/akshara.hook @@ -31,8 +31,9 @@ run_latehook() { cp -a /new_root/etc /new_root/.new_etc (cd /new_root/.new_etc && find . -type f -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type f) | xargs -0 rm -f) (cd /new_root/.new_etc && find . -type l -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type l) | xargs -0 rm -f) - (cd /new_root/var/lib && find . -maxdepth 1 -type d -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/var/lib" && find . -maxdepth 1 -type d) | xargs -0 -n 2 rm -rf)/ - (cd /new_root/.update_rootfs/var/lib && find . -maxdepth 1 -type d -print0 | grep -Fxvz -f <(cd "/new_root/var/lib" && find . -maxdepth 1 -type d) | xargs -0 -n 2 sh -c 'cp -r "$@" /new_root/var/lib' sh) + mkdir /.old.varlib + (cd /new_root/var/lib && find . -maxdepth 1 -type d -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/var/lib" && find . -maxdepth 1 -type d) | xargs -0 sh -c 'mv "$@" /new_root/.old.varlib' sh) + (cd /new_root/.update_rootfs/var/lib && find . -maxdepth 1 -type d -print0 | grep -Fxvz -f <(cd "/new_root/var/lib" && find . -maxdepth 1 -type d) | xargs -0 sh -c 'mv "$@" /new_root/var/lib' sh) cp /new_root/.update_rootfs/etc/pacman.conf /new_root/.new_etc/pacman.conf rm -rf /new_root/.new_etc/pacman.d cp -a /new_root/.update_rootfs/etc/pacman.d /new_root/.new_etc/pacman.d From 996084e146eb663d51d79fccd585266d0969b797 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Wed, 22 Nov 2023 09:41:37 +0530 Subject: [PATCH 081/135] feat: do not spontaneously delete /var/lib/pacman --- akshara.hook | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/akshara.hook b/akshara.hook index 20f4acb..7c266de 100755 --- a/akshara.hook +++ b/akshara.hook @@ -31,8 +31,8 @@ run_latehook() { cp -a /new_root/etc /new_root/.new_etc (cd /new_root/.new_etc && find . -type f -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type f) | xargs -0 rm -f) (cd /new_root/.new_etc && find . -type l -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type l) | xargs -0 rm -f) - mkdir /.old.varlib - (cd /new_root/var/lib && find . -maxdepth 1 -type d -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/var/lib" && find . -maxdepth 1 -type d) | xargs -0 sh -c 'mv "$@" /new_root/.old.varlib' sh) + mkdir -p /.old.varlib + (cd /new_root/var/lib && find . -maxdepth 1 -type d -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/var/lib" && find . -maxdepth 1 -type d) | grep -Fxvz './pacman' | xargs -0 sh -c 'mv "$@" /new_root/.old.varlib' sh) (cd /new_root/.update_rootfs/var/lib && find . -maxdepth 1 -type d -print0 | grep -Fxvz -f <(cd "/new_root/var/lib" && find . -maxdepth 1 -type d) | xargs -0 sh -c 'mv "$@" /new_root/var/lib' sh) cp /new_root/.update_rootfs/etc/pacman.conf /new_root/.new_etc/pacman.conf rm -rf /new_root/.new_etc/pacman.d From 0976e092b54481965cee9da69d97d773b4be3327 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Wed, 22 Nov 2023 13:16:14 +0530 Subject: [PATCH 082/135] feat: handle files in /etc better --- akshara.hook | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/akshara.hook b/akshara.hook index 7c266de..85a45c4 100755 --- a/akshara.hook +++ b/akshara.hook @@ -28,16 +28,15 @@ run_latehook() { if [[ -f /new_root/.etc-stage ]]; then # Create new /etc. rm -rf /new_root/.new_etc - cp -a /new_root/etc /new_root/.new_etc (cd /new_root/.new_etc && find . -type f -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type f) | xargs -0 rm -f) (cd /new_root/.new_etc && find . -type l -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type l) | xargs -0 rm -f) mkdir -p /.old.varlib (cd /new_root/var/lib && find . -maxdepth 1 -type d -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/var/lib" && find . -maxdepth 1 -type d) | grep -Fxvz './pacman' | xargs -0 sh -c 'mv "$@" /new_root/.old.varlib' sh) - (cd /new_root/.update_rootfs/var/lib && find . -maxdepth 1 -type d -print0 | grep -Fxvz -f <(cd "/new_root/var/lib" && find . -maxdepth 1 -type d) | xargs -0 sh -c 'mv "$@" /new_root/var/lib' sh) + (cd /new_root/.update_rootfs/var/lib && find . -maxdepth 1 -type d -print0 | grep -Fxvz -f <(cd "/new_root/var/lib" && find . -maxdepth 1 -type d) | xargs -0 sh -c 'cp -r "$@" /new_root/var/lib' sh) cp /new_root/.update_rootfs/etc/pacman.conf /new_root/.new_etc/pacman.conf rm -rf /new_root/.new_etc/pacman.d cp -a /new_root/.update_rootfs/etc/pacman.d /new_root/.new_etc/pacman.d - cp -an /new_root/.update_rootfs/etc/* /new_root/.new_etc + (cd /new_root/.update_rootfs/etc && find . -type f -print0 | grep -Fxvz -f <(cd "/new_root/.new_etc" && find . -type f -print0) | xargs -0 sh -c 'cp "$@" /new_root/.new_etc' sh) mv /new_root/etc /new_root/.old.etc || : mv /new_root/.new_etc /new_root/etc From 8238f67f798db34f14694dccae1c3cd4d4a07b6f Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Wed, 22 Nov 2023 13:30:36 +0530 Subject: [PATCH 083/135] fix: copy over /etc files correctly --- akshara.hook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara.hook b/akshara.hook index 85a45c4..08342c7 100755 --- a/akshara.hook +++ b/akshara.hook @@ -36,7 +36,7 @@ run_latehook() { cp /new_root/.update_rootfs/etc/pacman.conf /new_root/.new_etc/pacman.conf rm -rf /new_root/.new_etc/pacman.d cp -a /new_root/.update_rootfs/etc/pacman.d /new_root/.new_etc/pacman.d - (cd /new_root/.update_rootfs/etc && find . -type f -print0 | grep -Fxvz -f <(cd "/new_root/.new_etc" && find . -type f -print0) | xargs -0 sh -c 'cp "$@" /new_root/.new_etc' sh) + (cd /new_root/.update_rootfs/etc && find . -type f -print0 | grep -Fxvz -f <(cd "/new_root/.new_etc" && find . -type f -print0) | xargs -n 1 -0 sh -c 'mkdir -p "/new_root/.new_etc/$(dirname "$1")"; cp "$1" /new_root/.new_etc/$(dirname "$1")' sh) mv /new_root/etc /new_root/.old.etc || : mv /new_root/.new_etc /new_root/etc From bd688e01b99bb66e166bf0f17caf255c694a68fb Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Wed, 22 Nov 2023 15:49:41 +0530 Subject: [PATCH 084/135] fix: create .new_etc first --- akshara.hook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara.hook b/akshara.hook index 08342c7..8d0459c 100755 --- a/akshara.hook +++ b/akshara.hook @@ -27,7 +27,7 @@ run_latehook() { # Detect if /etc stage is active. if [[ -f /new_root/.etc-stage ]]; then # Create new /etc. - rm -rf /new_root/.new_etc + rm -rf /new_root/.new_etc; cp -r /new_root/etc /new_root/.new_etc (cd /new_root/.new_etc && find . -type f -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type f) | xargs -0 rm -f) (cd /new_root/.new_etc && find . -type l -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type l) | xargs -0 rm -f) mkdir -p /.old.varlib From 4f7426ace8fa7e70c936eb6f47c81691a96ac9ff Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Wed, 22 Nov 2023 17:02:19 +0530 Subject: [PATCH 085/135] fix: -a instead of -r --- akshara.hook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara.hook b/akshara.hook index 8d0459c..92ee79b 100755 --- a/akshara.hook +++ b/akshara.hook @@ -27,7 +27,7 @@ run_latehook() { # Detect if /etc stage is active. if [[ -f /new_root/.etc-stage ]]; then # Create new /etc. - rm -rf /new_root/.new_etc; cp -r /new_root/etc /new_root/.new_etc + rm -rf /new_root/.new_etc; cp -a /new_root/etc /new_root/.new_etc (cd /new_root/.new_etc && find . -type f -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type f) | xargs -0 rm -f) (cd /new_root/.new_etc && find . -type l -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type l) | xargs -0 rm -f) mkdir -p /.old.varlib From bb7e9f2aafbffe62fc4e39e5762349d7ddd7564f Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Wed, 22 Nov 2023 19:27:30 +0530 Subject: [PATCH 086/135] fix: temporarily use newlines instead of zeroes --- akshara.hook | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/akshara.hook b/akshara.hook index 92ee79b..2c23ac5 100755 --- a/akshara.hook +++ b/akshara.hook @@ -28,15 +28,15 @@ run_latehook() { if [[ -f /new_root/.etc-stage ]]; then # Create new /etc. rm -rf /new_root/.new_etc; cp -a /new_root/etc /new_root/.new_etc - (cd /new_root/.new_etc && find . -type f -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type f) | xargs -0 rm -f) - (cd /new_root/.new_etc && find . -type l -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type l) | xargs -0 rm -f) + (cd /new_root/.new_etc && find . -type f | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type f) | xargs rm -f) + (cd /new_root/.new_etc && find . -type l | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type l) | xargs rm -f) mkdir -p /.old.varlib - (cd /new_root/var/lib && find . -maxdepth 1 -type d -print0 | grep -Fxvz -f <(cd "/new_root/.update_rootfs/var/lib" && find . -maxdepth 1 -type d) | grep -Fxvz './pacman' | xargs -0 sh -c 'mv "$@" /new_root/.old.varlib' sh) - (cd /new_root/.update_rootfs/var/lib && find . -maxdepth 1 -type d -print0 | grep -Fxvz -f <(cd "/new_root/var/lib" && find . -maxdepth 1 -type d) | xargs -0 sh -c 'cp -r "$@" /new_root/var/lib' sh) + (cd /new_root/var/lib && find . -maxdepth 1 -type d | grep -Fxvz -f <(cd "/new_root/.update_rootfs/var/lib" && find . -maxdepth 1 -type d) | grep -Fxvz './pacman' | xargs sh -c 'mv "$@" /new_root/.old.varlib' sh) + (cd /new_root/.update_rootfs/var/lib && find . -maxdepth 1 -type d | grep -Fxvz -f <(cd "/new_root/var/lib" && find . -maxdepth 1 -type d) | xargs sh -c 'cp -r "$@" /new_root/var/lib' sh) cp /new_root/.update_rootfs/etc/pacman.conf /new_root/.new_etc/pacman.conf rm -rf /new_root/.new_etc/pacman.d cp -a /new_root/.update_rootfs/etc/pacman.d /new_root/.new_etc/pacman.d - (cd /new_root/.update_rootfs/etc && find . -type f -print0 | grep -Fxvz -f <(cd "/new_root/.new_etc" && find . -type f -print0) | xargs -n 1 -0 sh -c 'mkdir -p "/new_root/.new_etc/$(dirname "$1")"; cp "$1" /new_root/.new_etc/$(dirname "$1")' sh) + (cd /new_root/.update_rootfs/etc && find . -type f | grep -Fxvz -f <(cd "/new_root/.new_etc" && find . -type f) | xargs -n 1 sh -c 'mkdir -p "/new_root/.new_etc/$(dirname "$1")"; cp -a "$1" /new_root/.new_etc/$(dirname "$1")' sh) mv /new_root/etc /new_root/.old.etc || : mv /new_root/.new_etc /new_root/etc From bcec9dcef91382b8fa7ede0354d6bc7a3e43a6c9 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Wed, 22 Nov 2023 20:27:59 +0530 Subject: [PATCH 087/135] fix: complete switch to newlines --- akshara.hook | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/akshara.hook b/akshara.hook index 2c23ac5..23e0b05 100755 --- a/akshara.hook +++ b/akshara.hook @@ -28,15 +28,15 @@ run_latehook() { if [[ -f /new_root/.etc-stage ]]; then # Create new /etc. rm -rf /new_root/.new_etc; cp -a /new_root/etc /new_root/.new_etc - (cd /new_root/.new_etc && find . -type f | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type f) | xargs rm -f) - (cd /new_root/.new_etc && find . -type l | grep -Fxvz -f <(cd "/new_root/.update_rootfs/etc" && find . -type l) | xargs rm -f) + (cd /new_root/.new_etc && find . -type f | grep -Fxv -f <(cd "/new_root/.update_rootfs/etc" && find . -type f) | xargs rm -f) + (cd /new_root/.new_etc && find . -type l | grep -Fxv -f <(cd "/new_root/.update_rootfs/etc" && find . -type l) | xargs rm -f) mkdir -p /.old.varlib - (cd /new_root/var/lib && find . -maxdepth 1 -type d | grep -Fxvz -f <(cd "/new_root/.update_rootfs/var/lib" && find . -maxdepth 1 -type d) | grep -Fxvz './pacman' | xargs sh -c 'mv "$@" /new_root/.old.varlib' sh) - (cd /new_root/.update_rootfs/var/lib && find . -maxdepth 1 -type d | grep -Fxvz -f <(cd "/new_root/var/lib" && find . -maxdepth 1 -type d) | xargs sh -c 'cp -r "$@" /new_root/var/lib' sh) + (cd /new_root/var/lib && find . -maxdepth 1 -type d | grep -Fxv -f <(cd "/new_root/.update_rootfs/var/lib" && find . -maxdepth 1 -type d) | grep -Fxv './pacman' | xargs sh -c 'mv "$@" /new_root/.old.varlib' sh) + (cd /new_root/.update_rootfs/var/lib && find . -maxdepth 1 -type d | grep -Fxv -f <(cd "/new_root/var/lib" && find . -maxdepth 1 -type d) | xargs sh -c 'cp -r "$@" /new_root/var/lib' sh) cp /new_root/.update_rootfs/etc/pacman.conf /new_root/.new_etc/pacman.conf rm -rf /new_root/.new_etc/pacman.d cp -a /new_root/.update_rootfs/etc/pacman.d /new_root/.new_etc/pacman.d - (cd /new_root/.update_rootfs/etc && find . -type f | grep -Fxvz -f <(cd "/new_root/.new_etc" && find . -type f) | xargs -n 1 sh -c 'mkdir -p "/new_root/.new_etc/$(dirname "$1")"; cp -a "$1" /new_root/.new_etc/$(dirname "$1")' sh) + (cd /new_root/.update_rootfs/etc && find . -type f | grep -Fxv -f <(cd "/new_root/.new_etc" && find . -type f) | xargs -n 1 sh -c 'mkdir -p "/new_root/.new_etc/$(dirname "$1")"; cp -a "$1" /new_root/.new_etc/$(dirname "$1")' sh) mv /new_root/etc /new_root/.old.etc || : mv /new_root/.new_etc /new_root/etc From 6ee3a53ea210a3c459a1975613edea37a229968c Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Fri, 24 Nov 2023 08:57:15 +0530 Subject: [PATCH 088/135] chore: add arch-install-scripts as dep --- PKGBUILD | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index 1eb3194..1ec79f5 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,8 +1,8 @@ # Maintainer: Rudra Saraswat pkgname='akshara-git' -pkgver=r33.e380b80 -pkgrel=2 +pkgver=r59.9f2f25b +pkgrel=1 pkgdesc="An update system for operating systems" arch=('x86_64' 'i686') url="https://github.com/blend-os/blend" @@ -11,7 +11,7 @@ makedepends=('git' 'base-devel') source=('git+https://git.blendos.co/blendOS/system-tools/akshara') sha256sums=('SKIP') -depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'python-fasteners' 'python-yaml' 'squashfs-tools' 'wget' 'python-requests') +depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'python-fasteners' 'python-yaml' 'squashfs-tools' 'wget' 'python-requests' 'arch-install-scripts') provides=("${pkgname%-git}") conflicts=("${pkgname%-git}") From c2004b74222912c5ca26636a62020d1647b191e5 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Fri, 24 Nov 2023 09:06:31 +0530 Subject: [PATCH 089/135] chore: try using arch-chroot instead of systemd-nspawn --- akshara | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara b/akshara index 12ea79f..3dfceaf 100755 --- a/akshara +++ b/akshara @@ -79,7 +79,7 @@ def exec(*cmd, **kwargs): def exec_chroot(*cmd, **kwargs): - return exec('systemd-nspawn', '-D', '/.new_rootfs', '--', *cmd, **kwargs) + return exec('arch-chroot', '/.new_rootfs', *cmd, **kwargs) fg = colors.fg() From 375ccc84b3f9d54a01aa0172ccf16fedf5f6b210 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Fri, 24 Nov 2023 09:26:40 +0530 Subject: [PATCH 090/135] chore: bind mount before arch-chroot --- akshara | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/akshara b/akshara index 3dfceaf..7c46b15 100755 --- a/akshara +++ b/akshara @@ -79,7 +79,10 @@ def exec(*cmd, **kwargs): def exec_chroot(*cmd, **kwargs): - return exec('arch-chroot', '/.new_rootfs', *cmd, **kwargs) + exec('mount', '--bind', '/.new_rootfs', '/.new_rootfs') + ret = exec('arch-chroot', '/.new_rootfs', *cmd, **kwargs) + exec('umount', '-l', '/.new_rootfs') + return ret fg = colors.fg() From 98f56a7bd7ac42cdf46b6b28b5c4e3259188ef37 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Fri, 24 Nov 2023 10:36:33 +0530 Subject: [PATCH 091/135] chore: explicitly reinstall shadow --- akshara | 2 ++ 1 file changed, 2 insertions(+) diff --git a/akshara b/akshara index 7c46b15..268f70e 100755 --- a/akshara +++ b/akshara @@ -316,6 +316,8 @@ Server = {package_repo["repo-url"]} exec_chroot('bash', '-c', 'echo "FILES=()" >> /etc/mkinitcpio.conf') exec_chroot('bash', '-c', 'echo "HOOKS=(base udev akshara autodetect keyboard keymap modconf block filesystems fsck)" >> /etc/mkinitcpio.conf') + exec_chroot('pacman', '-S', 'shadow') + exec_chroot('mkinitcpio', '-P') exec('mv', '.new_rootfs', '.update_rootfs') From d2e30d77f968d6ecb54ea88f8c9f27c4412df289 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Fri, 24 Nov 2023 12:26:42 +0530 Subject: [PATCH 092/135] chore: --noconfirm --- akshara | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/akshara b/akshara index 268f70e..18b2efb 100755 --- a/akshara +++ b/akshara @@ -126,6 +126,7 @@ def update_system(): os.chdir('/') if os.path.isdir('/.new_rootfs'): + # add code here to unmount any directories under the new rootfs dir exec('rm', '-rf', '/.new_rootfs') # Check if update is available @@ -316,7 +317,7 @@ Server = {package_repo["repo-url"]} exec_chroot('bash', '-c', 'echo "FILES=()" >> /etc/mkinitcpio.conf') exec_chroot('bash', '-c', 'echo "HOOKS=(base udev akshara autodetect keyboard keymap modconf block filesystems fsck)" >> /etc/mkinitcpio.conf') - exec_chroot('pacman', '-S', 'shadow') + exec_chroot('pacman', '-S', '--nonconfirm', 'shadow') exec_chroot('mkinitcpio', '-P') From e3503e5e9f9e7952c366698086a1039db5ce5ef4 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Fri, 24 Nov 2023 12:26:56 +0530 Subject: [PATCH 093/135] fix: typo --- akshara | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara b/akshara index 18b2efb..0a108c0 100755 --- a/akshara +++ b/akshara @@ -317,7 +317,7 @@ Server = {package_repo["repo-url"]} exec_chroot('bash', '-c', 'echo "FILES=()" >> /etc/mkinitcpio.conf') exec_chroot('bash', '-c', 'echo "HOOKS=(base udev akshara autodetect keyboard keymap modconf block filesystems fsck)" >> /etc/mkinitcpio.conf') - exec_chroot('pacman', '-S', '--nonconfirm', 'shadow') + exec_chroot('pacman', '-S', '--noconfirm', 'shadow') exec_chroot('mkinitcpio', '-P') From 82c765a562a8365e16ebf547db77cd13bef38f17 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Fri, 24 Nov 2023 12:31:09 +0530 Subject: [PATCH 094/135] feat: handle links as well --- akshara.hook | 1 + 1 file changed, 1 insertion(+) diff --git a/akshara.hook b/akshara.hook index 23e0b05..8730352 100755 --- a/akshara.hook +++ b/akshara.hook @@ -37,6 +37,7 @@ run_latehook() { rm -rf /new_root/.new_etc/pacman.d cp -a /new_root/.update_rootfs/etc/pacman.d /new_root/.new_etc/pacman.d (cd /new_root/.update_rootfs/etc && find . -type f | grep -Fxv -f <(cd "/new_root/.new_etc" && find . -type f) | xargs -n 1 sh -c 'mkdir -p "/new_root/.new_etc/$(dirname "$1")"; cp -a "$1" /new_root/.new_etc/$(dirname "$1")' sh) + (cd /new_root/.update_rootfs/etc && find . -type l | grep -Fxv -f <(cd "/new_root/.new_etc" && find . -type l) | xargs -n 1 sh -c 'mkdir -p "/new_root/.new_etc/$(dirname "$1")"; cp -a "$1" /new_root/.new_etc/$(dirname "$1")' sh) mv /new_root/etc /new_root/.old.etc || : mv /new_root/.new_etc /new_root/etc From 1602ae3dd64a6224eeaad0111f1beb9f2d34d25c Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Fri, 24 Nov 2023 13:46:14 +0530 Subject: [PATCH 095/135] chore: keep localtime --- akshara.hook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara.hook b/akshara.hook index 8730352..820a702 100755 --- a/akshara.hook +++ b/akshara.hook @@ -29,7 +29,7 @@ run_latehook() { # Create new /etc. rm -rf /new_root/.new_etc; cp -a /new_root/etc /new_root/.new_etc (cd /new_root/.new_etc && find . -type f | grep -Fxv -f <(cd "/new_root/.update_rootfs/etc" && find . -type f) | xargs rm -f) - (cd /new_root/.new_etc && find . -type l | grep -Fxv -f <(cd "/new_root/.update_rootfs/etc" && find . -type l) | xargs rm -f) + (cd /new_root/.new_etc && find . -type l | grep -Fxv -f <(cd "/new_root/.update_rootfs/etc" && find . -type l) | grep -Fxv './localtime' | xargs rm -f) mkdir -p /.old.varlib (cd /new_root/var/lib && find . -maxdepth 1 -type d | grep -Fxv -f <(cd "/new_root/.update_rootfs/var/lib" && find . -maxdepth 1 -type d) | grep -Fxv './pacman' | xargs sh -c 'mv "$@" /new_root/.old.varlib' sh) (cd /new_root/.update_rootfs/var/lib && find . -maxdepth 1 -type d | grep -Fxv -f <(cd "/new_root/var/lib" && find . -maxdepth 1 -type d) | xargs sh -c 'cp -r "$@" /new_root/var/lib' sh) From 441115374ac9eebc90bf83d8b287b850b760e1b2 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Fri, 24 Nov 2023 14:12:33 +0530 Subject: [PATCH 096/135] chore: carry over sudoers.d --- akshara.hook | 2 ++ 1 file changed, 2 insertions(+) diff --git a/akshara.hook b/akshara.hook index 820a702..3d40749 100755 --- a/akshara.hook +++ b/akshara.hook @@ -36,6 +36,8 @@ run_latehook() { cp /new_root/.update_rootfs/etc/pacman.conf /new_root/.new_etc/pacman.conf rm -rf /new_root/.new_etc/pacman.d cp -a /new_root/.update_rootfs/etc/pacman.d /new_root/.new_etc/pacman.d + rm -rf /new_root/.new_etc/sudoers.d + cp -a /new_root/etc/sudoers.d /new_root/.new_etc (cd /new_root/.update_rootfs/etc && find . -type f | grep -Fxv -f <(cd "/new_root/.new_etc" && find . -type f) | xargs -n 1 sh -c 'mkdir -p "/new_root/.new_etc/$(dirname "$1")"; cp -a "$1" /new_root/.new_etc/$(dirname "$1")' sh) (cd /new_root/.update_rootfs/etc && find . -type l | grep -Fxv -f <(cd "/new_root/.new_etc" && find . -type l) | xargs -n 1 sh -c 'mkdir -p "/new_root/.new_etc/$(dirname "$1")"; cp -a "$1" /new_root/.new_etc/$(dirname "$1")' sh) mv /new_root/etc /new_root/.old.etc || : From 87f2e9198ada6fd427f982953e25272d63ed3530 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Fri, 24 Nov 2023 23:20:05 +0530 Subject: [PATCH 097/135] feat: make akshara immutable --- akshara.hook | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/akshara.hook b/akshara.hook index 3d40749..400c258 100755 --- a/akshara.hook +++ b/akshara.hook @@ -52,4 +52,14 @@ run_latehook() { mv /new_root/.update_rootfs /new_root/.old.update_rootfs touch /new_root/.successful-update fi + + rm -rf /new_root/.blend-overlays/usr.workdir /new_root/.blend-overlays/varlibpacman.workdir + + for i in usr varlibpacman; do + mkdir -p /new_root/.blend-overlays/$i + mkdir -p /new_root/.blend-overlays/$i.workdir + done + + mount -t overlay overlay -o index=off -o metacopy=off -o ro,lowerdir=/new_root/usr,upperdir=/new_root/.blend-overlays/usr,workdir=/new_root/.blend-overlays/usr.workdir /new_root/usr + mount -t overlay overlay -o index=off -o metacopy=off -o ro,lowerdir=/new_root/var/lib/pacman,upperdir=/new_root/.blend-overlays/varlibpacman,workdir=/new_root/.blend-overlays/varlibpacman.workdir /new_root/var/lib/pacman } From e8f137834818313dc4e632b15f5772358c3328a7 Mon Sep 17 00:00:00 2001 From: Veggie Tanuki Date: Sat, 30 Dec 2023 16:14:59 +0000 Subject: [PATCH 098/135] feat: add aur package support to system.yaml --- akshara | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/akshara b/akshara index 0a108c0..0a2f412 100755 --- a/akshara +++ b/akshara @@ -187,6 +187,8 @@ def update_system(): 'blend' ] + aur_packages = [] + services = [ 'akshara' ] @@ -209,6 +211,10 @@ def update_system(): if type(blend_release.get('packages')) == list: packages += blend_release.get('packages') + if type(blend_release.get('aur-packages')) == list: + packages += ['fakeroot', 'paru'] + aur_packages += blend_release.get('aur-packages') + if type(blend_release.get('services')) == list: services += blend_release.get('services') @@ -284,6 +290,23 @@ Server = {package_repo["repo-url"]} exit(50) if return_val == 0: break + + counter = 0 + 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') + return_val = exec_chroot( + 'runuser', '-u', 'aur', '--', 'paru', '-Sy', '--noconfirm', '--needed', + '--noprogressbar', '--skipreview', '--removemake', '--cleanafter', '--ask=4', + *blend_release.get('aur-packages')) + exec_chroot('userdel', '-r', 'aur') + exec_chroot('rm', '-f', '/etc/sudoers.d/aur') + counter += 1 + if counter > 30: + error('failed to download AUR packages') + exit(50) + if return_val == 0: + break for service in services: if type(service) is str: From deb302a20e6d9ded01c716ca4e97f87f038ee2b4 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Fri, 9 Feb 2024 13:55:45 +0530 Subject: [PATCH 099/135] feat: implement three-way /etc merge --- akshara | 67 +++++++++++++++++++++++++++++++++++++++------------- akshara.hook | 48 ++++++++++--------------------------- 2 files changed, 63 insertions(+), 52 deletions(-) diff --git a/akshara b/akshara index 0a2f412..49b466e 100755 --- a/akshara +++ b/akshara @@ -22,6 +22,7 @@ import sys import time import yaml import shutil +import filecmp import argparse import requests import platform @@ -71,8 +72,6 @@ class colors: cyan = '\033[46m' lightgrey = '\033[47m' -# END - def exec(*cmd, **kwargs): return subprocess.call(cmd, shell=False, stdout=sys.stdout, stderr=sys.stderr, **kwargs) @@ -197,6 +196,10 @@ def update_system(): 'blend-files' ] + keep = [ + '/usr/share' + ] + if (type(blend_release.get('impl')) == str and type(blend_release.get('track')) != 'custom'): res = interpret_track(blend_release) @@ -292,21 +295,22 @@ Server = {package_repo["repo-url"]} break counter = 0 - 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') - return_val = exec_chroot( - 'runuser', '-u', 'aur', '--', 'paru', '-Sy', '--noconfirm', '--needed', - '--noprogressbar', '--skipreview', '--removemake', '--cleanafter', '--ask=4', - *blend_release.get('aur-packages')) - exec_chroot('userdel', '-r', 'aur') - exec_chroot('rm', '-f', '/etc/sudoers.d/aur') - counter += 1 - if counter > 30: - error('failed to download AUR packages') - exit(50) - if return_val == 0: - break + 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') + return_val = exec_chroot( + 'runuser', '-u', 'aur', '--', 'paru', '-Sy', '--noconfirm', '--needed', + '--noprogressbar', '--skipreview', '--removemake', '--cleanafter', '--ask=4', + *aur_packages) + exec_chroot('userdel', '-r', 'aur') + exec_chroot('rm', '-f', '/etc/sudoers.d/aur') + counter += 1 + if counter > 30: + error('failed to download AUR packages') + exit(50) + if return_val == 0: + break for service in services: if type(service) is str: @@ -344,6 +348,35 @@ Server = {package_repo["repo-url"]} exec_chroot('mkinitcpio', '-P') + exec('cp', '-ax', '/.new_rootfs/etc', '/.new.etc') + + etc_diff = filecmp.dircmp('/etc/', '/usr/etc/') + + def get_diff_etc_files(dcmp): + dir_name = dcmp.left.replace('/etc/', '/.new.etc/', 1) + for name in dcmp.left_only: + exec('mkdir', '-p', dir_name) + exec('cp', '-ax', os.path.join(dcmp.left, name), dir_name) + for name in dcmp.diff_files: + exec('cp', '-ax', os.path.join(dcmp.left, name), dir_name) + for sub_dcmp in dcmp.subdirs.values(): + get_diff_etc_files(sub_dcmp) + + get_diff_etc_files(etc_diff) + + exec('cp', '-ax', '/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: + if os.path.isdir(os.path.join(var_lib_diff.left, name)): + exec('cp', '-ax', os.path.join(var_lib_diff.left, name), dir_name) + for name in var_lib_diff.right_only: + exec('rm', '-rf', os.path.join(dir_name, name)) + + exec('cp', '/.new_rootfs/etc/pacman.conf', '/.new.etc') + exec('mv', '.new_rootfs', '.update_rootfs') new_boot_files = [] diff --git a/akshara.hook b/akshara.hook index 400c258..08f2197 100755 --- a/akshara.hook +++ b/akshara.hook @@ -12,47 +12,25 @@ run_latehook() { mv /new_root/usr /new_root/.old.usr mv /new_root/.update_rootfs/usr /new_root/usr - # Same for /var/cache/pacman. - mv /new_root/var/cache/pacman /new_root/.old.pacmancache - mv /new_root/.update_rootfs/var/cache/pacman /new_root/var/cache + # Same for /etc. + if [[ -d /new_root/.update_rootfs/etc ]]; then + mv /new_root/.update_rootfs/etc /new_root/usr/etc + fi + if [[ -d /new_root/.new.etc ]]; then + mv /new_root/etc /new_root/.old.etc + mv /new_root/.new.etc /new_root/etc + fi # Same for /var/lib/pacman. - mv /new_root/var/lib/pacman /new_root/.old.var.lib.pacman - mv /new_root/.update_rootfs/var/lib/pacman /new_root/var/lib - - # Move to /etc stage. - touch /new_root/.etc-stage - fi - - # Detect if /etc stage is active. - if [[ -f /new_root/.etc-stage ]]; then - # Create new /etc. - rm -rf /new_root/.new_etc; cp -a /new_root/etc /new_root/.new_etc - (cd /new_root/.new_etc && find . -type f | grep -Fxv -f <(cd "/new_root/.update_rootfs/etc" && find . -type f) | xargs rm -f) - (cd /new_root/.new_etc && find . -type l | grep -Fxv -f <(cd "/new_root/.update_rootfs/etc" && find . -type l) | grep -Fxv './localtime' | xargs rm -f) - mkdir -p /.old.varlib - (cd /new_root/var/lib && find . -maxdepth 1 -type d | grep -Fxv -f <(cd "/new_root/.update_rootfs/var/lib" && find . -maxdepth 1 -type d) | grep -Fxv './pacman' | xargs sh -c 'mv "$@" /new_root/.old.varlib' sh) - (cd /new_root/.update_rootfs/var/lib && find . -maxdepth 1 -type d | grep -Fxv -f <(cd "/new_root/var/lib" && find . -maxdepth 1 -type d) | xargs sh -c 'cp -r "$@" /new_root/var/lib' sh) - cp /new_root/.update_rootfs/etc/pacman.conf /new_root/.new_etc/pacman.conf - rm -rf /new_root/.new_etc/pacman.d - cp -a /new_root/.update_rootfs/etc/pacman.d /new_root/.new_etc/pacman.d - rm -rf /new_root/.new_etc/sudoers.d - cp -a /new_root/etc/sudoers.d /new_root/.new_etc - (cd /new_root/.update_rootfs/etc && find . -type f | grep -Fxv -f <(cd "/new_root/.new_etc" && find . -type f) | xargs -n 1 sh -c 'mkdir -p "/new_root/.new_etc/$(dirname "$1")"; cp -a "$1" /new_root/.new_etc/$(dirname "$1")' sh) - (cd /new_root/.update_rootfs/etc && find . -type l | grep -Fxv -f <(cd "/new_root/.new_etc" && find . -type l) | xargs -n 1 sh -c 'mkdir -p "/new_root/.new_etc/$(dirname "$1")"; cp -a "$1" /new_root/.new_etc/$(dirname "$1")' sh) - mv /new_root/etc /new_root/.old.etc || : - mv /new_root/.new_etc /new_root/etc - - mv /new_root/etc/systemd/system /new_root/.old.etc.systemd.system - mv /new_root/.update_rootfs/etc/systemd/system /new_root/etc/systemd - - # Successful update. - rm -f /new_root/.etc-stage + if [[ -d /new_root/.new.var.lib ]]; then + mv /new_root/var/lib /new_root/.old.var.lib + mv /new_root/.new.var.lib /new_root/var/lib + fi mv /new_root/.update_rootfs /new_root/.old.update_rootfs touch /new_root/.successful-update fi - + rm -rf /new_root/.blend-overlays/usr.workdir /new_root/.blend-overlays/varlibpacman.workdir for i in usr varlibpacman; do From afd6cbb149fb014eec27a868db5a1c408c1cf1fe Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Fri, 9 Feb 2024 17:24:51 +0530 Subject: [PATCH 100/135] chore: handle /var/cache/pacman --- akshara | 6 +++--- akshara.hook | 14 ++++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/akshara b/akshara index 49b466e..c87e313 100755 --- a/akshara +++ b/akshara @@ -124,9 +124,7 @@ def update_system(): os.chdir('/') - if os.path.isdir('/.new_rootfs'): - # add code here to unmount any directories under the new rootfs dir - exec('rm', '-rf', '/.new_rootfs') + exec('rm', '-rf', '/.new_rootfs', '/.new.etc', '/.new.var.lib') # Check if update is available if not os.path.isfile('/system.yaml'): @@ -376,6 +374,8 @@ Server = {package_repo["repo-url"]} exec('rm', '-rf', os.path.join(dir_name, name)) exec('cp', '/.new_rootfs/etc/pacman.conf', '/.new.etc') + exec('rm', '-rf', '/.new.var.lib/pacman') + exec('cp', '-ax', '/.new_rootfs/var/lib/pacman', '/.new.var.lib/pacman') exec('mv', '.new_rootfs', '.update_rootfs') diff --git a/akshara.hook b/akshara.hook index 08f2197..69b4852 100755 --- a/akshara.hook +++ b/akshara.hook @@ -9,8 +9,10 @@ run_latehook() { # Detect if update downloaded. if [[ -d /new_root/.update_rootfs ]]; then # Available, rename old /usr and move new /usr to /. - mv /new_root/usr /new_root/.old.usr - mv /new_root/.update_rootfs/usr /new_root/usr + if [[ -d /new_root/.update_rootfs/usr ]]; then + mv /new_root/usr /new_root/.old.usr + mv /new_root/.update_rootfs/usr /new_root/usr + fi # Same for /etc. if [[ -d /new_root/.update_rootfs/etc ]]; then @@ -21,11 +23,15 @@ run_latehook() { mv /new_root/.new.etc /new_root/etc fi - # Same for /var/lib/pacman. + # Same for /var. if [[ -d /new_root/.new.var.lib ]]; then - mv /new_root/var/lib /new_root/.old.var.lib + mv /new_root/var/lib /new_root/.old.var.lib mv /new_root/.new.var.lib /new_root/var/lib fi + if [[ -d /new_root/.update_rootfs/var/cache/pacman ]]; then + mv /new_root/var/cache/pacman /new_root/.old.var.cache.pacman + mv /new_root/.update_rootfs/var/cache/pacman /new_root/var/cache/pacman + fi mv /new_root/.update_rootfs /new_root/.old.update_rootfs touch /new_root/.successful-update From 92e34c28cca8bae8bac7132c4771e33d89dbc864 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Fri, 9 Feb 2024 20:59:43 +0530 Subject: [PATCH 101/135] feat: SaaS, system update as a service --- akshara | 2 -- akshara-system-update.service | 10 ++++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 akshara-system-update.service diff --git a/akshara b/akshara index c87e313..ec97178 100755 --- a/akshara +++ b/akshara @@ -402,8 +402,6 @@ def daemon(): if dir.startswith('.old.'): exec('rm', '-rf', '/' + dir) - Event.wait() - description = f''' {colors.bold}{colors.fg.cyan}usage:{colors.reset} diff --git a/akshara-system-update.service b/akshara-system-update.service new file mode 100644 index 0000000..5d0486f --- /dev/null +++ b/akshara-system-update.service @@ -0,0 +1,10 @@ +[Unit] +Description=Update system + +[Service] +Type=simple +ExecStart=/usr/bin/akshara update +User=root + +[Install] +WantedBy=multi-user.target From 684b1b59d3ccc4d911e8711c40687bc7e06a05eb Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Fri, 9 Feb 2024 22:03:41 +0530 Subject: [PATCH 102/135] feat: make /usr/local/share an rw overlay --- akshara.hook | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/akshara.hook b/akshara.hook index 69b4852..94e3252 100755 --- a/akshara.hook +++ b/akshara.hook @@ -36,14 +36,14 @@ run_latehook() { mv /new_root/.update_rootfs /new_root/.old.update_rootfs touch /new_root/.successful-update fi - - rm -rf /new_root/.blend-overlays/usr.workdir /new_root/.blend-overlays/varlibpacman.workdir - for i in usr varlibpacman; do + for i in usr varlibpacman usrlocalshare; do + rm -rf /new_root/.blend-overlays/$i.workdir mkdir -p /new_root/.blend-overlays/$i mkdir -p /new_root/.blend-overlays/$i.workdir done mount -t overlay overlay -o index=off -o metacopy=off -o ro,lowerdir=/new_root/usr,upperdir=/new_root/.blend-overlays/usr,workdir=/new_root/.blend-overlays/usr.workdir /new_root/usr mount -t overlay overlay -o index=off -o metacopy=off -o ro,lowerdir=/new_root/var/lib/pacman,upperdir=/new_root/.blend-overlays/varlibpacman,workdir=/new_root/.blend-overlays/varlibpacman.workdir /new_root/var/lib/pacman + mount -t overlay overlay -o rw,lowerdir=/new_root/usr/local/share,upperdir=/new_root/.blend-overlays/usrlocalshare,workdir=/new_root/.blend-overlays/usrlocalshare.workdir /new_root/usr/local/share } From f2fc8bb1ce533f9a38bde45c0b1aec66dd2c1e9f Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Fri, 9 Feb 2024 22:18:56 +0530 Subject: [PATCH 103/135] chore: add system update service --- PKGBUILD | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PKGBUILD b/PKGBUILD index 1ec79f5..8bb3c5e 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -27,6 +27,8 @@ package() { -t "${pkgdir}"/usr/bin/ install -Dm644 "${pkgname%-git}.service" -t \ "${pkgdir}"/usr/lib/systemd/system/ + install -Dm644 "${pkgname%-git}-system-update.service" -t \ + "${pkgdir}"/usr/lib/systemd/system/ install -Dm644 "${pkgname%-git}.hook" \ "${pkgdir}/usr/lib/initcpio/hooks/${pkgname%-git}" install -Dm644 "${pkgname%-git}.install" \ From 08ffe045653c2ee1908b59887e8bfd0e020ef727 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Fri, 9 Feb 2024 22:34:44 +0530 Subject: [PATCH 104/135] chore: create /.update state file --- akshara | 2 ++ akshara.hook | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/akshara b/akshara index ec97178..3069acf 100755 --- a/akshara +++ b/akshara @@ -393,6 +393,8 @@ Server = {package_repo["repo-url"]} exec('grub-mkconfig', '-o', '/boot/grub/grub.cfg') + exec('touch', '/.update') + info('downloaded update and generated new rootfs') info('you may reboot now') diff --git a/akshara.hook b/akshara.hook index 94e3252..3334dd0 100755 --- a/akshara.hook +++ b/akshara.hook @@ -4,7 +4,7 @@ run_latehook() { echo # Remove /new_root/.successful-update if exists - rm -f /new_root/.successful-update + rm -f /new_root/.successful-update /.update # Detect if update downloaded. if [[ -d /new_root/.update_rootfs ]]; then From 072e93ebf013f34a3ce1e06c38209a3c8d7f67f7 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Sat, 10 Feb 2024 11:25:04 +0530 Subject: [PATCH 105/135] fix: do not delete dirs under /var/lib --- akshara | 2 -- 1 file changed, 2 deletions(-) diff --git a/akshara b/akshara index 3069acf..dbe400f 100755 --- a/akshara +++ b/akshara @@ -370,8 +370,6 @@ Server = {package_repo["repo-url"]} for name in var_lib_diff.left_only: if os.path.isdir(os.path.join(var_lib_diff.left, name)): exec('cp', '-ax', os.path.join(var_lib_diff.left, name), dir_name) - for name in var_lib_diff.right_only: - exec('rm', '-rf', os.path.join(dir_name, name)) exec('cp', '/.new_rootfs/etc/pacman.conf', '/.new.etc') exec('rm', '-rf', '/.new.var.lib/pacman') From 3b2ff8c19754508e67ecfb99a19cb099a2afb8ea Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Sat, 10 Feb 2024 12:30:18 +0530 Subject: [PATCH 106/135] fix: remove /.update --- akshara.hook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara.hook b/akshara.hook index 3334dd0..8e62cec 100755 --- a/akshara.hook +++ b/akshara.hook @@ -4,7 +4,7 @@ run_latehook() { echo # Remove /new_root/.successful-update if exists - rm -f /new_root/.successful-update /.update + rm -f /new_root/.successful-update /new_root/.update # Detect if update downloaded. if [[ -d /new_root/.update_rootfs ]]; then From 0732bd797752564d069515d0bfa7cb60def8e724 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Sat, 10 Feb 2024 12:40:29 +0530 Subject: [PATCH 107/135] feat: make /usr/local rw --- akshara.hook | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/akshara.hook b/akshara.hook index 8e62cec..bdcda9f 100755 --- a/akshara.hook +++ b/akshara.hook @@ -37,7 +37,7 @@ run_latehook() { touch /new_root/.successful-update fi - for i in usr varlibpacman usrlocalshare; do + for i in usr varlibpacman usrlocal; do rm -rf /new_root/.blend-overlays/$i.workdir mkdir -p /new_root/.blend-overlays/$i mkdir -p /new_root/.blend-overlays/$i.workdir @@ -45,5 +45,5 @@ run_latehook() { mount -t overlay overlay -o index=off -o metacopy=off -o ro,lowerdir=/new_root/usr,upperdir=/new_root/.blend-overlays/usr,workdir=/new_root/.blend-overlays/usr.workdir /new_root/usr mount -t overlay overlay -o index=off -o metacopy=off -o ro,lowerdir=/new_root/var/lib/pacman,upperdir=/new_root/.blend-overlays/varlibpacman,workdir=/new_root/.blend-overlays/varlibpacman.workdir /new_root/var/lib/pacman - mount -t overlay overlay -o rw,lowerdir=/new_root/usr/local/share,upperdir=/new_root/.blend-overlays/usrlocalshare,workdir=/new_root/.blend-overlays/usrlocalshare.workdir /new_root/usr/local/share + mount -t overlay overlay -o rw,lowerdir=/new_root/usr/local,upperdir=/new_root/.blend-overlays/usrlocal,workdir=/new_root/.blend-overlays/usrlocal.workdir /new_root/usr/local } From efd115dbf3c77c9aa8f810f04372853ce9b3728a Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Tue, 13 Feb 2024 09:29:48 +0530 Subject: [PATCH 108/135] feat: add AKSHARA_INSTALL to (re)create /usr/etc --- akshara | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/akshara b/akshara index dbe400f..35739f4 100755 --- a/akshara +++ b/akshara @@ -346,8 +346,13 @@ Server = {package_repo["repo-url"]} exec_chroot('mkinitcpio', '-P') + exec('cp', '-ax', '/.new_rootfs/etc', '/.update_rootfs/usr/etc') exec('cp', '-ax', '/.new_rootfs/etc', '/.new.etc') + if os.environ.get('AKSHARA_INSTALL') == '1': + exec('rm', '-rf', '/usr/etc') + exec('cp', '-ax', '/.new_rootfs/etc', '/usr/etc') + etc_diff = filecmp.dircmp('/etc/', '/usr/etc/') def get_diff_etc_files(dcmp): From d50e2fc06fd589b2b95131d3c142d8feace7d18e Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Tue, 13 Feb 2024 14:49:15 +0530 Subject: [PATCH 109/135] chore: always use /etc/systemd/system from new rootfs --- akshara | 2 ++ 1 file changed, 2 insertions(+) diff --git a/akshara b/akshara index 35739f4..7d8ad05 100755 --- a/akshara +++ b/akshara @@ -377,6 +377,8 @@ Server = {package_repo["repo-url"]} exec('cp', '-ax', os.path.join(var_lib_diff.left, name), dir_name) exec('cp', '/.new_rootfs/etc/pacman.conf', '/.new.etc') + exec('rm', '-rf', '/.new.etc/systemd/system') + exec('cp', '-ax', '/.new_rootfs/etc/systemd/system', '/.new.etc/systemd') exec('rm', '-rf', '/.new.var.lib/pacman') exec('cp', '-ax', '/.new_rootfs/var/lib/pacman', '/.new.var.lib/pacman') From d401439a58ec8050fbdf4b8093f8e8dbc58a5655 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Wed, 14 Feb 2024 13:17:03 +0530 Subject: [PATCH 110/135] chore: delete blend user on update --- akshara.hook | 2 ++ akshara.install | 1 + 2 files changed, 3 insertions(+) diff --git a/akshara.hook b/akshara.hook index bdcda9f..7a6756c 100755 --- a/akshara.hook +++ b/akshara.hook @@ -33,6 +33,8 @@ run_latehook() { mv /new_root/.update_rootfs/var/cache/pacman /new_root/var/cache/pacman fi + chroot /new_root userdel -r blend &>/dev/null + mv /new_root/.update_rootfs /new_root/.old.update_rootfs touch /new_root/.successful-update fi diff --git a/akshara.install b/akshara.install index 0ba292a..be38cc6 100644 --- a/akshara.install +++ b/akshara.install @@ -9,6 +9,7 @@ build() { add_binary grep add_binary findmnt add_binary uname + add_binary chroot add_runscript } From ccee6cbe33a6dd1bf590b17a996c799f80e15dee Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Wed, 14 Feb 2024 20:18:34 +0530 Subject: [PATCH 111/135] feat: regenerate locales on update --- akshara | 3 +++ akshara.hook | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/akshara b/akshara index 7d8ad05..7799d98 100755 --- a/akshara +++ b/akshara @@ -346,6 +346,9 @@ Server = {package_repo["repo-url"]} exec_chroot('mkinitcpio', '-P') + exec('cp', '-ax', '/etc/locale.gen', '/.new_rootfs/etc/locale.gen') + exec_chroot('locale-gen') + exec('cp', '-ax', '/.new_rootfs/etc', '/.update_rootfs/usr/etc') exec('cp', '-ax', '/.new_rootfs/etc', '/.new.etc') diff --git a/akshara.hook b/akshara.hook index 7a6756c..bdcda9f 100755 --- a/akshara.hook +++ b/akshara.hook @@ -33,8 +33,6 @@ run_latehook() { mv /new_root/.update_rootfs/var/cache/pacman /new_root/var/cache/pacman fi - chroot /new_root userdel -r blend &>/dev/null - mv /new_root/.update_rootfs /new_root/.old.update_rootfs touch /new_root/.successful-update fi From 14b4b2a55b0e01b3216821f3f7ca9c07041ceb1a Mon Sep 17 00:00:00 2001 From: Joey Schaff Date: Sat, 4 May 2024 16:32:35 +0000 Subject: [PATCH 112/135] pkgbuild has switched from packaging the archlinux-bootstrap with tar.gz to tar.zst, this is causing the installation of blendOS to fail. I have replaced all mentions of tar.gz with tar.zst, I have no clue if this will work and fix the issue, as I am not a programmer. --- akshara | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/akshara b/akshara index 7799d98..4d22020 100755 --- a/akshara +++ b/akshara @@ -137,31 +137,31 @@ def update_system(): info('downloading Arch tarball...') - if not os.path.isfile('/.update.tar.gz'): - if exec('wget', '-q', '--show-progress', 'https://geo.mirror.pkgbuild.com/iso/latest/archlinux-bootstrap-x86_64.tar.gz', '-O', '/.update.tar.gz') != 0: + 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: warn('failed download') print() info('trying download again...') print() - exec('rm', '-f', '/.update.tar.gz') - if exec('wget', '-q', '--show-progress', 'https://geo.mirror.pkgbuild.com/iso/latest/archlinux-bootstrap-x86_64.tar.gz', '-O', '/.update.tar.gz') != 0: + 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: 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\.gz/.update.tar.gz/g") 2>/dev/null') != 0: + 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: error('failed checksum verification') print() info('trying download again...') - exec('rm', '-f', '/.update.tar.gz') - if exec('wget', '-q', '--show-progress', 'https://geo.mirror.pkgbuild.com/iso/latest/archlinux-bootstrap-x86_64.tar.gz', '-O', '/.update.tar.gz') != 0: + 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: 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\.gz/.update.tar.gz/g") 2>/dev/null') != 0: + 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: error('failed checksum verification') print() error('update failed') @@ -174,7 +174,7 @@ def update_system(): info('generating new system...') - exec('tar', '--acls', '--xattrs', '-xf', '.update.tar.gz') + exec('tar', '--acls', '--xattrs', '-xf', '.update.tar.zst') exec('mv', 'root.x86_64', '.new_rootfs') exec('rm', '-f', '/.new_rootfs/pkglist.x86_64.txt') exec('rm', '-f', '/.new_rootfs/version') From 7656c658d12fc7158400e86f56ae8e7f72e0e431 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 3 Jun 2024 18:42:37 +0000 Subject: [PATCH 113/135] feat: remove debug messages --- akshara | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/akshara b/akshara index 4d22020..4a07e7d 100755 --- a/akshara +++ b/akshara @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +-#!/usr/bin/env python3 # Copyright (C) 2023 Rudra Saraswat # # This file is part of akshara. @@ -150,7 +150,7 @@ def update_system(): 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', '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: error('failed checksum verification') print() info('trying download again...') @@ -161,7 +161,7 @@ def update_system(): 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', '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: error('failed checksum verification') print() error('update failed') @@ -222,8 +222,6 @@ def update_system(): if type(blend_release.get('user-services')) == list: user_services += blend_release.get('user-services') - print(blend_release) - with open('/.new_rootfs/etc/pacman.d/mirrorlist', 'w') as pacman_mirrorlist_conf: pacman_mirrorlist_conf.write('Server = https://cloudflaremirrors.com/archlinux/$repo/os/$arch\n') From b40fd76f6781f0132945dd9ae17ad395b80d96b1 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 3 Jun 2024 20:15:45 +0000 Subject: [PATCH 114/135] feat: fix typo in shebang --- akshara | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara b/akshara index 4a07e7d..38e0d36 100755 --- a/akshara +++ b/akshara @@ -1,4 +1,4 @@ --#!/usr/bin/env python3 +#!/usr/bin/env python3 # Copyright (C) 2023 Rudra Saraswat # # This file is part of akshara. From dada7f79d3e2ec8e388cc27d7a848d411d710125 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Wed, 5 Jun 2024 07:34:10 +0000 Subject: [PATCH 115/135] feat: create /usr/etc correctly --- akshara | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara b/akshara index 38e0d36..6fa0469 100755 --- a/akshara +++ b/akshara @@ -347,7 +347,6 @@ Server = {package_repo["repo-url"]} exec('cp', '-ax', '/etc/locale.gen', '/.new_rootfs/etc/locale.gen') exec_chroot('locale-gen') - exec('cp', '-ax', '/.new_rootfs/etc', '/.update_rootfs/usr/etc') exec('cp', '-ax', '/.new_rootfs/etc', '/.new.etc') if os.environ.get('AKSHARA_INSTALL') == '1': @@ -384,6 +383,7 @@ Server = {package_repo["repo-url"]} exec('cp', '-ax', '/.new_rootfs/var/lib/pacman', '/.new.var.lib/pacman') exec('mv', '.new_rootfs', '.update_rootfs') + exec('cp', '-ax', '/.update_rootfs/etc', '/.update_rootfs/usr/etc') new_boot_files = [] From a0b4a25934a517b2ae72c28524924c0404d73d5d Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Wed, 5 Jun 2024 18:34:05 +0000 Subject: [PATCH 116/135] feat: use 1.1.1.1 when installing packages --- akshara | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/akshara b/akshara index 6fa0469..a928f9d 100755 --- a/akshara +++ b/akshara @@ -222,6 +222,11 @@ def update_system(): if type(blend_release.get('user-services')) == list: user_services += blend_release.get('user-services') + exec_chroot('cp', '/.new_rootfs/etc/resolv.conf', '/.new_rootfs/etc/resolv.conf.orig') + + with open('/.new_rootfs/etc/resolv.conf', 'w') as pacman_mirrorlist_conf: + pacman_mirrorlist_conf.write('nameserver 1.1.1.1\n') + with open('/.new_rootfs/etc/pacman.d/mirrorlist', 'w') as pacman_mirrorlist_conf: pacman_mirrorlist_conf.write('Server = https://cloudflaremirrors.com/archlinux/$repo/os/$arch\n') @@ -347,6 +352,8 @@ Server = {package_repo["repo-url"]} exec('cp', '-ax', '/etc/locale.gen', '/.new_rootfs/etc/locale.gen') exec_chroot('locale-gen') + exec_chroot('mv', '/.new_rootfs/etc/resolv.conf.orig', '/.new_rootfs/etc/resolv.conf') + exec('cp', '-ax', '/.new_rootfs/etc', '/.new.etc') if os.environ.get('AKSHARA_INSTALL') == '1': From 20295cae34b3236e53e1f96e70734015e2aa7c41 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Wed, 5 Jun 2024 18:39:40 +0000 Subject: [PATCH 117/135] feat: remove resolv.conf before dircmp --- akshara | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/akshara b/akshara index a928f9d..ea30167 100755 --- a/akshara +++ b/akshara @@ -124,7 +124,9 @@ def update_system(): os.chdir('/') - exec('rm', '-rf', '/.new_rootfs', '/.new.etc', '/.new.var.lib') + if exec('rm', '-rf', '/.new_rootfs', '/.new.etc', '/.new.var.lib') != 0: + exec('umount', '-l', '/.new_rootfs') + exec('rm', '-rf', '/.new_rootfs', '/.new.etc', '/.new.var.lib') # Check if update is available if not os.path.isfile('/system.yaml'): @@ -222,7 +224,7 @@ def update_system(): if type(blend_release.get('user-services')) == list: user_services += blend_release.get('user-services') - exec_chroot('cp', '/.new_rootfs/etc/resolv.conf', '/.new_rootfs/etc/resolv.conf.orig') + exec_chroot('bash', '-c', 'rm /.new_rootfs/etc/resolv.conf') with open('/.new_rootfs/etc/resolv.conf', 'w') as pacman_mirrorlist_conf: pacman_mirrorlist_conf.write('nameserver 1.1.1.1\n') @@ -352,7 +354,7 @@ Server = {package_repo["repo-url"]} exec('cp', '-ax', '/etc/locale.gen', '/.new_rootfs/etc/locale.gen') exec_chroot('locale-gen') - exec_chroot('mv', '/.new_rootfs/etc/resolv.conf.orig', '/.new_rootfs/etc/resolv.conf') + exec_chroot('bash', '-c', 'rm /.new_rootfs/etc/resolv.conf') exec('cp', '-ax', '/.new_rootfs/etc', '/.new.etc') From 03f30a545e12c457f5fae66b418e2b0a676b335b Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Wed, 5 Jun 2024 18:40:56 +0000 Subject: [PATCH 118/135] feat: do not error out if resolv.conf doesn't already exist --- akshara | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/akshara b/akshara index ea30167..9a85193 100755 --- a/akshara +++ b/akshara @@ -224,7 +224,7 @@ def update_system(): if type(blend_release.get('user-services')) == list: user_services += blend_release.get('user-services') - exec_chroot('bash', '-c', 'rm /.new_rootfs/etc/resolv.conf') + exec_chroot('rm', '-f', '/.new_rootfs/etc/resolv.conf') with open('/.new_rootfs/etc/resolv.conf', 'w') as pacman_mirrorlist_conf: pacman_mirrorlist_conf.write('nameserver 1.1.1.1\n') @@ -354,7 +354,7 @@ Server = {package_repo["repo-url"]} exec('cp', '-ax', '/etc/locale.gen', '/.new_rootfs/etc/locale.gen') exec_chroot('locale-gen') - exec_chroot('bash', '-c', 'rm /.new_rootfs/etc/resolv.conf') + exec_chroot('rm', '-f', '/.new_rootfs/etc/resolv.conf') exec('cp', '-ax', '/.new_rootfs/etc', '/.new.etc') From 97224821ef1e45f26e9eb18027028e6a0eeae37b Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Sat, 8 Jun 2024 06:36:07 +0000 Subject: [PATCH 119/135] feat: do not overwrite mkinitcpio.conf --- akshara | 5 ----- 1 file changed, 5 deletions(-) diff --git a/akshara b/akshara index 9a85193..476512e 100755 --- a/akshara +++ b/akshara @@ -342,11 +342,6 @@ Server = {package_repo["repo-url"]} error('cancelling update so as not to render the system unbootable') sys.exit(10) - exec_chroot('bash', '-c', 'echo "MODULES=()" > /etc/mkinitcpio.conf') - exec_chroot('bash', '-c', 'echo "BINARIES=()" >> /etc/mkinitcpio.conf') - exec_chroot('bash', '-c', 'echo "FILES=()" >> /etc/mkinitcpio.conf') - exec_chroot('bash', '-c', 'echo "HOOKS=(base udev akshara autodetect keyboard keymap modconf block filesystems fsck)" >> /etc/mkinitcpio.conf') - exec_chroot('pacman', '-S', '--noconfirm', 'shadow') exec_chroot('mkinitcpio', '-P') From 0fa9484c8fa888b0fa7d79793bfa13538a6404dd Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Sun, 9 Jun 2024 11:57:09 +0000 Subject: [PATCH 120/135] feat: allow users to use custom main Arch repo --- akshara | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/akshara b/akshara index 476512e..16b97ac 100755 --- a/akshara +++ b/akshara @@ -230,7 +230,10 @@ 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: - pacman_mirrorlist_conf.write('Server = https://cloudflaremirrors.com/archlinux/$repo/os/$arch\n') + 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://cloudflaremirrors.com/archlinux/$repo/os/$arch\n') exec_chroot('mkdir', '-p', '/var/cache/pacman/pkg') exec_chroot('rm', '-rf', '/var/cache/pacman/pkg') From 1c29f45a0bbec6d41f698b344778e0b7f18e4809 Mon Sep 17 00:00:00 2001 From: Rudra Saraswat Date: Mon, 10 Jun 2024 11:51:54 +0000 Subject: [PATCH 121/135] feat: use systemd-sysusers for /etc/passwd, /etc/group, /etc/shadow and /etc/gshadow --- akshara | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/akshara b/akshara index 16b97ac..685c272 100755 --- a/akshara +++ b/akshara @@ -383,6 +383,18 @@ Server = {package_repo["repo-url"]} if os.path.isdir(os.path.join(var_lib_diff.left, name)): exec('cp', '-ax', os.path.join(var_lib_diff.left, name), dir_name) + exec('cp', '/etc/passwd', '/.new_rootfs/etc') + exec('cp', '/etc/group', '/.new_rootfs/etc') + exec('cp', '/etc/shadow', '/.new_rootfs/etc') + exec('cp', '/etc/gshadow', '/.new_rootfs/etc') + + exec_chroot('systemd-sysusers') + + exec('cp', '/.new_rootfs/etc/passwd', '/.new.etc') + exec('cp', '/.new_rootfs/etc/group', '/.new.etc') + exec('cp', '/.new_rootfs/etc/shadow', '/.new.etc') + exec('cp', '/.new_rootfs/etc/gshadow', '/.new.etc') + exec('cp', '/.new_rootfs/etc/pacman.conf', '/.new.etc') exec('rm', '-rf', '/.new.etc/systemd/system') exec('cp', '-ax', '/.new_rootfs/etc/systemd/system', '/.new.etc/systemd') From bcf8abf874f7acf4e0ef036489a57994b22ea292 Mon Sep 17 00:00:00 2001 From: Asterisk Date: Sat, 15 Jun 2024 12:41:31 +0000 Subject: [PATCH 122/135] Change default mirror to geo.mirror.pkgbuild.com --- akshara | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara b/akshara index 685c272..d9a9e09 100755 --- a/akshara +++ b/akshara @@ -233,7 +233,7 @@ def update_system(): 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://cloudflaremirrors.com/archlinux/$repo/os/$arch\n') + pacman_mirrorlist_conf.write('Server = https://https://geo.mirror.pkgbuild.com/$repo/os/$arch\n') exec_chroot('mkdir', '-p', '/var/cache/pacman/pkg') exec_chroot('rm', '-rf', '/var/cache/pacman/pkg') From c47b5ff31633090862627a821ab7121b6889193b Mon Sep 17 00:00:00 2001 From: Asterisk Date: Sat, 15 Jun 2024 12:42:56 +0000 Subject: [PATCH 123/135] fix dual https:// --- akshara | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akshara b/akshara index d9a9e09..89f759f 100755 --- a/akshara +++ b/akshara @@ -233,7 +233,7 @@ def update_system(): 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://https://geo.mirror.pkgbuild.com/$repo/os/$arch\n') + pacman_mirrorlist_conf.write('Server = https://geo.mirror.pkgbuild.com/$repo/os/$arch\n') exec_chroot('mkdir', '-p', '/var/cache/pacman/pkg') exec_chroot('rm', '-rf', '/var/cache/pacman/pkg') From 3175518459e71b2471410cdf610e764265cf993a Mon Sep 17 00:00:00 2001 From: Asterisk Date: Tue, 27 Aug 2024 21:27:57 +0000 Subject: [PATCH 124/135] Make akshara enable multilib --- akshara | 1 + 1 file changed, 1 insertion(+) diff --git a/akshara b/akshara index 89f759f..37fc2da 100755 --- a/akshara +++ b/akshara @@ -260,6 +260,7 @@ def update_system(): 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''' From 5200aa18975c1ac7f19fe660c0ec1e3d99114359 Mon Sep 17 00:00:00 2001 From: Asterisk Date: Tue, 27 Aug 2024 21:35:41 +0000 Subject: [PATCH 125/135] Update file README.md --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..14da333 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# akshara + +A simple system builder and immutability layer. + +## Development + +To test `akshara`, run the following on a working blendOS install: + +```sh +umount -l /usr && sudo mv ./akshara /usr/bin/akshara +``` + +Replace `./akshara` with wherever your modified copy of `akshara` is. \ No newline at end of file From 11b62648b12bc3ca6eb0b26d46de052d22b31297 Mon Sep 17 00:00:00 2001 From: Asterisk Date: Tue, 27 Aug 2024 21:36:37 +0000 Subject: [PATCH 126/135] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 14da333..8776cc8 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A simple system builder and immutability layer. ## Development -To test `akshara`, run the following on a working blendOS install: +To test a modified copy of `akshara`, run the following on a working blendOS install: ```sh umount -l /usr && sudo mv ./akshara /usr/bin/akshara From 4057162e15266a194721cdd1ce4801aa8dfb3cb8 Mon Sep 17 00:00:00 2001 From: Asterisk Date: Wed, 28 Aug 2024 00:23:28 +0000 Subject: [PATCH 127/135] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8776cc8..d2e7163 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A simple system builder and immutability layer. To test a modified copy of `akshara`, run the following on a working blendOS install: ```sh -umount -l /usr && sudo mv ./akshara /usr/bin/akshara +umount -l /usr && sudo mv ./akshara /usr/bin/akshara && sudo chmod +x /usr/bin/akshara ``` Replace `./akshara` with wherever your modified copy of `akshara` is. \ No newline at end of file From e2adf15f4272b0c40b25e33b65255c46db88ff58 Mon Sep 17 00:00:00 2001 From: Asterisk Date: Wed, 28 Aug 2024 00:41:45 +0000 Subject: [PATCH 128/135] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d2e7163..1a1eb3f 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,6 @@ To test a modified copy of `akshara`, run the following on a working blendOS ins umount -l /usr && sudo mv ./akshara /usr/bin/akshara && sudo chmod +x /usr/bin/akshara ``` -Replace `./akshara` with wherever your modified copy of `akshara` is. \ No newline at end of file +Replace `./akshara` with wherever your modified copy of `akshara` is. + +⚠ **ANY CHANGES TO `/usr/bin/akshara` WILL BE REVERTED AFTER EVERY UPDATE!** ⚠ \ No newline at end of file From 0709eb7dcb15fad9a7d5acb2554d4a8f2bf9cb08 Mon Sep 17 00:00:00 2001 From: askiiart Date: Tue, 1 Oct 2024 22:26:17 -0500 Subject: [PATCH 129/135] edit for askiiart-blendos/akshara --- PKGBUILD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index 8bb3c5e..b81ca75 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -5,10 +5,10 @@ pkgver=r59.9f2f25b pkgrel=1 pkgdesc="An update system for operating systems" arch=('x86_64' 'i686') -url="https://github.com/blend-os/blend" +url="https://git.askiiart.net/askiiart-blendos/akshara" license=('GPL3') makedepends=('git' 'base-devel') -source=('git+https://git.blendos.co/blendOS/system-tools/akshara') +source=('git+https://git.askiiart.net/askiiart-blendos/akshara') sha256sums=('SKIP') depends=('bash' 'python' 'python-lockfile' 'python-psutil' 'python-fasteners' 'python-yaml' 'squashfs-tools' 'wget' 'python-requests' 'arch-install-scripts') From 19b90e85f4433854dceb14efd0d2ffa80757dc67 Mon Sep 17 00:00:00 2001 From: askiiart Date: Wed, 9 Oct 2024 10:40:48 -0500 Subject: [PATCH 130/135] AUR packages work now --- akshara.hook | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/akshara.hook b/akshara.hook index bdcda9f..d26594d 100755 --- a/akshara.hook +++ b/akshara.hook @@ -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 From cba45e457ec5d915e7471a465230770a2e27eb48 Mon Sep 17 00:00:00 2001 From: askiiart Date: Tue, 8 Apr 2025 12:50:25 -0500 Subject: [PATCH 131/135] remove update on exit (with flag to not do that) --- akshara | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/akshara b/akshara index 37fc2da..e646be6 100755 --- a/akshara +++ b/akshara @@ -458,10 +458,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 +482,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)") From 27da28ccca90da2ed4a412eef7f4c11d6b1552f0 Mon Sep 17 00:00:00 2001 From: askiiart Date: Tue, 8 Apr 2025 13:03:36 -0500 Subject: [PATCH 132/135] add custom bootstrap mirror option --- akshara | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/akshara b/akshara index e646be6..4bf2942 100755 --- a/akshara +++ b/akshara @@ -137,33 +137,41 @@ 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...') + # TODO: currently it errors if it doesn't have arch-repo anyways, so this doesn't need any extra checking, maybe add a check for that later though + # 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 + # Not sure why this wouldn't just use `arch-repo` but whatever + bootstrap_mirror = blend_release.get("arch-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_mirror}/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_mirror}/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_mirror}/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_mirror}/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_mirror}/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') From 53e7c32106beac4546e19168fe30da35f29bd79a Mon Sep 17 00:00:00 2001 From: askiiart Date: Tue, 8 Apr 2025 13:03:57 -0500 Subject: [PATCH 133/135] chore: format --- akshara | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/akshara b/akshara index 4bf2942..4613b3c 100755 --- a/akshara +++ b/akshara @@ -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(): @@ -141,7 +142,7 @@ def update_system(): info('downloading Arch tarball...') - # TODO: currently it errors if it doesn't have arch-repo anyways, so this doesn't need any extra checking, maybe add a check for that later though + # TODO: currently it errors if it doesn't have arch-repo anyways, so this doesn't need any extra checking, maybe add a check for that later though # 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 # Not sure why this wouldn't just use `arch-repo` but whatever @@ -209,7 +210,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(): @@ -239,13 +240,16 @@ def update_system(): 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') + 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( + 'Server = https://geo.mirror.pkgbuild.com/$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') @@ -261,14 +265,20 @@ 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''' @@ -280,7 +290,7 @@ Server = {blend_release['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 @@ -308,12 +318,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', @@ -385,7 +397,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: From 48ad492117310f77385323ce032acdb47d0e87de Mon Sep 17 00:00:00 2001 From: askiiart Date: Wed, 16 Apr 2025 23:47:40 -0500 Subject: [PATCH 134/135] handle repos better * add bootstrap repo * add fallback for all repos * make listing `https://` optional (http must be listed if applicable) --- akshara | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) mode change 100755 => 100644 akshara diff --git a/akshara b/akshara old mode 100755 new mode 100644 index 4613b3c..6bfa05b --- a/akshara +++ b/akshara @@ -142,37 +142,56 @@ def update_system(): info('downloading Arch tarball...') - # TODO: currently it errors if it doesn't have arch-repo anyways, so this doesn't need any extra checking, maybe add a check for that later though # 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 - # Not sure why this wouldn't just use `arch-repo` but whatever - bootstrap_mirror = blend_release.get("arch-repo") + 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', f'{bootstrap_mirror}/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', f'{bootstrap_mirror}/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', f'sha256sum -c --ignore-missing <(wget -qO- {bootstrap_mirror}/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', f'{bootstrap_mirror}/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', f'sha256sum -c --ignore-missing <(wget -qO- {bootstrap_mirror}/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') @@ -239,12 +258,8 @@ 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') @@ -284,7 +299,7 @@ def update_system(): pacman_conf.write(f''' [breakfast] SigLevel = Never -Server = {blend_release['repo']} +Server = {repo} ''') if type(blend_release.get('package-repos')) == list: From 17784b6c7d14bf1fed2ea56de099570746b7a82a Mon Sep 17 00:00:00 2001 From: askiiart Date: Mon, 28 Apr 2025 13:30:48 -0500 Subject: [PATCH 135/135] remove unused stuff --- akshara | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/akshara b/akshara index 6bfa05b..4a0dfa8 100644 --- a/akshara +++ b/akshara @@ -19,15 +19,11 @@ import os import sys -import time import yaml -import shutil import filecmp import argparse import requests -import platform import fasteners -from threading import Event import subprocess __version = '1.0.0' @@ -166,7 +162,6 @@ def update_system(): 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', f'{bootstrap_repo}/iso/latest/archlinux-bootstrap-x86_64.tar.zst', '-O', '/.update.tar.zst') != 0: warn('failed download') @@ -224,10 +219,6 @@ def update_system(): 'blend-files' ] - keep = [ - '/usr/share' - ] - if (type(blend_release.get('impl')) == str and type(blend_release.get('track')) != 'custom'): res = interpret_track(blend_release) @@ -259,7 +250,7 @@ def update_system(): with open('/.new_rootfs/etc/pacman.d/mirrorlist', 'w') as pacman_mirrorlist_conf: pacman_mirrorlist_conf.write( - f'Server = {arch_repo}/$repo/os/$arch\n') + f'Server = {arch_repo}/$repo/os/$arch\n') exec_chroot('mkdir', '-p', '/var/cache/pacman/pkg') exec_chroot('rm', '-rf', '/var/cache/pacman/pkg') @@ -439,7 +430,6 @@ Server = {package_repo["repo-url"]} exec('cp', '-ax', '/.new_rootfs/var/lib/pacman', '/.new.var.lib/pacman') exec('mv', '.new_rootfs', '.update_rootfs') - exec('cp', '-ax', '/.update_rootfs/etc', '/.update_rootfs/usr/etc') new_boot_files = []