Skip to content

Commit f71ea5f

Browse files
committed
Adding the installer generator and a sample file
1 parent e6b9994 commit f71ea5f

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

generate.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import toml
2+
import sys
3+
4+
methods = {
5+
"apt": "$APT_GET",
6+
"yum": "$YUM",
7+
"dnf": "$DNF",
8+
"apk": "$APK",
9+
"pacman": "$PACMAN"
10+
}
11+
12+
def get_method_case(method):
13+
return "[ ! -z "+methods[method]+"_CMD ]; then\n"
14+
15+
for path in sys.argv[1:]:
16+
17+
installer_toml_path = path+"/installer.toml"
18+
installer_sh_path = path+"/installer.sh"
19+
20+
installer_toml = open(installer_toml_path, "r")
21+
parsed_toml = toml.loads(installer_toml.read())
22+
23+
installer_sh = open(installer_sh_path, "w")
24+
25+
installer_sh.write("""#!/bin/sh
26+
27+
YUM_CMD=$(which yum) # yum package manager for RHEL & CentOS
28+
DNF_CMD=$(which dnf) # dnf package manager for new RHEL & CentOS
29+
APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian based distributions
30+
PACMAN_CMD=$(which pacman) # pacman package manager for ArchLinux
31+
APK_CMD=$(which apk) # apk package manager for Alpine
32+
33+
""")
34+
35+
seperator = "if"
36+
37+
for section in parsed_toml:
38+
lines = parsed_toml[section]['sh']
39+
installer_sh.write(seperator+" "+get_method_case(section))
40+
for line in lines.split("\n"):
41+
installer_sh.write(" "+line+"\n")
42+
seperator = "elif"
43+
44+
installer_sh.write("""
45+
else
46+
echo "Couldn't install package"
47+
exit 1;
48+
fi
49+
""".strip())
50+
51+
52+
installer_sh.close()

installers/hello/installer.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
14+
[apk]
15+
sh = """
16+
echo "Installing hello"
17+
echo "Installed hello"
18+
"""

0 commit comments

Comments
 (0)