From d5665df3041df62b07aee38c42bc93b2a9289ef7 Mon Sep 17 00:00:00 2001 From: Fankouzu Date: Sat, 21 Feb 2026 01:49:48 +0800 Subject: [PATCH] feat(install): enhance script robustness (check dependencies, secure permissions, env override) --- install.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index a9a4ce2..d8528e8 100644 --- a/install.sh +++ b/install.sh @@ -3,7 +3,7 @@ set -e # target name -target=$(uname -m) +target=${TARGET_ARCH:-$(uname -m)} # represents the directory where the script is located cwd=$(pwd) @@ -50,6 +50,19 @@ YELLOW=$'\e[0;33m' # No Color NC=$'\e[0m' +function check_dependencies { + local dependencies=("curl" "tar" "awk" "grep" "openssl") + for cmd in "${dependencies[@]}"; do + if ! command -v "$cmd" &> /dev/null; then + error "Error: '$cmd' is not installed. Please install it and try again." + exit 1 + fi + done +} + +# Check dependencies before proceeding +check_dependencies + function print_usage { printf "Usage:\n" printf " ./install.sh [Options]\n\n" @@ -346,20 +359,20 @@ fi # Check if $gaianet_base_dir directory exists if [ ! -d $gaianet_base_dir ]; then - mkdir -p -m777 $gaianet_base_dir + mkdir -p -m755 $gaianet_base_dir fi cd $gaianet_base_dir # check if `log` directory exists or not. It needs to allow `gaianet` to write into it if [ ! -d "$gaianet_base_dir/log" ]; then - mkdir -p -m777 $gaianet_base_dir/log + mkdir -p -m755 $gaianet_base_dir/log fi log_dir=$gaianet_base_dir/log # Check if "$gaianet_base_dir/bin" directory exists if [ ! -d "$gaianet_base_dir/bin" ]; then # If not, create it - mkdir -p -m777 $gaianet_base_dir/bin + mkdir -p -m755 $gaianet_base_dir/bin fi bin_dir=$gaianet_base_dir/bin