Skip to content

Commit 22d64e8

Browse files
committed
Only prepend sudo if not running as root already.
1 parent 2f33ff3 commit 22d64e8

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

install.sh

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,27 @@ EOF
8989
if command_exists apt-get; then
9090
cat <<EOF
9191
Install missing dependencies on Debian/Ubuntu:
92-
sudo apt-get update && sudo apt-get install -y $pkgs
92+
${SUDO}apt-get update && ${SUDO}apt-get install -y $pkgs
9393
EOF
9494
elif command_exists dnf; then
9595
cat <<EOF
9696
Install missing dependencies on Fedora/RHEL:
97-
sudo dnf install -y $pkgs
97+
${SUDO}dnf install -y $pkgs
9898
EOF
9999
elif command_exists yum; then
100100
cat <<EOF
101101
Install missing dependencies on CentOS/RHEL:
102-
sudo yum install -y $pkgs
102+
${SUDO}yum install -y $pkgs
103103
EOF
104104
elif command_exists pacman; then
105105
cat <<EOF
106106
Install missing dependencies on Arch:
107-
sudo pacman -S --needed $pkgs
107+
${SUDO}pacman -S --needed $pkgs
108108
EOF
109109
elif command_exists zypper; then
110110
cat <<EOF
111111
Install missing dependencies on openSUSE:
112-
sudo zypper install -y $pkgs
112+
${SUDO}zypper install -y $pkgs
113113
EOF
114114
else
115115
cat <<EOF
@@ -156,8 +156,8 @@ suggest_runtime_library_install() {
156156
if [ -n "$package" ]; then
157157
cat <<EOF
158158
Install the missing runtime library on Debian/Ubuntu:
159-
sudo apt-get update
160-
sudo apt-get install -y $package
159+
${SUDO}apt-get update
160+
${SUDO}apt-get install -y $package
161161
EOF
162162
else
163163
cat <<EOF
@@ -175,7 +175,7 @@ EOF
175175
if [ -n "$package" ]; then
176176
cat <<EOF
177177
Install the missing runtime library on Fedora/RHEL:
178-
sudo dnf install -y $package
178+
${SUDO}dnf install -y $package
179179
EOF
180180
else
181181
cat <<EOF
@@ -193,7 +193,7 @@ EOF
193193
if [ -n "$package" ]; then
194194
cat <<EOF
195195
Install the missing runtime library on CentOS/RHEL:
196-
sudo yum install -y $package
196+
${SUDO}yum install -y $package
197197
EOF
198198
else
199199
cat <<EOF
@@ -211,7 +211,7 @@ EOF
211211
if [ -n "$package" ]; then
212212
cat <<EOF
213213
Install the missing runtime library on Arch:
214-
sudo pacman -S --needed $package
214+
${SUDO}pacman -S --needed $package
215215
EOF
216216
else
217217
cat <<EOF
@@ -227,7 +227,7 @@ EOF
227227
if [ -n "$package" ]; then
228228
cat <<EOF
229229
Install the missing runtime library on openSUSE:
230-
sudo zypper install -y $package
230+
${SUDO}zypper install -y $package
231231
EOF
232232
else
233233
cat <<EOF
@@ -365,35 +365,35 @@ EOF
365365
if command_exists apt-get; then
366366
cat <<EOF
367367
Suggested Rust setup on Debian/Ubuntu:
368-
sudo apt-get update
369-
sudo apt-get install -y curl build-essential pkg-config libssl-dev
368+
${SUDO}apt-get update
369+
${SUDO}apt-get install -y curl build-essential pkg-config libssl-dev
370370
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
371371
. "\$HOME/.cargo/env"
372372
EOF
373373
elif command_exists dnf; then
374374
cat <<EOF
375375
Suggested Rust setup on Fedora/RHEL:
376-
sudo dnf install -y curl gcc make pkgconfig openssl-devel
376+
${SUDO}dnf install -y curl gcc make pkgconfig openssl-devel
377377
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
378378
. "\$HOME/.cargo/env"
379379
EOF
380380
elif command_exists yum; then
381381
cat <<EOF
382382
Suggested Rust setup on CentOS/RHEL:
383-
sudo yum install -y curl gcc make pkgconfig openssl-devel
383+
${SUDO}yum install -y curl gcc make pkgconfig openssl-devel
384384
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
385385
. "\$HOME/.cargo/env"
386386
EOF
387387
elif command_exists pacman; then
388388
cat <<EOF
389389
Suggested Rust setup on Arch:
390-
sudo pacman -S --needed rustup
390+
${SUDO}pacman -S --needed rustup
391391
rustup default stable
392392
EOF
393393
elif command_exists zypper; then
394394
cat <<EOF
395395
Suggested Rust setup on openSUSE:
396-
sudo zypper install -y curl gcc make pkg-config libopenssl-devel
396+
${SUDO}zypper install -y curl gcc make pkg-config libopenssl-devel
397397
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
398398
. "\$HOME/.cargo/env"
399399
EOF
@@ -640,6 +640,13 @@ for arg in "$@"; do
640640
esac
641641
done
642642

643+
# Determine sudo prefix for suggested commands (empty if already root or sudo unavailable)
644+
if [ "$(id -u)" = "0" ] || ! command_exists sudo; then
645+
SUDO=""
646+
else
647+
SUDO="sudo "
648+
fi
649+
643650
# Set default install directory if not specified
644651
if [ -z "$INSTALL_DIR" ]; then
645652
if [ "$(id -u)" = "0" ] || has_sudo; then

0 commit comments

Comments
 (0)