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.

83 lines
2.1 KiB

#!/usr/bin/env miaou-bash
# CONSTANTS
INSTALL_URL='https://git.artcode.re/miaou/miaou-bash/raw/branch/main/install.sh'
# FUNCTIONS
function hosted_upgrade {
cat >&2 <<EOF
FAILURE:
You are running inside a container within the HOSTED miaou mode.
Perform the same action again underneath HOST machine!
EOF
builtin exit 10
}
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 lib/initiate.bash
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"
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"
# if "$backup"/install.sh upgraded; then
#
# shellcheck disable=SC1091
if source /tmp/miaou-bash-install.sh upgrade; then
if [[ $(find "$backup"/hooks.d -maxdepth 1 -type f | wc -l) -gt 0 ]]; then
sudo mv "$backup"/hooks.d/* "$MIAOU_BASH_DIR"/hooks.d/
fi
sudo rm -rf "$backup"
cat <<EOF
To reset this session, you can run:
exec bash -l
EOF
else
echo "ERROR: trouble during self-upgrade: revert back"
sudo rm -rf "$MIAOU_BASH_DIR"
sudo mv "$backup" "$MIAOU_BASH_DIR"
fi
}
# MAIN
source "$MIAOU_BASH_DIR"/lib/functions.bash
fetch_mode
case "$MIAOU_BASH_MODE" in
hosted) hosted_upgrade ;;
development) development_upgrade ;;
system) system_upgrade ;;
esac