You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
#!/usr/bin/env bash
|
|
|
|
## CONSTANTS
|
|
|
|
## FUNCTIONS
|
|
|
|
function upgrade {
|
|
echo UPGRADE
|
|
if sudo -E "$MIAOU_BASH_DIR"/bin/miaou-bash none 3>&1; then
|
|
echo FAILURE $?
|
|
fi
|
|
}
|
|
|
|
function assert_supported_distro {
|
|
if ! grep -E '^ID=debian|^ID_LIKE=debian' /etc/os-release &&
|
|
! grep -E '^ID=arch|^ID_LIKE=arch' /etc/os-release; then
|
|
local distro
|
|
distro=$(grep -oP '^ID=\K(.*)' /etc/os-release)
|
|
>&2 echo "unsupported GNU/Linux distribution: $distro"
|
|
>&2 echo 'only debian-like OR arch-like currently supported'
|
|
return 10
|
|
fi
|
|
}
|
|
|
|
function assert_bash {
|
|
if [[ $(basename "$SHELL") != 'bash' ]]; then
|
|
>&2 echo "MIAOU ERROR: you are running on SHELL=$SHELL rather than 'bash'!"
|
|
return 11
|
|
fi
|
|
}
|
|
|
|
function sudo_root {
|
|
if [[ "$UID" -ne 0 ]] && ! sudo -vp 'SUDO privilege required: '; then
|
|
>&2 echo "canceled"
|
|
return 12
|
|
fi
|
|
}
|
|
## MAIN
|
|
|
|
set -Eeuo pipefail
|
|
if assert_supported_distro && assert_bash && sudo_root; then
|
|
if [[ ! -v MIAOU_BASH_DIR ]]; then
|
|
MIAOU_BASH_DIR=/opt/miaou-bash
|
|
export MIAOU_BASH_DIR
|
|
fi
|
|
upgrade
|
|
else
|
|
>&2 echo "MIAOU_BASH_ERROR: requirements failure"
|
|
fi
|