-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetStatic.sh
More file actions
137 lines (121 loc) · 3.44 KB
/
getStatic.sh
File metadata and controls
137 lines (121 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
# Setups a static file to run the ojob command.
# Author: Nuno Aguiar
ARCH=${ARCH:-`uname -m`}
SYST=${SYST:-`uname -s`}
MUSL=${MUSL:-`cat /etc/*-release | grep -q "Alpine" && echo 'alpine'`}
DIST=${DIST:-}
PBSH=${PBSH:-/bin/bash}
if [ ! -e $PBSH ]
then
echo bash is needed to run this script
exit 1
fi
parseURL() {
# Parse protocol
proto=$(echo $_url | grep :// | sed -e's,^\(.*://\).*,\1,g')
_url=$(echo $_url | sed -e"s,$proto,,g")
# Parse user / host / port
user="$(echo $_url | grep @ | cut -d@ -f1)"
hostport=$(echo $_url | sed -e"s,$user@,,g" | cut -d/ -f1)
host="$(echo $hostport | sed -e 's,:.*,,g')"
port="$(echo $hostport | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g')"
# Transform the protocol into lowercase
proto=$(echo $proto | tr '[:upper:]' '[:lower:]')
# Determine the port
if [ "$host" = "$port" ]; then
if [ "$proto" = "http://" ]; then
port=80
fi
if [ "$proto" = "https://" ]; then
port=443
echo "WARNING: https is not supported through this download method. Try using http if possible."
fi
fi
uri="$(echo $_url | grep / | cut -d/ -f2-)"
file="$(echo $uri | sed -e 's/.*\///')"
if [ "$file" = "" ]; then
file=output.bin
fi
#echo "(parsedInput: (protocol: '$proto', host: '$host', port: '$port', uri: '$uri', file: '$file'))"
}
downloadURL() {
parseURL
echo "Downloading from '$proto$_url' to '$_output'..."
#echo "host = $host | port = $port | uri = $uri | output = $_output | PBSH = $PBSH"
$PBSH -c "exec 3<>/dev/tcp/$host/$port && echo -e \"GET /$uri HTTP/1.1\nHost: $host\nUser-Agent: curl\nConnection: close\n\n\" >&3 && cat <&3" > "$_output"
# Strip HTTP headers only when present, without running sed over binary payloads.
# This avoids BSD sed "illegal byte sequence" errors and preserves embedded tar.gz data.
if LC_ALL=C head -n 1 "$_output" | grep -q '^HTTP/[0-9]'; then
{
while IFS= read -r _line || [ -n "$_line" ]; do
_line=${_line%$'\r'}
[ -z "$_line" ] && break
done
cat
} < "$_output" > "$_output.temp"
mv "$_output.temp" "$_output"
fi
}
help() {
echo Done.
echo
echo To run just execute:
echo
echo " ---> ./ojob ojob.io <---"
echo
echo "To auto-complete 'ojob ojob.io' in bash just execute:"
echo
echo " export PATH=$(pwd):\$PATH && . $(pwd)/ojobAutoComplete.sh"
echo
echo --------------------------------------
./oaf --repack
}
# Determine architecture
case $ARCH in
x86_64)
if [ "$SYST" = "Darwin" ]
then
TARCH="mac-x86_64"
else
if [ "$MUSL" = "alpine" ]
then
TARCH="alpine-x86_64"
else
TARCH="linux-x86_64"
fi
fi
;;
aarch64_be | aarch64 | armv8b | armv8l | arm64)
if [ "$SYST" = "Darwin" ]
then
TARCH="mac-aarch64"
else
if [ "$MUSL" = "alpine" ]
then
TARCH="alpine-aarch64"
else
TARCH="linux-aarch64"
fi
fi
;;
*)
echo -n "Architecture $ARCH on $SYST not recognized."
esac
# Downloads
# ---------
echo ---------------------
echo Downloading openaf...
_url=http://openaf.io/${DIST:+${DIST}/}oaf-$TARCH
_output=oaf-$TARCH
downloadURL
_url=http://ojob.io/autoComplete.sh
_output=ojobAutoComplete.sh
downloadURL
chmod u+x oaf-$TARCH
./oaf-$TARCH
if [ $? -ne 0 ]; then
echo "ERROR: oaf-$TARCH failed to run."
exit 1
fi
help