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.
84 lines
2.1 KiB
84 lines
2.1 KiB
#!/usr/bin/env bash
|
|
|
|
## CONSTANTS
|
|
|
|
BASE_ARCHIVE_URL='https://git.artcode.re/miaou/miaou-bash/archive'
|
|
BASH_SHELL='/bin/bash'
|
|
|
|
## FUNCTIONS
|
|
|
|
function upgrade {
|
|
echo UPGRADE
|
|
execute_miaou_lib self-upgrade
|
|
}
|
|
|
|
function install {
|
|
echo INSTALL
|
|
|
|
local latest_tag
|
|
latest_tag=$(curl -s https://git.artcode.re/api/v1/repos/miaou/miaou-bash/tags |
|
|
grep -oPm1 '{"name":".*?",' |
|
|
head -n1 |
|
|
cut -d'"' -f4)
|
|
echo "latest_tag=$latest_tag"
|
|
|
|
local tempfile='/tmp/miaou-bash-latest.tar.gz'
|
|
curl -so "$tempfile" "${BASE_ARCHIVE_URL}/${latest_tag}.tar.gz"
|
|
sudo tar -xzf "$tempfile" --directory "$(dirname "$MIAOU_BASH_DIR")"
|
|
rm "$tempfile"
|
|
execute_miaou_lib initiate
|
|
|
|
echo "miaou-bash successfully $deployment_type_adjective"
|
|
}
|
|
|
|
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 once_installed {
|
|
[[ -v MIAOU_BASH_DIR && -d "$MIAOU_BASH_DIR" &&
|
|
-L /etc/inputrc &&
|
|
"$(readlink /etc/inputrc)" == "$MIAOU_BASH_DIR"/etc/inputrc ]]
|
|
}
|
|
|
|
function execute_miaou_lib {
|
|
sudo -E "$MIAOU_BASH_DIR"/bin/miaou-bash "$MIAOU_BASH_DIR"/lib/"$1".bash
|
|
}
|
|
|
|
function assert_bash {
|
|
if [[ $SHELL != "$BASH_SHELL" ]]; then
|
|
>&2 echo "you are running on SHELL=$SHELL. expectation: $BASH_SHELL"
|
|
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
|
|
|
|
deployment_type_adjective="${1:-installed}" # `miaou-bash --self-upgrade` provides the 'upgrade' term
|
|
if once_installed; then upgrade; else install; fi
|
|
if [[ $deployment_type_adjective == 'installed' ]]; then
|
|
exec bash -l
|
|
fi
|
|
else
|
|
>&2 echo "MIAOU_BASH_ERROR: requirements failure"
|
|
fi
|