Skip to content

Commit 4a72995

Browse files
authored
Merge pull request #66 from Heshdude/master
Phase II improvements to Installer Generator and Installers
2 parents 8701c79 + d1a3998 commit 4a72995

24 files changed

+723
-223
lines changed

.github/workflows/deploy.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515
uses: technote-space/get-diff-action@v1
1616
- name: Generate installers
1717
run: pip install toml && python generate.py ${{ env.GIT_DIFF }}
18+
- name: Minify generated installers
19+
run: ./minify.sh ${{ env.GIT_DIFF }}
1820
- name: Archive Production Artifact
1921
uses: actions/upload-artifact@master
2022
with:
@@ -46,5 +48,5 @@ jobs:
4648
PROJECT_ID: installer-to
4749
APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
4850
with:
49-
args: rsync -r installers gs://installer-to.appspot.com/installers
51+
args: rsync -r installers gs://installer-to.appspot.com/
5052
cli: gsutil

.github/workflows/dockerimage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919
- uses: actions/checkout@v2
2020
- uses: technote-space/get-diff-action@v1
2121
- 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 }}"
22+
run: pip install toml pytablewriter && 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 }}"

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@ Try,
1515
```
1616
curl https://installer.to/git | bash
1717
```
18-
18+
__
1919
This will install Git on your machine!
2020

2121
## Tools list
22-
23-
| Tool | Apt-get | Yum | DNF | Apk | URL |
24-
|--------- |--------- |----- |----- |----- | --------|
25-
| Git | 👍 | 👍 | 👍 | 👍 | https://installer.to/git |
26-
| Docker | 👍 | 👍 | WIP | WIP | https://installer.to/docker |
27-
| Kubectl | 👍 | WIP | WIP | WIP | https://installer.to/kubectl |
28-
| NVM | WIP | WIP | WIP | WIP | https://installer.to/nvm |
29-
| Docker Compose | 👍 | 👍 | WIP | WIP | https://installer.to/docker-compose |
22+
<!-- beginning of tools list -->
23+
| Tool |Apt|Yum|Packman|APK|DNF|CURL| URL |
24+
|--------|---|---|-------|---|---|----|----------------------------|
25+
|Git |Yes|Yes|Yes |Yes|Yes|No |https://installer.to/git |
26+
|Hello |Yes|Yes|Yes |Yes|Yes|Yes |https://installer.to/hello |
27+
|NodeJS |Yes|Yes|No |Yes|Yes|No |https://installer.to/node |
28+
|Python 3|Yes|Yes|Yes |Yes|Yes|No |https://installer.to/python3|
29+
|Nginx |Yes|Yes|Yes |Yes|Yes|No |https://installer.to/nginx |
30+
|gCloud |No |No |No |No |No |Yes |https://installer.to/gcloud |
31+
|Docker |Yes|Yes|No |No |No |No |https://installer.to/docker |
32+
|Fabric |No |No |No |No |No |Yes |https://installer.to/hlf |
33+
34+
<!-- end of tools list -->

generate.py

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os
44
import logging
55
import errno
6+
import pytablewriter
7+
import re
68

79
methods = {
810
"curl": "$CURL",
@@ -13,6 +15,63 @@
1315
"pacman": "$PACMAN",
1416
"git": "$GIT"
1517
}
18+
def update_readme(summary):
19+
writer = pytablewriter.MarkdownTableWriter()
20+
writer.headers = ["Tool", "Apt", "Yum", "Packman", "APK", "DNF", "CURL", "URL"]
21+
value_matrix = []
22+
for tool_shortname in summary:
23+
tool = summary[tool_shortname]
24+
name = tool['name']
25+
installers = tool['installers']
26+
apt = "Yes" if "apt" in installers else "No"
27+
yum = "Yes" if "yum" in installers else "No"
28+
pacman = "Yes" if "pacman" in installers else "No"
29+
apk = "Yes" if "apk" in installers else "No"
30+
dnf = "Yes" if "dnf" in installers else "No"
31+
curl = "Yes" if "curl" in installers else "No"
32+
url = "https://installer.to/"+tool_shortname
33+
value_matrix.append([name, apt, yum, pacman, apk, dnf, curl, url])
34+
print(value_matrix)
35+
writer.value_matrix = value_matrix
36+
table_md = writer.dumps()
37+
try:
38+
with open("./README.md", "r+") as readme_md:
39+
readme = readme_md.read()
40+
beggining = "<!-- beginning of tools list -->"
41+
end = "<!-- end of tools list -->"
42+
regex = r""+beggining+"\n(.*)\n"+end
43+
readme = re.sub(regex, beggining+"\n"+table_md+"\n"+end, readme, flags=re.S)
44+
readme_md.seek(0) # sets point at the beginning of the file
45+
readme_md.truncate() # Clear previous content
46+
readme_md.write(readme)
47+
readme_md.close()
48+
except Error as e:
49+
print(e)
50+
51+
52+
def update_summary(name, shortname, description, installers):
53+
try:
54+
with open("./installers.toml", "r+") as installer_summary:
55+
summaary = installer_summary.read()
56+
print (summaary)
57+
parsed_summary_toml = toml.loads(summaary)
58+
print (parsed_summary_toml)
59+
if shortname not in parsed_summary_toml:
60+
parsed_summary_toml[shortname] = {}
61+
parsed_summary_toml[shortname]['name'] = name
62+
parsed_summary_toml[shortname]['name'] = name
63+
parsed_summary_toml[shortname]['description'] = description
64+
parsed_summary_toml[shortname]['installers'] = ",".join(installers)
65+
print (parsed_summary_toml)
66+
installer_summary.seek(0) # sets point at the beginning of the file
67+
installer_summary.truncate() # Clear previous content
68+
installer_summary.write(toml.dumps(parsed_summary_toml))
69+
installer_summary.close()
70+
71+
update_readme(parsed_summary_toml)
72+
except IOError as e:
73+
print ("Error", e)
74+
pass
1675

1776
def get_method_case(method):
1877
if method in methods:
@@ -22,11 +81,16 @@ def get_method_case(method):
2281
exit(1)
2382

2483
def parse_line(line):
25-
line = line.replace('@sudo', '$SUDO')
84+
line = line\
85+
.replace('@sudo', '$SUDO')\
86+
.replace('@log', 'info')\
87+
.replace('@info', 'info')\
88+
.replace('@warn', 'warn')\
89+
.replace('@error', 'error')
2690
return line
2791

2892
def generate(path):
29-
93+
installer_methods = [ ]
3094
installer_toml_path = path+"/installer.toml"
3195
installer_sh_path = path+"/installer.sh"
3296

@@ -37,14 +101,14 @@ def generate(path):
37101

38102
installer_sh.write("""#!/bin/sh
39103
40-
CURL_CMD=$(which curl) # curl tool
41-
YUM_CMD=$(which yum) # yum package manager for RHEL & CentOS
42-
DNF_CMD=$(which dnf) # dnf package manager for new RHEL & CentOS
43-
APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian based distributions
44-
PACMAN_CMD=$(which pacman) # pacman package manager for ArchLinux
45-
APK_CMD=$(which apk) # apk package manager for Alpine
46-
GIT_CMD=$(which git) # to build from source pulling from git
47-
SUDO_CMD=$(which sudo) # check if sudo command is there
104+
CURL_CMD=$(which curl)
105+
YUM_CMD=$(which yum)
106+
DNF_CMD=$(which dnf)
107+
APT_GET_CMD=$(which apt-get)
108+
PACMAN_CMD=$(which pacman)
109+
APK_CMD=$(which apk)
110+
GIT_CMD=$(which git)
111+
SUDO_CMD=$(which sudo)
48112
49113
USER="$(id -un 2>/dev/null || true)"
50114
SUDO=''
@@ -60,11 +124,33 @@ def generate(path):
60124
fi
61125
fi
62126
127+
RESET='\033[0m'
128+
RED='\033[0;31m'
129+
GREEN='\033[0;32m'
130+
YELLOW='\033[0;33m'
131+
log () {
132+
echo "[`date "+%Y.%m.%d-%H:%M:%S%Z"`]$1 $2"
133+
}
134+
info () {
135+
log "$GREEN INFO$RESET $1"
136+
}
137+
warn () {
138+
log "$YELLOW WARN$RESET $1"
139+
}
140+
error () {
141+
log "$RED ERROR$RESET $1"
142+
}
143+
63144
""")
64145

65146
seperator = "if"
66147

67148
for section in parsed_toml:
149+
if not isinstance(parsed_toml[section], dict):
150+
continue
151+
if parsed_toml[section]['sh'] is "":
152+
continue
153+
installer_methods.append(section)
68154
lines = parsed_toml[section]['sh']
69155
installer_sh.write(seperator+" "+get_method_case(section))
70156
for line in lines.split("\n"):
@@ -80,6 +166,8 @@ def generate(path):
80166
""".strip())
81167

82168
installer_sh.close()
169+
update_summary(parsed_toml['name'], parsed_toml['shortname'], parsed_toml['description'], installer_methods)
170+
print("installer_methods",installer_methods)
83171

84172
except IOError as x:
85173
if x.errno == errno.EACCES:

installers.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[git]
2+
name = "Git"
3+
installers = "apt,yum,pacman,dnf,apk"
4+
description = "Git SVM"
5+
6+
[hello]
7+
name = "Hello"
8+
installers = "apt,yum,pacman,apk,dnf,curl"
9+
description = "This is just a sample tool"
10+
11+
[node]
12+
name = "NodeJS"
13+
installers = "apt,yum,dnf,apk"
14+
15+
[python3]
16+
name = "Python 3"
17+
description = "Python 3"
18+
installers = "apt,yum,pacman,apk,dnf"
19+
20+
[nginx]
21+
name = "Nginx"
22+
description = "Nginx server"
23+
installers = "apt,yum,pacman,apk,dnf"
24+
25+
[gcloud]
26+
name = "gCloud"
27+
description = "CLI tool of GCP"
28+
installers = "curl"
29+
30+
[docker]
31+
name = "Docker"
32+
description = "Docker"
33+
installers = "apt,yum"
34+
35+
[hlf]
36+
name = "Fabric"
37+
description = "Hyperledger Fabric"
38+
installers = "curl"

installers/docker/installer.sh

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/bin/sh
2-
3-
CURL_CMD=$(which curl) # curl tool
4-
YUM_CMD=$(which yum) # yum package manager for RHEL & CentOS
5-
DNF_CMD=$(which dnf) # dnf package manager for new RHEL & CentOS
6-
APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian based distributions
7-
PACMAN_CMD=$(which pacman) # pacman package manager for ArchLinux
8-
APK_CMD=$(which apk) # apk package manager for Alpine
9-
GIT_CMD=$(which git) # to build from source pulling from git
10-
SUDO_CMD=$(which sudo) # check if sudo command is there
2+
3+
CURL_CMD=$(which curl)
4+
YUM_CMD=$(which yum)
5+
DNF_CMD=$(which dnf)
6+
APT_GET_CMD=$(which apt-get)
7+
PACMAN_CMD=$(which pacman)
8+
APK_CMD=$(which apk)
9+
GIT_CMD=$(which git)
10+
SUDO_CMD=$(which sudo)
1111

1212
USER="$(id -un 2>/dev/null || true)"
1313
SUDO=''
@@ -23,43 +23,37 @@ if [ "$USER" != 'root' ]; then
2323
fi
2424
fi
2525

26+
RESET=''
27+
RED=''
28+
GREEN=''
29+
YELLOW=''
30+
log () {
31+
echo "[`date "+%Y.%m.%d-%H:%M:%S%Z"`]$1 $2"
32+
}
33+
info () {
34+
log "$GREEN INFO$RESET $1"
35+
}
36+
warn () {
37+
log "$YELLOW WARN$RESET $1"
38+
}
39+
error () {
40+
log "$RED ERROR$RESET $1"
41+
}
42+
2643
if [ ! -z $APT_GET_CMD ]; then
2744
$SUDO apt-get update
28-
$SUDO apt-get install \
29-
apt-transport-https \
30-
ca-certificates \
31-
curl \
32-
gnupg-agent \
33-
software-properties-common
34-
35-
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
36-
37-
$SUDO add-apt-repository \
38-
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
39-
$(lsb_release -cs) \
40-
stable"
41-
42-
$SUDO apt-get update
43-
44-
$SUDO apt-get install docker-ce docker-ce-cli containerd.io
45-
45+
$SUDO apt-get install apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
46+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
47+
$SUDO add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
48+
$SUDO apt-get update
49+
$SUDO apt-get install docker-ce docker-ce-cli containerd.io
50+
4651
elif [ ! -z $YUM_CMD ]; then
4752
$SUDO yum install -y yum-utils
48-
$SUDO yum-config-manager \
49-
--add-repo \
50-
https://download.docker.com/linux/centos/docker-ce.repo
53+
$SUDO yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
5154
$SUDO yum install docker-ce docker-ce-cli containerd.io
52-
53-
# elif [ ! -z $PACMAN_CMD ]; then
54-
# pacman -Sy git
55-
56-
# elif [ ! -z $DNF_CMD ]; then
57-
# $SUDO dnf install git
58-
59-
# elif [ ! -z $APK_CMD ]; then
60-
# $SUDO apk add git
61-
55+
6256
else
6357
echo "Couldn't install package"
6458
exit 1;
65-
fi
59+
fi

installers/docker/installer.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
name = "Docker"
2+
shortname = "docker"
3+
description = "Docker"
4+
15
[apt]
26
sh = """
37
@sudo apt-get update

installers/dunner/installer.toml

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)