Skip to content

Commit b1bfda6

Browse files
committed
Merge branch 'master' of github.com:Heshdude/installer.to into update-docker-description
2 parents ff21edf + 0d8b8f2 commit b1bfda6

19 files changed

+383
-71
lines changed

functions/index.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,30 @@ const storage = new Storage();
1010
const bucket = storage.bucket('installer-to.appspot.com');
1111

1212
app.get('/', (req, res) => {
13-
res.json({ status: 'OK' });
13+
res.set('Content-Type', 'application/json');
14+
res.json({ status: 'OK' });
15+
});
16+
17+
app.get('/health', (req, res) => {
18+
res.set('Content-Type', 'application/json');
19+
res.json({ status: 'OK' });
1420
});
1521

1622
app.get('/:package', (req, res) => {
1723
try {
18-
const file = bucket.file(req.params.package + '/installer.sh');
24+
const minParam = req.query.min;
25+
const withParam = req.query.with;
26+
const fileName = ['installer'];
27+
28+
if (minParam){
29+
fileName.push('min');
30+
}
31+
if (withParam){
32+
fileName.push(withParam);
33+
}
34+
fileName.push('sh');
35+
const fileNameString = fileName.join(".");
36+
const file = bucket.file(req.params.package + '/'+fileNameString);
1937
res.set('Content-Type', 'text/plain');
2038
const readStream = file.createReadStream();
2139
readStream.pipe(res);

generate.py

Lines changed: 106 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
import re
88

99
methods = {
10-
"curl": "$CURL",
11-
"apt": "$APT_GET",
12-
"yum": "$YUM",
13-
"dnf": "$DNF",
14-
"apk": "$APK",
15-
"pacman": "$PACMAN",
16-
"git": "$GIT"
10+
"curl": "$CURL",
11+
"apt": "$APT_GET",
12+
"yum": "$YUM",
13+
"dnf": "$DNF",
14+
"apk": "$APK",
15+
"pacman": "$PACMAN",
16+
"git": "$GIT"
1717
}
18+
1819
def update_readme(summary):
1920
writer = pytablewriter.MarkdownTableWriter()
2021
writer.headers = ["Tool", "Apt", "Yum", "Packman", "APK", "DNF", "CURL", "URL"]
@@ -29,7 +30,7 @@ def update_readme(summary):
2930
apk = "Yes" if "apk" in installers else "No"
3031
dnf = "Yes" if "dnf" in installers else "No"
3132
curl = "Yes" if "curl" in installers else "No"
32-
url = "https://installer.to/"+tool_shortname
33+
url = "https://installer.to/" + tool_shortname
3334
value_matrix.append([name, apt, yum, pacman, apk, dnf, curl, url])
3435

3536
writer.value_matrix = value_matrix
@@ -39,14 +40,14 @@ def update_readme(summary):
3940
readme = readme_md.read()
4041
beggining = "<!-- beginning of tools list -->"
4142
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)
43+
regex = r"" + beggining + "\n(.*)\n" + end
44+
readme = re.sub(regex, beggining + "\n" + table_md + "\n" + end, readme, flags=re.S)
4445
readme_md.seek(0) # sets point at the beginning of the file
4546
readme_md.truncate() # Clear previous content
4647
readme_md.write(readme)
4748
readme_md.close()
4849
except Error as e:
49-
logging.error('Error occurred when trying to update README.md, error: '+ e)
50+
logging.error('Error occurred when trying to update README.md, error: ' + e)
5051

5152

5253
def update_summary(name, shortname, description, installers):
@@ -67,43 +68,40 @@ def update_summary(name, shortname, description, installers):
6768

6869
update_readme(parsed_summary_toml)
6970
except IOError as e:
70-
logging.error('Error occurred when trying to update installers.toml, error: '+ e)
71+
logging.error('Error occurred when trying to update installers.toml, error: ' + e)
7172

7273
def get_method_case(method):
73-
if method in methods:
74-
return "[ ! -z "+methods[method]+"_CMD ]; then\n"
75-
else:
76-
logging.error('Unpupported method in the TOML file, method: '+method)
77-
exit(1)
74+
if method in methods:
75+
return "[ ! -z " + methods[method] + "_CMD ]; then\n"
76+
else:
77+
logging.error('Unpupported method in the TOML file, method: ' + method)
78+
exit(1)
79+
7880

7981
def parse_line(line):
80-
line = line\
81-
.replace('@sudo', '$SUDO')\
82-
.replace('@log', 'info')\
83-
.replace('@info', 'info')\
84-
.replace('@warn', 'warn')\
82+
line = line \
83+
.replace('@sudo', '$SUDO') \
84+
.replace('@log', 'info') \
85+
.replace('@info', 'info') \
86+
.replace('@warn', 'warn') \
8587
.replace('@error', 'error')
8688
return line
8789

88-
def generate(path):
89-
installer_methods = [ ]
90-
installer_toml_path = path+"/installer.toml"
91-
installer_sh_path = path+"/installer.sh"
92-
93-
installer_toml = open(installer_toml_path, "r")
94-
parsed_toml = toml.loads(installer_toml.read())
95-
try:
96-
with open(installer_sh_path, "w") as installer_sh:
9790

98-
installer_sh.write("""#!/bin/sh
99-
91+
def write_sniffer_commands(sh_file):
92+
sh_file.write("""
10093
CURL_CMD=$(which curl)
10194
YUM_CMD=$(which yum)
10295
DNF_CMD=$(which dnf)
10396
APT_GET_CMD=$(which apt-get)
10497
PACMAN_CMD=$(which pacman)
10598
APK_CMD=$(which apk)
10699
GIT_CMD=$(which git)
100+
""")
101+
102+
103+
def write_sudo_fix_commands(sh_file):
104+
sh_file.write("""
107105
SUDO_CMD=$(which sudo)
108106
109107
USER="$(id -un 2>/dev/null || true)"
@@ -119,7 +117,11 @@ def generate(path):
119117
exit 1
120118
fi
121119
fi
120+
""")
122121

122+
123+
def write_logger_commands(sh_file):
124+
sh_file.write("""
123125
RESET='\033[0m'
124126
RED='\033[0;31m'
125127
GREEN='\033[0;32m'
@@ -139,42 +141,82 @@ def generate(path):
139141
140142
""")
141143

142-
seperator = "if"
143-
144-
for section in parsed_toml:
145-
if not isinstance(parsed_toml[section], dict):
146-
continue
147-
if parsed_toml[section]['sh'] is "":
148-
continue
149-
installer_methods.append(section)
150-
lines = parsed_toml[section]['sh']
151-
installer_sh.write(seperator+" "+get_method_case(section))
152-
for line in lines.split("\n"):
153-
step = parse_line(line)
154-
installer_sh.write(" "+step+"\n")
155-
seperator = "elif"
156-
157-
installer_sh.write("""
144+
145+
def write_installer_commands(sh_file, lines, indent=""):
146+
for line in lines.split("\n"):
147+
step = parse_line(line)
148+
sh_file.write(indent + step + "\n")
149+
150+
def generate_individual_installers(method, lines):
151+
installer_sh_path = path + "/installer."+method+".sh"
152+
try:
153+
with open(installer_sh_path, "w") as installer_sh:
154+
installer_sh.write("""#!/bin/sh
155+
""")
156+
write_sudo_fix_commands(installer_sh)
157+
write_logger_commands(installer_sh)
158+
write_installer_commands(installer_sh, lines)
159+
160+
except IOError as x:
161+
if x.errno == errno.EACCES:
162+
logging.error('No enough permissions to write to ' + installer_sh_path)
163+
exit(1)
164+
else:
165+
logging.error('Something went wrong when trying to write to ' + installer_sh_path, x)
166+
exit(1)
167+
168+
def generate(path):
169+
installer_methods = []
170+
installer_toml_path = path + "/installer.toml"
171+
installer_sh_path = path + "/installer.sh"
172+
173+
installer_toml = open(installer_toml_path, "r")
174+
parsed_toml = toml.loads(installer_toml.read())
175+
try:
176+
with open(installer_sh_path, "w") as installer_sh:
177+
178+
installer_sh.write("""#!/bin/sh
179+
180+
""")
181+
write_sniffer_commands(installer_sh)
182+
write_sudo_fix_commands(installer_sh)
183+
write_logger_commands(installer_sh)
184+
185+
seperator = "if"
186+
187+
for section in parsed_toml:
188+
if not isinstance(parsed_toml[section], dict):
189+
continue
190+
if parsed_toml[section]['sh'] is "":
191+
continue
192+
installer_methods.append(section)
193+
lines = parsed_toml[section]['sh']
194+
installer_sh.write(seperator + " " + get_method_case(section))
195+
write_installer_commands(installer_sh, lines, " ")
196+
generate_individual_installers(section, lines)
197+
seperator = "elif"
198+
199+
installer_sh.write("""
158200
else
159201
echo "Couldn't install package"
160202
exit 1;
161203
fi
162-
""".strip())
204+
""".strip())
163205

164-
installer_sh.close()
165-
update_summary(parsed_toml['name'], parsed_toml['shortname'], parsed_toml['description'], installer_methods)
206+
installer_sh.close()
207+
update_summary(parsed_toml['name'], parsed_toml['shortname'], parsed_toml['description'], installer_methods)
166208

167-
except IOError as x:
168-
if x.errno == errno.EACCES:
169-
logging.error('No enough permissions to write to '+installer_sh_path)
170-
exit(1)
171-
else:
172-
logging.error('Something went wrong when trying to write to '+installer_sh_path)
173-
exit(1)
209+
except IOError as x:
210+
if x.errno == errno.EACCES:
211+
logging.error('No enough permissions to write to ' + installer_sh_path)
212+
exit(1)
213+
else:
214+
logging.error('Something went wrong when trying to write to ' + installer_sh_path, x)
215+
exit(1)
174216

175217
for path in sys.argv[1:]:
176-
if os.path.exists(path+'/installer.toml'):
177-
logging.info('Generating installer.sh for '+path)
178-
generate(path)
179-
else:
180-
logging.warn('Could not find an installer.toml in '+path)
218+
if os.path.exists(path + '/installer.toml'):
219+
logging.info('Generating installer.sh for ' + path)
220+
generate(path)
221+
else:
222+
logging.warn('Could not find an installer.toml in ' + path)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
;SUDO_CMD=$(which sudo);;USER="$(id -un 2>/dev/null || true)";SUDO='';if [ "$USER" != 'root' ]; then;if [ ! -z $SUDO_CMD ]; then;SUDO='sudo';else cat >&2 <<-'EOF';Error: this installer needs the ability to run commands as root.;We are unable to find "sudo". Make sure its available to make this happen;EOF;exit 1;fi;fi;;RESET='';RED='';GREEN='';YELLOW='';log () { echo "[`date "+%Y.%m.%d-%H:%M:%S%Z"`]$1 $2"; };info () { log "$GREEN INFO$RESET $1"; };warn () { log "$YELLOW WARN$RESET $1"; };error () { log "$RED ERROR$RESET $1"; };;info "Downloading eksctl";$SUDO curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp;info "Setting up at /usr/local/bin/eksctl";$SUDO mv /tmp/eksctl /usr/local/bin;$SUDO rm /tmp/eksctl;;;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
3+
SUDO_CMD=$(which sudo)
4+
5+
USER="$(id -un 2>/dev/null || true)"
6+
SUDO=''
7+
if [ "$USER" != 'root' ]; then
8+
if [ ! -z $SUDO_CMD ]; then
9+
SUDO='sudo'
10+
else
11+
cat >&2 <<-'EOF'
12+
Error: this installer needs the ability to run commands as root.
13+
We are unable to find "sudo". Make sure its available to make this happen
14+
EOF
15+
exit 1
16+
fi
17+
fi
18+
19+
RESET=''
20+
RED=''
21+
GREEN=''
22+
YELLOW=''
23+
log () {
24+
echo "[`date "+%Y.%m.%d-%H:%M:%S%Z"`]$1 $2"
25+
}
26+
info () {
27+
log "$GREEN INFO$RESET $1"
28+
}
29+
warn () {
30+
log "$YELLOW WARN$RESET $1"
31+
}
32+
error () {
33+
log "$RED ERROR$RESET $1"
34+
}
35+
36+
info "Downloading eksctl"
37+
$SUDO curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
38+
info "Setting up at /usr/local/bin/eksctl"
39+
$SUDO mv /tmp/eksctl /usr/local/bin
40+
$SUDO rm /tmp/eksctl
41+

installers/eksctl/installer.min.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/sh
2-
;CURL_CMD=$(which curl);YUM_CMD=$(which yum);DNF_CMD=$(which dnf);APT_GET_CMD=$(which apt-get);PACMAN_CMD=$(which pacman);APK_CMD=$(which apk);GIT_CMD=$(which git);SUDO_CMD=$(which sudo);;USER="$(id -un 2>/dev/null || true)";SUDO='';if [ "$USER" != 'root' ]; then;if [ ! -z $SUDO_CMD ]; then;SUDO='sudo';else cat >&2 <<-'EOF';Error: this installer needs the ability to run commands as root.;We are unable to find "sudo". Make sure its available to make this happen;EOF;exit 1;fi;fi;;RESET='';RED='';GREEN='';YELLOW='';log () { echo "[`date "+%Y.%m.%d-%H:%M:%S%Z"`]$1 $2"; };info () { log "$GREEN INFO$RESET $1"; };warn () { log "$YELLOW WARN$RESET $1"; };error () { log "$RED ERROR$RESET $1"; };;if [ ! -z $CURL_CMD ]; then;info "Downloading eksctl";$SUDO curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp;info "Setting up at /usr/local/bin/eksctl";$SUDO mv /tmp/eksctl /usr/local/bin;$SUDO rm /tmp/eksctl;;else echo "Couldn't install package";exit 1;;fi;
2+
;;CURL_CMD=$(which curl);YUM_CMD=$(which yum);DNF_CMD=$(which dnf);APT_GET_CMD=$(which apt-get);PACMAN_CMD=$(which pacman);APK_CMD=$(which apk);GIT_CMD=$(which git);;SUDO_CMD=$(which sudo);;USER="$(id -un 2>/dev/null || true)";SUDO='';if [ "$USER" != 'root' ]; then;if [ ! -z $SUDO_CMD ]; then;SUDO='sudo';else cat >&2 <<-'EOF';Error: this installer needs the ability to run commands as root.;We are unable to find "sudo". Make sure its available to make this happen;EOF;exit 1;fi;fi;;RESET='';RED='';GREEN='';YELLOW='';log () { echo "[`date "+%Y.%m.%d-%H:%M:%S%Z"`]$1 $2"; };info () { log "$GREEN INFO$RESET $1"; };warn () { log "$YELLOW WARN$RESET $1"; };error () { log "$RED ERROR$RESET $1"; };;if [ ! -z $CURL_CMD ]; then;info "Downloading eksctl";$SUDO curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp;info "Setting up at /usr/local/bin/eksctl";$SUDO mv /tmp/eksctl /usr/local/bin;$SUDO rm /tmp/eksctl;;else echo "Couldn't install package";exit 1;;fi;

installers/eksctl/installer.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/bin/sh
22

3+
34
CURL_CMD=$(which curl)
45
YUM_CMD=$(which yum)
56
DNF_CMD=$(which dnf)
67
APT_GET_CMD=$(which apt-get)
78
PACMAN_CMD=$(which pacman)
89
APK_CMD=$(which apk)
910
GIT_CMD=$(which git)
11+
1012
SUDO_CMD=$(which sudo)
1113

1214
USER="$(id -un 2>/dev/null || true)"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
;SUDO_CMD=$(which sudo);;USER="$(id -un 2>/dev/null || true)";SUDO='';if [ "$USER" != 'root' ]; then;if [ ! -z $SUDO_CMD ]; then;SUDO='sudo';else cat >&2 <<-'EOF';Error: this installer needs the ability to run commands as root.;We are unable to find "sudo". Make sure its available to make this happen;EOF;exit 1;fi;fi;;RESET='';RED='';GREEN='';YELLOW='';log () { echo "[`date "+%Y.%m.%d-%H:%M:%S%Z"`]$1 $2"; };info () { log "$GREEN INFO$RESET $1"; };warn () { log "$YELLOW WARN$RESET $1"; };error () { log "$RED ERROR$RESET $1"; };;$SUDO apk add py3-pip;;;

installers/pip3/installer.apk.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/sh
2+
3+
SUDO_CMD=$(which sudo)
4+
5+
USER="$(id -un 2>/dev/null || true)"
6+
SUDO=''
7+
if [ "$USER" != 'root' ]; then
8+
if [ ! -z $SUDO_CMD ]; then
9+
SUDO='sudo'
10+
else
11+
cat >&2 <<-'EOF'
12+
Error: this installer needs the ability to run commands as root.
13+
We are unable to find "sudo". Make sure its available to make this happen
14+
EOF
15+
exit 1
16+
fi
17+
fi
18+
19+
RESET=''
20+
RED=''
21+
GREEN=''
22+
YELLOW=''
23+
log () {
24+
echo "[`date "+%Y.%m.%d-%H:%M:%S%Z"`]$1 $2"
25+
}
26+
info () {
27+
log "$GREEN INFO$RESET $1"
28+
}
29+
warn () {
30+
log "$YELLOW WARN$RESET $1"
31+
}
32+
error () {
33+
log "$RED ERROR$RESET $1"
34+
}
35+
36+
$SUDO apk add py3-pip
37+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
;SUDO_CMD=$(which sudo);;USER="$(id -un 2>/dev/null || true)";SUDO='';if [ "$USER" != 'root' ]; then;if [ ! -z $SUDO_CMD ]; then;SUDO='sudo';else cat >&2 <<-'EOF';Error: this installer needs the ability to run commands as root.;We are unable to find "sudo". Make sure its available to make this happen;EOF;exit 1;fi;fi;;RESET='';RED='';GREEN='';YELLOW='';log () { echo "[`date "+%Y.%m.%d-%H:%M:%S%Z"`]$1 $2"; };info () { log "$GREEN INFO$RESET $1"; };warn () { log "$YELLOW WARN$RESET $1"; };error () { log "$RED ERROR$RESET $1"; };;$SUDO apt-get update;$SUDO apt install python3-pip;;;

0 commit comments

Comments
 (0)