diff --git a/demo_source.sh b/demo_source.sh new file mode 100755 index 0000000..503a48f --- /dev/null +++ b/demo_source.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +## CONSTANTS + +## FUNCTIONS + +function upgrade { + echo UPGRADE + sudo -E "$MIAOU_BASH_DIR"/bin/miaou-bash none +} + +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