Skip to content

Commit 3fbc1b5

Browse files
authored
Merge pull request #11 from Heshdude/generate-summary-and-update-readme
Generate summary and update README
2 parents ed3fe57 + 9f6f90f commit 3fbc1b5

File tree

16 files changed

+423
-49
lines changed

16 files changed

+423
-49
lines changed

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +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 | WIP | https://installer.to/docker |
27-
| Kubectl | 👍 | WIP | WIP | WIP | https://installer.to/kubectl |
28-
| NVM | WIP | WIP | WIP | WIP | https://installer.to/nvm |
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 |Yes|Yes|Yes |Yes|Yes|No |https://installer.to/hlf |
33+
34+
<!-- end of tools list -->

generate.py

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import logging
55
import errno
66
import constants
7+
import pytablewriter
8+
import re
79

810
print (constants.CURL_CHECK)
911

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

2079
def get_method_case(method):
2180
if method in methods:
@@ -34,7 +93,7 @@ def parse_line(line):
3493
return line
3594

3695
def generate(path):
37-
96+
installer_methods = [ ]
3897
installer_toml_path = path+"/installer.toml"
3998
installer_sh_path = path+"/installer.sh"
4099

@@ -90,6 +149,11 @@ def generate(path):
90149
seperator = "if"
91150

92151
for section in parsed_toml:
152+
if not isinstance(parsed_toml[section], dict):
153+
continue
154+
if parsed_toml[section]['sh'] is "":
155+
continue
156+
installer_methods.append(section)
93157
lines = parsed_toml[section]['sh']
94158
installer_sh.write(seperator+" "+get_method_case(section))
95159
for line in lines.split("\n"):
@@ -105,6 +169,8 @@ def generate(path):
105169
""".strip())
106170

107171
installer_sh.close()
172+
update_summary(parsed_toml['name'], parsed_toml['shortname'], parsed_toml['description'], installer_methods)
173+
print("installer_methods",installer_methods)
108174

109175
except IOError as x:
110176
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 = "apt,yum,pacman,dnf,apk"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/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
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
25+
26+
if [ ! -z $APT_GET_CMD ]; then
27+
$SUDO apt-get update
28+
$SUDO apt-get install curl
29+
$SUDO curl -L "https://github.com/docker/compose/releases/download/1.26.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
30+
$SUDO chmod +x /usr/local/bin/docker-compose
31+
32+
elif [ ! -z $YUM_CMD ]; then
33+
$SUDO yum install curl
34+
$SUDO curl -L "https://github.com/docker/compose/releases/download/1.26.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
35+
$SUDO chmod +x /usr/local/bin/docker-compose
36+
37+
else
38+
echo "Couldn't install package"
39+
exit 1;
40+
fi

installers/docker/installer.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/sh
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)
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
25+
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+
43+
if [ ! -z $APT_GET_CMD ]; then
44+
$SUDO apt-get update
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+
51+
elif [ ! -z $YUM_CMD ]; then
52+
$SUDO yum install -y yum-utils
53+
$SUDO yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
54+
$SUDO yum install docker-ce docker-ce-cli containerd.io
55+
56+
else
57+
echo "Couldn't install package"
58+
exit 1;
59+
fi

installers/docker/installer.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name = "Docker"
2+
shortname = "docker"
3+
description = "Docker"
4+
5+
[apt]
6+
sh = """
7+
@sudo apt-get update
8+
@sudo apt-get install apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
9+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
10+
@sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
11+
@sudo apt-get update
12+
@sudo apt-get install docker-ce docker-ce-cli containerd.io
13+
"""
14+
15+
[yum]
16+
sh = """
17+
@sudo yum install -y yum-utils
18+
@sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
19+
@sudo yum install docker-ce docker-ce-cli containerd.io
20+
"""
21+

installers/git/installer.sh

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/bin/sh
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)
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,23 +23,40 @@ 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
2845
$SUDO apt-get install git
29-
46+
3047
elif [ ! -z $YUM_CMD ]; then
3148
$SUDO yum install git
32-
49+
3350
elif [ ! -z $PACMAN_CMD ]; then
3451
pacman -Sy git
35-
52+
3653
elif [ ! -z $DNF_CMD ]; then
3754
$SUDO dnf install git
38-
55+
3956
elif [ ! -z $APK_CMD ]; then
4057
$SUDO apk add git
41-
58+
4259
else
4360
echo "Couldn't install package"
4461
exit 1;
45-
fi
62+
fi

installers/git/installer.toml

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

installers/hello/installer.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# @info "This is an info log"
55
# @warn "This is an warn log"
66
# @error "This is an error log"
7+
name = "Hello"
8+
shortname = "hello"
9+
description = "This is just a sample tool"
710

811
[apt]
912
sh = """

0 commit comments

Comments
 (0)