define uninstall subcommand for ubuntu setup

parse options and subcommands in setup script
update readme
This commit is contained in:
Luis Marsano
2023-01-14 19:39:25 -05:00
parent 695f4b06ba
commit 1749789f9a
2 changed files with 72 additions and 12 deletions

View File

@@ -40,16 +40,11 @@ Re-generate your initramfs
`mkinitcpio -P` (option -P means, all preset present in `/etc/mkinitcpio.d`)
#### Ubuntu
1. Install initramfs scripts.
Install initramfs scripts & re-generate initramfs.
``` shell
sudo ./initramfs/ubuntu/setup
```
2. Re-generate initramfs.
``` shell
sudo update-initramfs -u
```
``` shell
sudo initramfs/ubuntu/setup install
```
#### Other distribution
Refer to your distribution's documentation

View File

@@ -1,5 +1,70 @@
#!/usr/bin/env bash
log() {
local CODE=$?
echo >&2 "$*"
return $CODE
}
print-help() {
log "\
usage: ${0##*/} [-h] [--] (install|uninstall)
Install initramfs scripts for Ubuntu.
SCRIPT_DIR="$(cd -P -- "$(dirname -- "$BASH_SOURCE")" && pwd)"
install {"$SCRIPT_DIR",/etc/initramfs-tools}/hooks/grub-btrfs-overlay
install {"$SCRIPT_DIR",/etc/initramfs-tools}/scripts/local-bottom/grub-btrfs-overlay
# Options
-h display this help & exit
# Subcommands
install install initramfs scripts
uninstall remove initramfs scripts"
}
usage-error() {
print-help
exit 2
}
action-install() {
local SCRIPT_DIR="$(cd -P -- "$(dirname -- "$BASH_SOURCE")" && pwd)"
install {"$SCRIPT_DIR",/etc/initramfs-tools}/hooks/grub-btrfs-overlay
install {"$SCRIPT_DIR",/etc/initramfs-tools}/scripts/local-bottom/grub-btrfs-overlay
}
action-uninstall() {
rm -f /etc/initramfs-tools/{hooks,scripts/local-bottom}/grub-btrfs-overlay
}
set -e
while getopts h OPT
do case "$OPT" in
h)
print-help
exit
;;
*)
usage-error
esac done
shift $(( OPTIND - 1 ))
OPTIND=1
ACTION=
case "$#" in
0)
log event: a subcommand is required
usage-error
;;
1)
case "$1" in
install|uninstall)
ACTION="action-$1"
;;
*)
log "\
event: unknown subcommand
subcommand: $1"
usage-error
esac
;;
*)
log "\
event: too many arguments
arguments: $*"
usage-error
esac
"$ACTION" || log "\
event: execution failure
suggestion: rerun with sudo"
exec update-initramfs -u