Handle future overlays
This commit is contained in:
parent
958e1bc738
commit
ad66b4e6a7
2 changed files with 48 additions and 39 deletions
66
akshara
66
akshara
|
@ -21,12 +21,13 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import yaml
|
import yaml
|
||||||
import psutil
|
|
||||||
import shutil
|
import shutil
|
||||||
import argparse
|
import argparse
|
||||||
import platform
|
import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from lockfile import LockFile
|
||||||
|
|
||||||
__version = '1.0.0'
|
__version = '1.0.0'
|
||||||
|
|
||||||
with open('/etc/blend_release') as blend_release_file:
|
with open('/etc/blend_release') as blend_release_file:
|
||||||
|
@ -80,19 +81,6 @@ def exec(*cmd, **kwargs):
|
||||||
return subprocess.call(cmd, shell=False, **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):
|
def exec_chroot(*cmd, **kwargs):
|
||||||
return exec('systemd-nspawn', '-D', '/mnt/iso-update/squashfs-root', '--', *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')
|
exec('umount', '-l', '/mnt/iso-update/squashfs-root/proc')
|
||||||
|
|
||||||
|
|
||||||
def handle_system_packages(install):
|
def handle_system_packages(operation):
|
||||||
if len(args.pkg) == 0:
|
if len(args.pkg) == 0:
|
||||||
error('no packages specified')
|
error('no packages specified')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
for pkg in args.pkg:
|
if operation == 'set-custom-packages':
|
||||||
if pkg.startswith('-'):
|
info('this operation will replace the current overlay on the next boot')
|
||||||
error(f'invalid package {pkg}')
|
info('(any custom system packages/drivers installed earlier will be removed)')
|
||||||
exit(1)
|
print()
|
||||||
|
info('this command should __only__ be used for the installation of drivers')
|
||||||
if is_running():
|
info('blendOS is __not__ responsible for any system breakage')
|
||||||
error('already running')
|
elif operation == 'drop-packages':
|
||||||
exit(1)
|
info('any installed packages will be removed')
|
||||||
|
else:
|
||||||
info("if this operation fails, any system packages installed previously")
|
error('unsupported operation')
|
||||||
info('without rebooting shall be removed')
|
|
||||||
print()
|
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')
|
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:
|
||||||
|
@ -271,14 +258,14 @@ def handle_system_packages(install):
|
||||||
exec('mount', '-t', 'overlay', 'overlay', '-o',
|
exec('mount', '-t', 'overlay', 'overlay', '-o',
|
||||||
f'lowerdir=/var/lib/pacman,upperdir={varlibpacman_overlay},workdir={varlibpacman_overlay_workdir}', '/.blendrw/var/lib/pacman')
|
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']
|
operation = ['-Sy']
|
||||||
if args.noconfirm:
|
if args.noconfirm:
|
||||||
operation.append('--noconfirm')
|
operation.append('--noconfirm')
|
||||||
elif install == 'remove':
|
elif operation == 'drop-overlay':
|
||||||
operation = ['-Rn']
|
exec('rm', '-f', '/.blend-overlays/future-usr/.okay')
|
||||||
if args.noconfirm:
|
exec('rm', '-f', '/.blend-overlays/future-varlibpacman/.okay')
|
||||||
operation.append('--noconfirm')
|
exit()
|
||||||
|
|
||||||
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')
|
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', usr_overlay, '/.blend-overlays/future-usr')
|
||||||
exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman')
|
exec('mv', varlibpacman_overlay, '/.blend-overlays/future-varlibpacman')
|
||||||
exec('rm', '-rf', usr_overlay_workdir, varlibpacman_overlay_workdir)
|
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')
|
info('reboot to apply changes')
|
||||||
else:
|
else:
|
||||||
info("you are requested to review the operation's output")
|
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)
|
epilog=epilog, formatter_class=argparse.RawTextHelpFormatter)
|
||||||
command_map = {'help': 'help',
|
command_map = {'help': 'help',
|
||||||
'version': 'version',
|
'version': 'version',
|
||||||
'install': handle_system_packages,
|
'set-custom-packages': handle_system_packages,
|
||||||
'remove': handle_system_packages,
|
'drop-overlay': handle_system_packages,
|
||||||
'daemon': daemon}
|
'daemon': daemon}
|
||||||
parser.add_argument('command', choices=command_map.keys(),
|
parser.add_argument('command', choices=command_map.keys(),
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
|
@ -397,6 +386,13 @@ try:
|
||||||
elif command == 'version':
|
elif command == 'version':
|
||||||
parser.parse_args(['--version'])
|
parser.parse_args(['--version'])
|
||||||
elif command == handle_system_packages:
|
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)
|
command(args.command)
|
||||||
else:
|
else:
|
||||||
command()
|
command()
|
||||||
|
|
19
akshara.hook
19
akshara.hook
|
@ -3,6 +3,9 @@
|
||||||
run_latehook() {
|
run_latehook() {
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
# Remove /new_root/mnt/iso-update/.successful-update if exists
|
||||||
|
rm -f /new_root/mnt/iso-update/.successful-update
|
||||||
|
|
||||||
# Detect if update downloaded.
|
# Detect if update downloaded.
|
||||||
if [[ -f /new_root/mnt/iso-update/.ready-for-update ]]; then
|
if [[ -f /new_root/mnt/iso-update/.ready-for-update ]]; then
|
||||||
# Available, rename old /usr and move new /usr to /.
|
# Available, rename old /usr and move new /usr to /.
|
||||||
|
@ -63,10 +66,20 @@ run_latehook() {
|
||||||
|
|
||||||
# Handle overlays.
|
# 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
|
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
|
||||||
mkdir -p /new_root/.blend-overlays/$i.workdir
|
mkdir -p /new_root/.blend-overlays/$i.workdir
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue