diff --git a/lib/devmode.bash b/lib/devmode.bash index 86823d0..0185c15 100755 --- a/lib/devmode.bash +++ b/lib/devmode.bash @@ -19,11 +19,6 @@ function assert_credentials { fi } -function assert_system_mode { - [[ -L "$MIAOU_BASH_DIR" ]] && echo "already in develoment mode: $(realpath $MIAOU_BASH_DIR)" && return 3 - true -} - function dev_mode { git clone "$GIT_URL" sudo rm "$MIAOU_BASH_DIR" -rf @@ -37,13 +32,13 @@ function assert_reachable_target { # Main +source "$MIAOU_BASH_DIR"/lib/functions.bash assert_normal_user assert_system_mode assert_credentials name=$(echo "$GIT_URL" | cut -d/ -f2) name="${name%.git}" target="$PWD/$name" -source "$MIAOU_BASH_DIR"/lib/functions.bash _confirm_destructive "target directory will be: ${target}" assert_reachable_target dev_mode diff --git a/lib/functions.bash b/lib/functions.bash index 8c30f07..0d328f3 100644 --- a/lib/functions.bash +++ b/lib/functions.bash @@ -1,5 +1,16 @@ ## library of useful functions, usually prefixed with '_' +## ASSERT Functions + +function assert_root { + [[ "$UID" -ne 0 ]] && echo 'root privilege required' && return 1 + true +} + +function assert_system_mode { + [[ -L "$MIAOU_BASH_DIR" ]] && >&2 echo "ERROR: development mode: $(realpath $MIAOU_BASH_DIR)" && return 3 + true +} ## =============== ## ARRAY Functions ## =============== diff --git a/lib/self-upgrade.bash b/lib/self-upgrade.bash index d09802a..6dedc88 100755 --- a/lib/self-upgrade.bash +++ b/lib/self-upgrade.bash @@ -18,20 +18,26 @@ function bootstrap { fi echo "miaou-bash refreshed from: $MIAOU_BASH_DIR" } -# MAIN -[[ "$UID" -ne 0 ]] && echo 'root privilege required' && exit 1 -current=$(miaou-bash --version) -latest=$("$MIAOU_BASH_DIR/tools/wget_semver" artcode miaou/miaou-bash) - -if [[ "$current" == "$latest" ]]; then - echo "up-to-date version: $current" -else - # TODO: prevent refresh from development purpose +function self_upgrade { rm -rf "$MIAOU_BASH_DIR" bootstrap . "$MIAOU_BASH_DIR/lib/init.bash" echo "miaou-bash successfully updated" miaou-bash --version +} + +# MAIN + +source "$MIAOU_BASH_DIR"/lib/functions.bash +assert_system_mode +assert_root + +current=$(miaou-bash --version) +latest=$("$MIAOU_BASH_DIR/tools/wget_semver" artcode miaou/miaou-bash) +if [[ "$current" == "$latest" ]]; then + echo "up-to-date version: $current" +else + self_upgrade fi diff --git a/lib/uninstall.bash b/lib/uninstall.bash index 7493c35..b4513e5 100644 --- a/lib/uninstall.bash +++ b/lib/uninstall.bash @@ -1,13 +1,10 @@ #!/usr/bin/env miaou-bash -# MAIN -[[ "$UID" -ne 0 ]] && echo 'root privilege required' && exit 1 +# Constants -cd || exit - -source "$MIAOU_BASH_DIR"/lib/functions.bash +# Functions -if _confirm_destructive; then +function uninstall { if [[ -f /etc/bash.bashrc.ORIGINAL ]]; then rm /etc/bash.bashrc mv /etc/bash.bashrc.ORIGINAL /etc/bash.bashrc @@ -23,4 +20,16 @@ if _confirm_destructive; then unset MIAOU_BASH_DIR echo 'MIAOU-BASH fully uninstalled, restored from original' +} + +# Main + +source "$MIAOU_BASH_DIR"/lib/functions.bash +assert_system_mode +assert_root +cd || exit +if _confirm_destructive; then + uninstall +else + >&2 echo canceled && builtin exit 1 fi