From b783764e76c4b9a8953ad1edefa050aaf68f2b62 Mon Sep 17 00:00:00 2001 From: Jeevitha Kannan K S Date: Wed, 6 Nov 2024 09:07:12 +0530 Subject: [PATCH] fix: installation bug --- scripts/install.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index 7a63e056..1ecfa4e1 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -46,6 +46,11 @@ error() { exit 1 } +# Check if running as root +if [[ $(id -u) -eq 0 ]]; then + error "Should not run as root" +fi + # Log detected OS and architecture log_message "Detected OS: $OS" log_message "Detected Architecture: $ARCH" @@ -55,6 +60,18 @@ if ! command -v curl &>/dev/null; then error "curl is required but not installed." fi +# Check for escalation tool +for cmd in sudo doas; do + if command -v "$cmd" &>/dev/null; then + ESCALATION_TOOL="$cmd" + break + fi +done + +if [ -z "$ESCALATION_TOOL" ]; then + error "Cannot find sudo or doas for escalated privileges" +fi + # Get installed FVM version if exists INSTALLED_FVM_VERSION="" if command -v fvm &>/dev/null; then @@ -116,7 +133,7 @@ fi # Create a symlink -if ! sudo ln -sf "$FVM_DIR_BIN/fvm" "$SYMLINK_TARGET"; then +if ! "$ESCALATION_TOOL" ln -sf "$FVM_DIR_BIN/fvm" "$SYMLINK_TARGET"; then error "Failed to create symlink." fi