From 1eb8459950fff345e30d588cc827e42f0ce96dcf Mon Sep 17 00:00:00 2001 From: pvincent Date: Tue, 18 Aug 2026 12:31:14 +0400 Subject: [PATCH] install2 --- install2.sh | 8 +++++--- lib/functions.bash | 28 +++++++++++++--------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/install2.sh b/install2.sh index 51a4b99..dcb6045 100755 --- a/install2.sh +++ b/install2.sh @@ -15,10 +15,12 @@ function install { echo INSTALL MIAOU_BASH_DIR=/opt/miaou-bash export MIAOU_BASH_DIR - cd /tmp - curl -sO $MAIN_TAR_GZ_URL - sudo tar -xzf main.tar.gz --directory "$(dirname "$MIAOU_BASH_DIR")" + local tempfile + tempfile="/tmp/$(basename "$MAIN_TAR_GZ_URL")" + + curl -sO $MAIN_TAR_GZ_URL -o "$tempfile" + sudo tar -xzf "$tempfile" --directory "$(dirname "$MIAOU_BASH_DIR")" execute_miaou_lib initiate source /etc/profile diff --git a/lib/functions.bash b/lib/functions.bash index b380054..c8b769a 100644 --- a/lib/functions.bash +++ b/lib/functions.bash @@ -2,17 +2,13 @@ ## ASSERT Functions -function sudo_root { - [[ "$UID" -ne 0 ]] && sudo -vp 'SUDO privilege required: ' -} - function assert_root { [[ "$UID" -ne 0 ]] && echo 'root privilege required' && return 1 true } function assert_container { - cat /proc/self/cgroup | grep -E '/session-c[0-9]+.scope' + cat /proc/self/cgroup | grep -qE'session-c[0-9]+\.scope' } function assert_system_mode { @@ -26,7 +22,6 @@ function assert_system_mode { true } - ## =============== ## ARRAY Functions ## =============== @@ -34,7 +29,10 @@ function assert_system_mode { function _array_contains { local -n array=$1 local element=$2 - [[ " ${array[@]} " =~ " ${element} " ]] && return 0 || return 1 + for item in "${array[@]}"; do + [[ "$item" == "$element" ]] && return 0 + done + return 1 } function _array_intersect { @@ -50,9 +48,10 @@ function _array_intersect { } function _array_subtract { - local -n arr1=$1 # First array - local -n arr2=$2 # Array to subtract - local -n result=$3 # Output array + local -n arr1 arr2 result + arr1=$1 # First array + arr2=$2 # Array to subtract + result=$3 # Output array [[ ${#arr2[@]} == 0 ]] && result=("${arr1[@]}") && return @@ -68,7 +67,7 @@ function _array_subtract { function _pluralize_simple { echo -n "$1 " - [[ $1 -eq 1 || $1 -eq -1 ]] && echo ${2} || echo ${2}s + [[ $1 -eq 1 || $1 -eq -1 ]] && echo "${2}" || echo "${2}s" } ## ============== @@ -89,7 +88,7 @@ function fetch_distro_like { function _confirm_destructive { local message="${1:-This cannot be undone!}" echo "⚠️ WARNING: $message" - read -p "Type YES to confirm: " response + read -rp "Type YES to confirm: " response case "$response" in [yY][eE][sS] | [yY]) return 0 ;; *) echo "canceled!" && return 1 ;; @@ -103,7 +102,7 @@ function _confirm_destructive { function _flatten_short_options { local -n args=$1 local result=() - for word in ${args[@]}; do + for word in "${args[@]}"; do [[ $word == -- ]] && break if [[ $word =~ ^-[a-z][a-z] ]]; then word=${word:1} @@ -134,8 +133,7 @@ function get_distro_like { return 1 } -## ============== -## Deprecated: FIXME: to remove +## FIXME: Deprecated -> to remove ## ============== ##