|
89 | 89 | if command_exists apt-get; then |
90 | 90 | cat <<EOF |
91 | 91 | 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 |
93 | 93 | EOF |
94 | 94 | elif command_exists dnf; then |
95 | 95 | cat <<EOF |
96 | 96 | Install missing dependencies on Fedora/RHEL: |
97 | | - sudo dnf install -y $pkgs |
| 97 | + ${SUDO}dnf install -y $pkgs |
98 | 98 | EOF |
99 | 99 | elif command_exists yum; then |
100 | 100 | cat <<EOF |
101 | 101 | Install missing dependencies on CentOS/RHEL: |
102 | | - sudo yum install -y $pkgs |
| 102 | + ${SUDO}yum install -y $pkgs |
103 | 103 | EOF |
104 | 104 | elif command_exists pacman; then |
105 | 105 | cat <<EOF |
106 | 106 | Install missing dependencies on Arch: |
107 | | - sudo pacman -S --needed $pkgs |
| 107 | + ${SUDO}pacman -S --needed $pkgs |
108 | 108 | EOF |
109 | 109 | elif command_exists zypper; then |
110 | 110 | cat <<EOF |
111 | 111 | Install missing dependencies on openSUSE: |
112 | | - sudo zypper install -y $pkgs |
| 112 | + ${SUDO}zypper install -y $pkgs |
113 | 113 | EOF |
114 | 114 | else |
115 | 115 | cat <<EOF |
@@ -156,8 +156,8 @@ suggest_runtime_library_install() { |
156 | 156 | if [ -n "$package" ]; then |
157 | 157 | cat <<EOF |
158 | 158 | 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 |
161 | 161 | EOF |
162 | 162 | else |
163 | 163 | cat <<EOF |
|
175 | 175 | if [ -n "$package" ]; then |
176 | 176 | cat <<EOF |
177 | 177 | Install the missing runtime library on Fedora/RHEL: |
178 | | - sudo dnf install -y $package |
| 178 | + ${SUDO}dnf install -y $package |
179 | 179 | EOF |
180 | 180 | else |
181 | 181 | cat <<EOF |
|
193 | 193 | if [ -n "$package" ]; then |
194 | 194 | cat <<EOF |
195 | 195 | Install the missing runtime library on CentOS/RHEL: |
196 | | - sudo yum install -y $package |
| 196 | + ${SUDO}yum install -y $package |
197 | 197 | EOF |
198 | 198 | else |
199 | 199 | cat <<EOF |
|
211 | 211 | if [ -n "$package" ]; then |
212 | 212 | cat <<EOF |
213 | 213 | Install the missing runtime library on Arch: |
214 | | - sudo pacman -S --needed $package |
| 214 | + ${SUDO}pacman -S --needed $package |
215 | 215 | EOF |
216 | 216 | else |
217 | 217 | cat <<EOF |
|
227 | 227 | if [ -n "$package" ]; then |
228 | 228 | cat <<EOF |
229 | 229 | Install the missing runtime library on openSUSE: |
230 | | - sudo zypper install -y $package |
| 230 | + ${SUDO}zypper install -y $package |
231 | 231 | EOF |
232 | 232 | else |
233 | 233 | cat <<EOF |
@@ -365,35 +365,35 @@ EOF |
365 | 365 | if command_exists apt-get; then |
366 | 366 | cat <<EOF |
367 | 367 | 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 |
370 | 370 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y |
371 | 371 | . "\$HOME/.cargo/env" |
372 | 372 | EOF |
373 | 373 | elif command_exists dnf; then |
374 | 374 | cat <<EOF |
375 | 375 | 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 |
377 | 377 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y |
378 | 378 | . "\$HOME/.cargo/env" |
379 | 379 | EOF |
380 | 380 | elif command_exists yum; then |
381 | 381 | cat <<EOF |
382 | 382 | 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 |
384 | 384 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y |
385 | 385 | . "\$HOME/.cargo/env" |
386 | 386 | EOF |
387 | 387 | elif command_exists pacman; then |
388 | 388 | cat <<EOF |
389 | 389 | Suggested Rust setup on Arch: |
390 | | - sudo pacman -S --needed rustup |
| 390 | + ${SUDO}pacman -S --needed rustup |
391 | 391 | rustup default stable |
392 | 392 | EOF |
393 | 393 | elif command_exists zypper; then |
394 | 394 | cat <<EOF |
395 | 395 | 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 |
397 | 397 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y |
398 | 398 | . "\$HOME/.cargo/env" |
399 | 399 | EOF |
@@ -640,6 +640,13 @@ for arg in "$@"; do |
640 | 640 | esac |
641 | 641 | done |
642 | 642 |
|
| 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 | + |
643 | 650 | # Set default install directory if not specified |
644 | 651 | if [ -z "$INSTALL_DIR" ]; then |
645 | 652 | if [ "$(id -u)" = "0" ] || has_sudo; then |
|
0 commit comments