Skip to content

Commit 5a1226d

Browse files
authored
Merge pull request #9 from Heshdude/creating-installer-generator
Adding curl as a install method
2 parents 4065771 + f134209 commit 5a1226d

File tree

8 files changed

+84
-6
lines changed

8 files changed

+84
-6
lines changed

generate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import errno
66

77
methods = {
8+
"curl": "$CURL",
89
"apt": "$APT_GET",
910
"yum": "$YUM",
1011
"dnf": "$DNF",
@@ -36,6 +37,7 @@ def generate(path):
3637

3738
installer_sh.write("""#!/bin/sh
3839
40+
CURL_CMD=$(which curl) # curl tool
3941
YUM_CMD=$(which yum) # yum package manager for RHEL & CentOS
4042
DNF_CMD=$(which dnf) # dnf package manager for new RHEL & CentOS
4143
APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian based distributions
@@ -47,7 +49,7 @@ def generate(path):
4749
USER="$(id -un 2>/dev/null || true)"
4850
SUDO=''
4951
if [ "$USER" != 'root' ]; then
50-
if $SUDO_CMD; then
52+
if [ ! -z $SUDO_CMD ]; then
5153
SUDO='sudo'
5254
else
5355
cat >&2 <<-'EOF'

installers/git/installer.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/sh
22

3+
CURL_CMD=$(which curl) # curl tool
34
YUM_CMD=$(which yum) # yum package manager for RHEL & CentOS
45
DNF_CMD=$(which dnf) # dnf package manager for new RHEL & CentOS
56
APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian based distributions
@@ -22,8 +23,6 @@ if [ "$USER" != 'root' ]; then
2223
fi
2324
fi
2425

25-
echo $SUDO
26-
2726
if [ ! -z $APT_GET_CMD ]; then
2827
$SUDO apt-get update
2928
$SUDO apt-get install git
@@ -43,4 +42,4 @@ elif [ ! -z $APK_CMD ]; then
4342
else
4443
echo "Couldn't install package"
4544
exit 1;
46-
fi
45+
fi

installers/hello/installer.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
#!/bin/sh
22

3+
CURL_CMD=$(which curl) # curl tool
34
YUM_CMD=$(which yum) # yum package manager for RHEL & CentOS
45
DNF_CMD=$(which dnf) # dnf package manager for new RHEL & CentOS
56
APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian based distributions
67
PACMAN_CMD=$(which pacman) # pacman package manager for ArchLinux
78
APK_CMD=$(which apk) # apk package manager for Alpine
89
GIT_CMD=$(which git) # to build from source pulling from git
10+
SUDO_CMD=$(which sudo) # check if sudo command is there
11+
12+
USER="$(id -un 2>/dev/null || true)"
13+
SUDO=''
14+
if [ "$USER" != 'root' ]; then
15+
if [ ! -z $SUDO_CMD ]; then
16+
SUDO='sudo'
17+
else
18+
cat >&2 <<-'EOF'
19+
Error: this installer needs the ability to run commands as root.
20+
We are unable to find "sudo". Make sure its available to make this happen
21+
EOF
22+
exit 1
23+
fi
24+
fi
925

1026
if [ ! -z $APT_GET_CMD ]; then
1127
echo "Installing hello"
@@ -15,6 +31,10 @@ elif [ ! -z $YUM_CMD ]; then
1531
echo "Installing hello"
1632
echo "Installed hello"
1733

34+
elif [ ! -z $PACMAN_CMD ]; then
35+
echo "Installing hello"
36+
echo "Installed hello"
37+
1838
elif [ ! -z $APK_CMD ]; then
1939
echo "Installing hello"
2040
echo "Installed hello"
@@ -23,6 +43,10 @@ elif [ ! -z $DNF_CMD ]; then
2343
echo "Installing hello"
2444
echo "Installed hello"
2545

46+
elif [ ! -z $CURL_CMD ]; then
47+
echo "Installing hello"
48+
echo "Installed hello"
49+
2650
else
2751
echo "Couldn't install package"
2852
exit 1;

installers/hello/installer.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,9 @@ sh = """
2727
echo "Installing hello"
2828
echo "Installed hello"
2929
"""
30+
31+
[curl]
32+
sh = """
33+
echo "Installing hello"
34+
echo "Installed hello"
35+
"""

installers/hello/spec/hello_spec.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Describe "Installer script for"
22
Describe "hello"
33
It "should say hello!"
44
When call installers/hello/installer.sh
5-
The output should eq "Hello!"
5+
The output should include "Installed"
66
End
77
End
88
End

installers/nginx/installer.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
#!/bin/sh
22

3+
CURL_CMD=$(which curl) # curl tool
34
YUM_CMD=$(which yum) # yum package manager for RHEL & CentOS
45
DNF_CMD=$(which dnf) # dnf package manager for new RHEL & CentOS
56
APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian based distributions
67
PACMAN_CMD=$(which pacman) # pacman package manager for ArchLinux
78
APK_CMD=$(which apk) # apk package manager for Alpine
89
GIT_CMD=$(which git) # to build from source pulling from git
10+
SUDO_CMD=$(which sudo) # check if sudo command is there
11+
12+
USER="$(id -un 2>/dev/null || true)"
13+
SUDO=''
14+
if [ "$USER" != 'root' ]; then
15+
if [ ! -z $SUDO_CMD ]; then
16+
SUDO='sudo'
17+
else
18+
cat >&2 <<-'EOF'
19+
Error: this installer needs the ability to run commands as root.
20+
We are unable to find "sudo". Make sure its available to make this happen
21+
EOF
22+
exit 1
23+
fi
24+
fi
925

1026
if [ ! -z $APT_GET_CMD ]; then
1127
sudo apt-get update
@@ -15,7 +31,7 @@ elif [ ! -z $YUM_CMD ]; then
1531
sudo yum install nginx
1632

1733
elif [ ! -z $PACMAN_CMD ]; then
18-
sudo pacman -S nginx
34+
$SUDO pacman -S nginx
1935

2036
elif [ ! -z $APK_CMD ]; then
2137
sudo apk update

installers/node/installer.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
#!/bin/sh
22

3+
CURL_CMD=$(which curl) # curl tool
34
YUM_CMD=$(which yum) # yum package manager for RHEL & CentOS
45
DNF_CMD=$(which dnf) # dnf package manager for new RHEL & CentOS
56
APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian based distributions
67
PACMAN_CMD=$(which pacman) # pacman package manager for ArchLinux
78
APK_CMD=$(which apk) # apk package manager for Alpine
89
GIT_CMD=$(which git) # to build from source pulling from git
10+
SUDO_CMD=$(which sudo) # check if sudo command is there
11+
12+
USER="$(id -un 2>/dev/null || true)"
13+
SUDO=''
14+
if [ "$USER" != 'root' ]; then
15+
if [ ! -z $SUDO_CMD ]; then
16+
SUDO='sudo'
17+
else
18+
cat >&2 <<-'EOF'
19+
Error: this installer needs the ability to run commands as root.
20+
We are unable to find "sudo". Make sure its available to make this happen
21+
EOF
22+
exit 1
23+
fi
24+
fi
925

1026
if [ ! -z $APT_GET_CMD ]; then
1127
if [ -n "$(uname -a | grep Ubuntu)" ]; then

installers/python3/installer.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/sh
22

3+
CURL_CMD=$(which curl) # curl tool
34
YUM_CMD=$(which yum) # yum package manager for RHEL & CentOS
45
DNF_CMD=$(which dnf) # dnf package manager for new RHEL & CentOS
56
APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian based distributions
@@ -8,6 +9,20 @@ APK_CMD=$(which apk) # apk package manager for Alpine
89
GIT_CMD=$(which git) # to build from source pulling from git
910
SUDO_CMD=$(which sudo) # check if sudo command is there
1011

12+
USER="$(id -un 2>/dev/null || true)"
13+
SUDO=''
14+
if [ "$USER" != 'root' ]; then
15+
if [ ! -z $SUDO_CMD ]; then
16+
SUDO='sudo'
17+
else
18+
cat >&2 <<-'EOF'
19+
Error: this installer needs the ability to run commands as root.
20+
We are unable to find "sudo". Make sure its available to make this happen
21+
EOF
22+
exit 1
23+
fi
24+
fi
25+
1126
if [ ! -z $APT_GET_CMD ]; then
1227
sudo apt-get update
1328
sudo apt-get install python3

0 commit comments

Comments
 (0)