Skip to content

Commit 4ae355e

Browse files
authored
Merge pull request #2 from Heshdude/creating-installer-generator
Creating installer generator
2 parents 23d275f + 5e1e8f1 commit 4ae355e

File tree

19 files changed

+540
-50
lines changed

19 files changed

+540
-50
lines changed

.github/workflows/deploy.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Build and Deploy
2+
on:
3+
push:
4+
branches:
5+
- master
6+
7+
jobs:
8+
build:
9+
name: Build
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout Repo
13+
uses: actions/checkout@master
14+
- name: Get the list of modified files only & Generate installers
15+
uses: technote-space/get-diff-action@v1
16+
run: pip install toml && python generate.py ${{ env.GIT_DIFF }}
17+
- name: Archive Production Artifact
18+
uses: actions/upload-artifact@master
19+
with:
20+
name: installers
21+
path: installers
22+
deploy:
23+
name: Deploy
24+
needs: build
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout Repo
28+
uses: actions/checkout@master
29+
- name: Download Artifact
30+
uses: actions/download-artifact@master
31+
with:
32+
name: installers
33+
path: installers
34+
- name: Deploy to Firebase
35+
uses: w9jds/firebase-action@master
36+
with:
37+
args: deploy --only storage
38+
env:
39+
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

.github/workflows/dockerimage.yml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1+
12
name: Run tests
23

34
on:
5+
46
push:
57
branches: [ master ]
8+
69
pull_request:
710
branches: [ master ]
811

12+
913
jobs:
1014

11-
test-alpine:
15+
test-on-ubuntu:
1216

1317
runs-on: ubuntu-latest
14-
15-
steps:
16-
- uses: actions/checkout@v2
17-
- name: Run Tests on Alpine Linux
18-
run: docker run alpine pwd
19-
20-
test-ubuntu:
21-
22-
runs-on: ubuntu-latest
23-
2418
steps:
2519
- uses: actions/checkout@v2
26-
- name: Run Tests on Ubuntu Linux
27-
run: docker run ubuntu pwd
20+
- uses: technote-space/get-diff-action@v1
21+
- name: Get the list of modified files only
22+
run: pip install toml && python generate.py ${{ env.GIT_DIFF }} && docker build -t shellspec . && docker run -v $PWD:/app shellspec bash -c "cd /app && ./test.sh ${{ env.GIT_DIFF }}"

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM ubuntu
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
RUN apt update && apt install -y curl git expect
5+
RUN git clone https://github.com/shellspec/shellspec.git \
6+
&& mkdir $HOME/bin/ \
7+
&& ln -s /shellspec/shellspec /usr/local/bin/
8+
RUN apt remove git -y
9+
RUN shellspec -v
10+
WORKDIR /app
11+
CMD shellspec

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Leopards Lab
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

generate.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import toml
2+
import sys
3+
import os
4+
import logging
5+
import errno
6+
7+
methods = {
8+
"apt": "$APT_GET",
9+
"yum": "$YUM",
10+
"dnf": "$DNF",
11+
"apk": "$APK",
12+
"pacman": "$PACMAN",
13+
"git": "$GIT"
14+
}
15+
16+
def get_method_case(method):
17+
if method in methods:
18+
return "[ ! -z "+methods[method]+"_CMD ]; then\n"
19+
else:
20+
logging.error('Unpupported method in the TOML file, method: '+method)
21+
exit(1)
22+
23+
def parse_line(line):
24+
line = line.replace('@sudo', '$SUDO')
25+
return line
26+
27+
def generate(path):
28+
29+
installer_toml_path = path+"/installer.toml"
30+
installer_sh_path = path+"/installer.sh"
31+
32+
installer_toml = open(installer_toml_path, "r")
33+
parsed_toml = toml.loads(installer_toml.read())
34+
try:
35+
with open(installer_sh_path, "w") as installer_sh:
36+
37+
installer_sh.write("""#!/bin/sh
38+
39+
YUM_CMD=$(which yum) # yum package manager for RHEL & CentOS
40+
DNF_CMD=$(which dnf) # dnf package manager for new RHEL & CentOS
41+
APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian based distributions
42+
PACMAN_CMD=$(which pacman) # pacman package manager for ArchLinux
43+
APK_CMD=$(which apk) # apk package manager for Alpine
44+
GIT_CMD=$(which git) # to build from source pulling from git
45+
SUDO_CMD=$(which sudo) # check if sudo command is there
46+
47+
USER="$(id -un 2>/dev/null || true)"
48+
SUDO=''
49+
if [ "$USER" != 'root' ]; then
50+
if $SUDO_CMD; then
51+
SUDO='sudo'
52+
else
53+
cat >&2 <<-'EOF'
54+
Error: this installer needs the ability to run commands as root.
55+
We are unable to find "sudo". Make sure its available to make this happen
56+
EOF
57+
exit 1
58+
fi
59+
fi
60+
61+
""")
62+
63+
seperator = "if"
64+
65+
for section in parsed_toml:
66+
lines = parsed_toml[section]['sh']
67+
installer_sh.write(seperator+" "+get_method_case(section))
68+
for line in lines.split("\n"):
69+
step = parse_line(line)
70+
installer_sh.write(" "+step+"\n")
71+
seperator = "elif"
72+
73+
installer_sh.write("""
74+
else
75+
echo "Couldn't install package"
76+
exit 1;
77+
fi
78+
""".strip())
79+
80+
installer_sh.close()
81+
82+
except IOError as x:
83+
if x.errno == errno.EACCES:
84+
logging.error('No enough permissions to write to '+installer_sh_path)
85+
exit(1)
86+
else:
87+
logging.error('Something went wrong when trying to write to '+installer_sh_path)
88+
exit(1)
89+
90+
for path in sys.argv[1:]:
91+
if os.path.exists(path+'/installer.toml'):
92+
logging.info('Generating installer.sh for '+path)
93+
generate(path)
94+
else:
95+
logging.warn('Could not find an installer.toml in '+path)

installers/dunner/installer.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
3+
[apt]
4+
sh = """
5+
echo "Installing hello"
6+
echo "Installed hello"
7+
"""
8+
9+
[yum]
10+
sh = """
11+
echo "Installing hello"
12+
echo "Installed hello"
13+
"""
14+
15+
16+
[apk]
17+
sh = """
18+
echo "Installing hello"
19+
echo "Installed hello"
20+
"""
21+
22+
[dnf]
23+
sh = """
24+
echo "Installing hello"
25+
echo "Installed hello"
26+
"""

installers/git/installer.sh

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,46 @@
11
#!/bin/sh
2-
2+
33
YUM_CMD=$(which yum) # yum package manager for RHEL & CentOS
44
DNF_CMD=$(which dnf) # dnf package manager for new RHEL & CentOS
55
APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian based distributions
66
PACMAN_CMD=$(which pacman) # pacman package manager for ArchLinux
77
APK_CMD=$(which apk) # apk package manager for Alpine
8+
GIT_CMD=$(which git) # to build from source pulling from git
9+
SUDO_CMD=$(which sudo) # check if sudo command is there
10+
11+
USER="$(id -un 2>/dev/null || true)"
12+
SUDO=''
13+
if [ "$USER" != 'root' ]; then
14+
if [ ! -z $SUDO_CMD ]; then
15+
SUDO='sudo'
16+
else
17+
cat >&2 <<-'EOF'
18+
Error: this installer needs the ability to run commands as root.
19+
We are unable to find "sudo". Make sure its available to make this happen
20+
EOF
21+
exit 1
22+
fi
23+
fi
824

9-
if [ ! -z $APT_GET_CMD ]; then
10-
sudo apt-get update
11-
sudo apt-get install git
12-
elif [ ! -z $DNF_CMD ]; then
13-
sudo dnf install git
14-
elif [ ! -z $YUM_CMD ]; then
15-
sudo yum install git
16-
elif [ ! -z $PACMAN_CMD ]; then
17-
pacman -Sy git
18-
elif [ ! -z $APK_CMD ]; then
19-
sudo apk add git
20-
else
21-
echo "Couldn't install package"
22-
exit 1;
23-
fi
25+
echo $SUDO
2426

25-
git --version
27+
if [ ! -z $APT_GET_CMD ]; then
28+
$SUDO apt-get update
29+
$SUDO apt-get install git
30+
31+
elif [ ! -z $YUM_CMD ]; then
32+
$SUDO yum install git
33+
34+
elif [ ! -z $PACMAN_CMD ]; then
35+
pacman -Sy git
36+
37+
elif [ ! -z $DNF_CMD ]; then
38+
$SUDO dnf install git
39+
40+
elif [ ! -z $APK_CMD ]; then
41+
$SUDO apk add git
42+
43+
else
44+
echo "Couldn't install package"
45+
exit 1;
46+
fi

installers/git/installer.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[apt]
2+
sh = """
3+
@sudo apt-get update
4+
@sudo apt-get install git
5+
"""
6+
7+
[yum]
8+
sh = """
9+
@sudo yum install git
10+
"""
11+
12+
[pacman]
13+
sh = """
14+
pacman -Sy git
15+
"""
16+
17+
[dnf]
18+
sh = """
19+
@sudo dnf install git
20+
"""
21+
22+
[apk]
23+
sh = """
24+
@sudo apk add git
25+
"""

installers/hello/installer.sh

100644100755
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
11
#!/bin/sh
2+
3+
YUM_CMD=$(which yum) # yum package manager for RHEL & CentOS
4+
DNF_CMD=$(which dnf) # dnf package manager for new RHEL & CentOS
5+
APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian based distributions
6+
PACMAN_CMD=$(which pacman) # pacman package manager for ArchLinux
7+
APK_CMD=$(which apk) # apk package manager for Alpine
8+
GIT_CMD=$(which git) # to build from source pulling from git
29

3-
echo "Hello!"
10+
if [ ! -z $APT_GET_CMD ]; then
11+
echo "Installing hello"
12+
echo "Installed hello"
13+
14+
elif [ ! -z $YUM_CMD ]; then
15+
echo "Installing hello"
16+
echo "Installed hello"
17+
18+
elif [ ! -z $APK_CMD ]; then
19+
echo "Installing hello"
20+
echo "Installed hello"
21+
22+
elif [ ! -z $DNF_CMD ]; then
23+
echo "Installing hello"
24+
echo "Installed hello"
25+
26+
else
27+
echo "Couldn't install package"
28+
exit 1;
29+
fi

installers/hello/installer.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[apt]
2+
sh = """
3+
echo "Installing hello"
4+
echo "Installed hello"
5+
"""
6+
7+
[yum]
8+
sh = """
9+
echo "Installing hello"
10+
echo "Installed hello"
11+
"""
12+
13+
[pacman]
14+
sh = """
15+
echo "Installing hello"
16+
echo "Installed hello"
17+
"""
18+
19+
[apk]
20+
sh = """
21+
echo "Installing hello"
22+
echo "Installed hello"
23+
"""
24+
25+
[dnf]
26+
sh = """
27+
echo "Installing hello"
28+
echo "Installed hello"
29+
"""

0 commit comments

Comments
 (0)