linuxbox/update/update.sh

65 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
ROOT_DIR=$(dirname "$SCRIPT_DIR")
source "$SCRIPT_DIR/common.sh"
source "$SCRIPT_DIR/arch.sh"
source "$SCRIPT_DIR/ubuntu.sh"
update::detect_os() {
local name=""
if [[ -f /etc/os-release ]]; then
. /etc/os-release
name="$NAME"
fi
case "$name" in
"Arch Linux") echo "arch" ;;
"Ubuntu") echo "ubuntu" ;;
*) echo "" ;;
esac
}
update::usage() {
cat <<'EOF'
Usage: update.sh [arch|ubuntu|auto]
When no argument is provided, the script will attempt to detect the current distribution.
EOF
}
update::main() {
local target="${1:-auto}"
local resolved=""
case "$target" in
arch|ubuntu)
resolved="$target"
;;
auto)
resolved=$(update::detect_os)
if [[ -z "$resolved" ]]; then
echo "[!] Unable to detect supported distribution." >&2
exit 1
fi
;;
*)
update::usage
exit 1
;;
esac
case "$resolved" in
arch)
arch::run
;;
ubuntu)
ubuntu::run
;;
esac
}
update::main "$@"