Add akshara service
This commit is contained in:
parent
a5a683a1a4
commit
90a9c6542c
4 changed files with 44 additions and 19 deletions
15
akshara
15
akshara
|
@ -21,6 +21,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import yaml
|
import yaml
|
||||||
|
import shutil
|
||||||
import argparse
|
import argparse
|
||||||
import platform
|
import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -193,7 +194,12 @@ def update_system():
|
||||||
exec('umount', '-l', '/mnt/iso-update/squashfs-root/proc')
|
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:
|
while True:
|
||||||
if not os.path.isfile('/mnt/iso-update/.ready-for-update'):
|
if not os.path.isfile('/mnt/iso-update/.ready-for-update'):
|
||||||
update_system()
|
update_system()
|
||||||
|
@ -206,10 +212,7 @@ description = f'''
|
||||||
|
|
||||||
{colors.bold}{colors.fg.cyan}version:{colors.reset} {__version}{colors.bold}
|
{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}{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}help{colors.reset} Show this help message and exit.
|
||||||
{colors.bold}version{colors.reset} Show version information 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)
|
epilog=epilog, formatter_class=argparse.RawTextHelpFormatter)
|
||||||
command_map = {'help': 'help',
|
command_map = {'help': 'help',
|
||||||
'version': 'version',
|
'version': 'version',
|
||||||
'update-daemon': 'update_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)
|
||||||
parser.add_argument('-v', '--version', action='version',
|
parser.add_argument('-v', '--version', action='version',
|
||||||
|
@ -248,4 +251,4 @@ if command == 'help':
|
||||||
elif command == 'version':
|
elif command == 'version':
|
||||||
parser.parse_args(['--version'])
|
parser.parse_args(['--version'])
|
||||||
else:
|
else:
|
||||||
globals()[command]()
|
command()
|
||||||
|
|
35
akshara.hook
35
akshara.hook
|
@ -9,6 +9,13 @@ run_latehook() {
|
||||||
mv /new_root/usr /new_root/.old.usr
|
mv /new_root/usr /new_root/.old.usr
|
||||||
mv /new_root/mnt/iso-update/squashfs-root/usr /new_root/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.
|
# Same for /var/lib/pacman.
|
||||||
mv /new_root/var/lib/pacman /new_root/.old.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/mnt/iso-update/squashfs-root/var/lib/pacman /new_root/var/lib
|
||||||
|
@ -38,28 +45,32 @@ run_latehook() {
|
||||||
cp /new_root/mnt/iso-update/squashfs-root/etc/os-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
|
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.
|
# Successful update.
|
||||||
rm -f /new_root/mnt/iso-update/.etc-stage
|
rm -f /new_root/mnt/iso-update/.etc-stage
|
||||||
touch /new_root/mnt/iso-update/.successful-update
|
touch /new_root/mnt/iso-update/.successful-update
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create overlay directories
|
# Handle overlays.
|
||||||
rm -rf /new_root/.blend-overlays /new_root/.blendrw
|
|
||||||
|
|
||||||
|
rm -rf /new_root/.blend-overlays /new_root/.blendrw
|
||||||
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
|
||||||
|
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
|
||||||
|
|
||||||
mount -t overlay overlay -o lowerdir=/new_root/usr:/new_root/.blend-overlays/usr /new_root/usr
|
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 lowerdir=/new_root/var/lib/pacman:/new_root/.blend-overlays/varlibpacman /new_root/var/lib/pacman
|
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
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ build() {
|
||||||
add_module overlay
|
add_module overlay
|
||||||
add_binary bash
|
add_binary bash
|
||||||
add_binary findmnt
|
add_binary findmnt
|
||||||
|
add_binary uname
|
||||||
add_runscript
|
add_runscript
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
akshara.service
Normal file
10
akshara.service
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Handle system operations
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/bin/akshara daemon
|
||||||
|
User=root
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
Loading…
Reference in a new issue