Skip to content

Commit 8c1e85e

Browse files
committed
Adding generating Summary installers.toml and updating the README.md
1 parent 0199e4d commit 8c1e85e

File tree

11 files changed

+218
-49
lines changed

11 files changed

+218
-49
lines changed

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@ 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+
32+
<!-- 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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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"

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 = """

installers/nginx/installer.sh

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/bin/sh
22

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
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,6 +23,23 @@ 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 nginx

installers/nginx/installer.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
name = "Nginx"
2+
shortname = "nginx"
3+
description = "Nginx server"
4+
5+
16
[apt]
27
sh = """
38
sudo apt-get update

installers/node/installer.sh

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

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
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,26 +23,43 @@ 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
if [ -n "$(uname -a | grep Ubuntu)" ]; then
28-
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
29-
sudo apt-get install -y nodejs
45+
curl -sL https://deb.nodesource.com/setup_12.x | $SUDO -E bash -
46+
$SUDO apt-get install -y nodejs
3047
else
3148
curl -sL https://deb.nodesource.com/setup_12.x | bash -
32-
sudo apt-get install -y nodejs
49+
$SUDO apt-get install -y nodejs
3350
fi
3451

3552
elif [ ! -z $YUM_CMD ]; then
36-
sudo yum install nodejs12
53+
$SUDO yum install nodejs12
3754

3855
elif [ ! -z $DNF_CMD ]; then
39-
sudo dnf install -y gcc-c++ make
40-
curl -sL https://rpm.nodesource.com/setup_12.x | sudo -E bash -
41-
sudo dnf install nodejs
56+
$SUDO dnf install -y gcc-c++ make
57+
curl -sL https://rpm.nodesource.com/setup_12.x | $SUDO -E bash -
58+
$SUDO dnf install nodejs
4259

4360
elif [ ! -z $APK_CMD ]; then
44-
sudo apk update
45-
sudo apk add nodejs
61+
$SUDO apk update
62+
$SUDO apk add nodejs
4663

4764
else
4865
echo "Couldn't install package"

installers/node/installer.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
name = "NodeJS"
2+
shortname = "node"
3+
description = "NodeJs v12"
4+
15
[apt]
26
sh = """
37
if [ -n "$(uname -a | grep Ubuntu)" ]; then

0 commit comments

Comments
 (0)