Skip to content

Commit f4ac5d0

Browse files
authored
Merge pull request #56 from Heshdude/fix/git-installer-script
Fix/git installer script
2 parents 4a51b0b + 9868290 commit f4ac5d0

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

installers/git/installer.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,33 @@ APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian bas
66
PACMAN_CMD=$(which pacman) # pacman package manager for ArchLinux
77
APK_CMD=$(which apk) # apk package manager for Alpine
88

9+
USER="$(id -un 2>/dev/null || true)"
10+
PREFIX=''
11+
if [ "$USER" != 'root' ]; then
12+
if command_exists sudo; then
13+
PREFIX='sudo'
14+
else
15+
cat >&2 <<-'EOF'
16+
Error: this installer needs the ability to run commands as root.
17+
We are unable to find "sudo". Make sure its available to make this happen
18+
EOF
19+
exit 1
20+
fi
21+
fi
22+
923
if [ ! -z $APT_GET_CMD ]; then
10-
sudo apt-get update
11-
sudo apt-get install git
24+
$PREFIX apt-get update
25+
$PREFIX apt-get install git
1226
elif [ ! -z $DNF_CMD ]; then
13-
sudo dnf install git
27+
$PREFIX dnf install git
1428
elif [ ! -z $YUM_CMD ]; then
15-
sudo yum install git
29+
$PREFIX yum install git
1630
elif [ ! -z $PACMAN_CMD ]; then
1731
pacman -Sy git
1832
elif [ ! -z $APK_CMD ]; then
19-
sudo apk add git
33+
$PREFIX apk add git
2034
else
21-
echo "Couldn't install package"
35+
echo "Couldn't find an installer matching to this package"
2236
exit 1;
2337
fi
2438

0 commit comments

Comments
 (0)