MIAOU-BASH is a collection of scripts and configurations designed to enhance your terminal experience. As the name suggests, it is built on Bash and is designed to work on most modern GNU/Linux systems.
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.

76 lines
2.1 KiB

# CONSTANTS
INSTALL_URL='https://git.artcode.re/miaou/miaou-bash/raw/branch/main/install.sh'
# FUNCTIONS
function container_upgrade {
echo "MIAOU_BASH_MODE=$MIAOU_BASH_MODE"
. "$MIAOU_BASH_DIR"/lib/container-upgrade.bash
}
function development_upgrade {
[[ "$MIAOU_BASH_MODE_OWNER" != "$USER" ]] &&
>&2 echo "ERROR: development mode owned by: $MIAOU_BASH_MODE_OWNER" &&
builtin exit 11
cd "$MIAOU_BASH_DIR"/ || return 12 # should not happen
[[ -n "$(git status --porcelain)" ]] &&
>&2 echo 'ERROR: repository has uncommited changes!' &&
builtin exit 12
local git_output
git_output=$(git pull 2>&1)
if echo "$git_output" | grep -q 'up to date'; then
echo already up-to-date
else
sudo_root
sudo miaou-bash "$MIAOU_BASH_DIR"/lib/initiate.bash
echo "reset session now!"
exec bash -l
fi
}
function system_upgrade {
local current latest
current=$("$MIAOU_BASH_DIR"/bin/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
echo "new version available: $latest"
#TODO: should down new file self-upgrade.bash, then call it again
perform_upgrade
fi
}
function perform_upgrade {
sudo_root
local backup="$MIAOU_BASH_DIR".before_upgrade
sudo mv "$MIAOU_BASH_DIR" "$backup"
curl -s --output /tmp/miaou-bash-install.sh "$INSTALL_URL"
# shellcheck disable=SC1091
if source /tmp/miaou-bash-install.sh upgrade; then
if [[ $(find "$backup"/hooks.d -maxdepth 1 -type f -not -name '.*' | wc -l) -gt 0 ]]; then
sudo mv "$backup"/hooks.d/* "$MIAOU_BASH_DIR"/hooks.d/
sudo miaou-bash "$MIAOU_BASH_DIR"/lib/initiate.bash
fi
sudo rm -rf "$backup"
else
echo "ERROR: trouble during self-upgrade: revert back"
sudo rm -rf "$MIAOU_BASH_DIR"
sudo mv "$backup" "$MIAOU_BASH_DIR"
builtin exit 99
fi
}
# MAIN
source "$MIAOU_BASH_DIR"/lib/functions.bash
fetch_mode
case "$MIAOU_BASH_MODE" in
hosted) container_upgrade ;;
development) development_upgrade ;;
system) system_upgrade ;;
esac