Browse Source

devmode

main
pvincent 5 days ago
parent
commit
c883c0c36c
  1. 7
      lib/devmode.bash
  2. 11
      lib/functions.bash
  3. 24
      lib/self-upgrade.bash
  4. 21
      lib/uninstall.bash

7
lib/devmode.bash

@ -19,11 +19,6 @@ function assert_credentials {
fi fi
} }
function assert_system_mode {
[[ -L "$MIAOU_BASH_DIR" ]] && echo "already in develoment mode: $(realpath $MIAOU_BASH_DIR)" && return 3
true
}
function dev_mode { function dev_mode {
git clone "$GIT_URL" git clone "$GIT_URL"
sudo rm "$MIAOU_BASH_DIR" -rf sudo rm "$MIAOU_BASH_DIR" -rf
@ -37,13 +32,13 @@ function assert_reachable_target {
# Main # Main
source "$MIAOU_BASH_DIR"/lib/functions.bash
assert_normal_user assert_normal_user
assert_system_mode assert_system_mode
assert_credentials assert_credentials
name=$(echo "$GIT_URL" | cut -d/ -f2) name=$(echo "$GIT_URL" | cut -d/ -f2)
name="${name%.git}" name="${name%.git}"
target="$PWD/$name" target="$PWD/$name"
source "$MIAOU_BASH_DIR"/lib/functions.bash
_confirm_destructive "target directory will be: ${target}" _confirm_destructive "target directory will be: ${target}"
assert_reachable_target assert_reachable_target
dev_mode dev_mode

11
lib/functions.bash

@ -1,5 +1,16 @@
## library of useful functions, usually prefixed with '_' ## 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 ## ARRAY Functions
## =============== ## ===============

24
lib/self-upgrade.bash

@ -18,20 +18,26 @@ function bootstrap {
fi fi
echo "miaou-bash refreshed from: $MIAOU_BASH_DIR" 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" rm -rf "$MIAOU_BASH_DIR"
bootstrap bootstrap
. "$MIAOU_BASH_DIR/lib/init.bash" . "$MIAOU_BASH_DIR/lib/init.bash"
echo "miaou-bash successfully updated" echo "miaou-bash successfully updated"
miaou-bash --version 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 fi

21
lib/uninstall.bash

@ -1,13 +1,10 @@
#!/usr/bin/env miaou-bash #!/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 if [[ -f /etc/bash.bashrc.ORIGINAL ]]; then
rm /etc/bash.bashrc rm /etc/bash.bashrc
mv /etc/bash.bashrc.ORIGINAL /etc/bash.bashrc mv /etc/bash.bashrc.ORIGINAL /etc/bash.bashrc
@ -23,4 +20,16 @@ if _confirm_destructive; then
unset MIAOU_BASH_DIR unset MIAOU_BASH_DIR
echo 'MIAOU-BASH fully uninstalled, restored from original' 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 fi
Loading…
Cancel
Save