Files
grub-btrfs/initramfs/ubuntu/setup
Luis Marsano 1749789f9a define uninstall subcommand for ubuntu setup
parse options and subcommands in setup script
update readme
2023-01-15 14:26:08 -05:00

71 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
log() {
local CODE=$?
echo >&2 "$*"
return $CODE
}
print-help() {
log "\
usage: ${0##*/} [-h] [--] (install|uninstall)
Install initramfs scripts for Ubuntu.
# 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