From 9ff46a896c0ab236b9e938eb8ebb75993ebea75f Mon Sep 17 00:00:00 2001 From: pvincent Date: Sat, 8 Aug 2026 11:54:48 +0400 Subject: [PATCH] simplified install --- install.sh | 31 +++++++++++++++++-------------- lib/functions.bash | 12 ++++++++++-- lib/self-upgrade.bash | 23 ++++++----------------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/install.sh b/install.sh index 7bf0745..615f00a 100755 --- a/install.sh +++ b/install.sh @@ -2,36 +2,39 @@ ## CONSTANTS -readonly DESTINATION=/opt +readonly MIAOU_BASH_DIR=/opt/miaou-bash readonly MAIN_TAR_GZ_URL="https://git.artcode.re/miaou/miaou-bash/archive/main.tar.gz" ## FUNCTIONS function bootstrap { - if [[ ! -d "$DESTINATION/miaou-bash" ]]; then - local temp_dir - temp_dir=$(mktemp -d) - pushd "$temp_dir" >/dev/null || return 2 - curl -s -O $MAIN_TAR_GZ_URL - tar -xzf main.tar.gz --directory "$DESTINATION" - echo "directory: miaou-bash successfully deployed to $DESTINATION" - popd >/dev/null || return 3 - fi + cd "$(mktemp -d)" || exit 3 + curl -s -O $MAIN_TAR_GZ_URL + tar -xzf main.tar.gz --directory "$MIAOU_BASH_DIR/.." - local source_bin="$DESTINATION/miaou-bash/bin/miaou-bash" + local source_bin="$MIAOU_BASH_DIR/bin/miaou-bash" local dest_bin="/usr/bin/miaou-bash" if ! cmp -s "$source_bin" "$dest_bin"; then cp -f "$source_bin" "$dest_bin" - echo "executable: /usr/bin/miaou-bash freshly created" fi + echo "miaou-bash deployed to: $MIAOU_BASH_DIR" + +} - export MIAOU_BASH_DIR="$DESTINATION/miaou-bash" +function assert_supported_distro { + grep -E '^ID=debian|^ID_LIKE=debian' /etc/os-release || + grep -E '^ID=arch|^ID_LIKE=arch' /etc/os-release } ## MAIN +set -Eeuo pipefail + [[ "$UID" -ne 0 ]] && echo 'root privilege required' && exit 1 -if [[ -v MIAOU_BASH_DIR && -d "$MIAOU_BASH_DIR" ]]; then +! assert_supported_distro && echo 'unsupported distro: debian-like OR arch-like expected' && exit 2 + +export MIAOU_BASH_DIR +if [[ -d "$MIAOU_BASH_DIR" ]]; then miaou-bash "$MIAOU_BASH_DIR/lib/self-upgrade.bash" else bootstrap diff --git a/lib/functions.bash b/lib/functions.bash index 2254607..7c76de5 100644 --- a/lib/functions.bash +++ b/lib/functions.bash @@ -4,6 +4,14 @@ ## ARRAY Functions ## =============== +function is_debian_like { + grep -E 'ID=debian|ID_LIKE=debian' /etc/os-release +} + +function is_arch_like { + grep -E 'ID=arch|ID_LIKE=arch' /etc/os-release +} + function _array_contains { local -n array=$1 local element=$2 @@ -101,11 +109,11 @@ function isArray { } function isDebian { - grep ^ID=debian /etc/os-release + grep -q ^ID=debian /etc/os-release } function isArch { - grep ^ID=arch /etc/os-release + grep -q ^ID=arch /etc/os-release } function os-release { diff --git a/lib/self-upgrade.bash b/lib/self-upgrade.bash index 5dd90a7..9b2a720 100755 --- a/lib/self-upgrade.bash +++ b/lib/self-upgrade.bash @@ -2,9 +2,7 @@ # CONSTANTS -#FIXME: source from functions.bash -if [[ ! -v DESTINATION && ! -v MAIN_TAR_GZ_URL ]]; then - readonly DESTINATION=/opt +if [[ ! -v MAIN_TAR_GZ_URL ]]; then readonly MAIN_TAR_GZ_URL="https://git.artcode.re/miaou/miaou-bash/archive/main.tar.gz" fi @@ -12,30 +10,21 @@ fi #FIXME: source from functions.bash function bootstrap { - if [[ ! -d "$DESTINATION/miaou-bash" ]]; then - local temp_dir - temp_dir=$(mktemp -d) - pushd "$temp_dir" >/dev/null || return 2 - curl -s -O $MAIN_TAR_GZ_URL - tar -xzf main.tar.gz --directory "$DESTINATION" - echo "directory: miaou-bash successfully deployed to $DESTINATION" - popd >/dev/null || return 3 - fi + cd "$(mktemp -d)" || exit 4 + curl -s -O $MAIN_TAR_GZ_URL + tar -xzf main.tar.gz --directory "$MIAOU_BASH_DIR/.." - local source_bin="$DESTINATION/miaou-bash/bin/miaou-bash" + local source_bin="$MIAOU_BASH_DIR/bin/miaou-bash" local dest_bin="/usr/bin/miaou-bash" if ! cmp -s "$source_bin" "$dest_bin"; then cp -f "$source_bin" "$dest_bin" - echo "executable: /usr/bin/miaou-bash freshly created" + echo "/usr/bin/miaou-bash updated" fi - - export MIAOU_BASH_DIR="$DESTINATION/miaou-bash" } # MAIN [[ "$UID" -ne 0 ]] && echo 'root privilege required' && exit 1 -[[ ! -v MIAOU_BASH_DIR ]] && export MIAOU_BASH_DIR="$DESTINATION/miaou-bash" current=$(miaou-bash --version) latest=$("$MIAOU_BASH_DIR/tools/wget_semver" artcode miaou/miaou-bash)