Skip to content

Commit 2b7a2a9

Browse files
committed
fix
1 parent 9b1afc3 commit 2b7a2a9

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

Linux/install_bins_curl.sh

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ fi
2222
declare -a PARALLEL_PIDS=()
2323
declare -A INSTALL_STATUS=()
2424
MAX_PARALLEL_JOBS=${MAX_PARALLEL_JOBS:-10}
25+
# Global sudo usage flag
26+
USE_SUDO=0
2527
#-------------------------------------------------------------------------------#
2628

2729
#-------------------------------------------------------------------------------#
@@ -77,6 +79,7 @@ setup_dirs() {
7779
INSTALL_PRE="${INSTALL_PRE:-sudo curl -qfsSL}"
7880
INSTALL_POST="${INSTALL_POST:-sudo chmod +x}"
7981
SYMLINK_CMD="${SYMLINK_CMD:-sudo ln -fsv}"
82+
USE_SUDO=1
8083
echo -e "\n[+] Setting Install Dir (ROOT) :: ${INSTALL_DIR}\n"
8184
else
8285
# User-space installation
@@ -85,29 +88,50 @@ setup_dirs() {
8588
INSTALL_PRE="${INSTALL_PRE:-timeout -k 1m 5m curl -qfsSL}"
8689
INSTALL_POST="${INSTALL_POST:-chmod +x}"
8790
SYMLINK_CMD="${SYMLINK_CMD:-ln -fsv}"
91+
USE_SUDO=0
8892
echo -e "\n[+] Setting Install Dir (USERSPACE) :: ${INSTALL_DIR}\n"
8993
fi
9094

91-
# If running as root, strip sudo from commands
95+
# If running as root, strip sudo from commands but keep USE_SUDO flag
9296
if [[ $(id -u) -eq 0 ]]; then
9397
INSTALL_PRE="${INSTALL_PRE/sudo /}"
9498
INSTALL_POST="${INSTALL_POST/sudo /}"
9599
SYMLINK_CMD="${SYMLINK_CMD/sudo /}"
100+
USE_SUDO=0 # Running as root, no need for sudo
96101
fi
97102

98103
# Verify directories are writable (create if needed)
99104
for dir in "$INSTALL_DIR" "$INSTALL_DIR_ROOT"; do
100105
if [[ ! -d "$dir" ]]; then
101-
if ! mkdir -p "$dir" 2>/dev/null; then
102-
echo "[-] ERROR: Cannot create directory: $dir"
103-
exit 1
106+
if [[ $USE_SUDO -eq 1 ]]; then
107+
if ! sudo mkdir -p "$dir" 2>/dev/null; then
108+
echo "[-] ERROR: Cannot create directory: $dir"
109+
exit 1
110+
fi
111+
else
112+
if ! mkdir -p "$dir" 2>/dev/null; then
113+
echo "[-] ERROR: Cannot create directory: $dir"
114+
exit 1
115+
fi
104116
fi
105117
fi
106118

107-
if [[ ! -w "$dir" ]]; then
108-
echo "[-] ERROR: Directory not writable: $dir"
109-
echo " Try running with appropriate permissions or set INSTALL_DIR manually"
110-
exit 1
119+
# Test writability with appropriate permissions
120+
local test_file="${dir}/.write_test_$$"
121+
if [[ $USE_SUDO -eq 1 ]]; then
122+
if ! sudo touch "$test_file" 2>/dev/null; then
123+
echo "[-] ERROR: Directory not writable: $dir"
124+
echo " Try running with appropriate permissions or set INSTALL_DIR manually"
125+
exit 1
126+
fi
127+
sudo rm -f "$test_file" 2>/dev/null || true
128+
else
129+
if ! touch "$test_file" 2>/dev/null; then
130+
echo "[-] ERROR: Directory not writable: $dir"
131+
echo " Try running with appropriate permissions or set INSTALL_DIR manually"
132+
exit 1
133+
fi
134+
rm -f "$test_file" 2>/dev/null || true
111135
fi
112136
done
113137

@@ -117,7 +141,7 @@ setup_dirs() {
117141
local temp_lock="/tmp/install_dirs_$$.lock"
118142
(
119143
flock -x 200
120-
if [[ ${INSTALL_PRE} == sudo* ]]; then
144+
if [[ $USE_SUDO -eq 1 ]]; then
121145
sudo mkdir -p "${INSTALL_DIR}" "${INSTALL_DIR_ROOT}" "${INSTALL_DIR_LOCALH}"
122146
sudo chmod 777 -R "${HOME}/.local" 2>/dev/null || true
123147
else
@@ -502,7 +526,7 @@ main() {
502526
reset >/dev/null 2>&1; echo
503527

504528
# Fix permissions
505-
if [[ ${INSTALL_PRE} == sudo* ]]; then
529+
if [[ $USE_SUDO -eq 1 ]]; then
506530
sudo chmod 777 -R "${HOME}/.local" 2>/dev/null || true
507531
fi
508532

0 commit comments

Comments
 (0)