-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget.sh
146 lines (128 loc) · 3.27 KB
/
get.sh
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
138
139
140
141
142
143
144
145
146
#!/bin/bash
# Setups a local 'oaf' folder to run the ojob command.
# Author: Nuno Aguiar
ARCH=${ARCH:-`uname -m`}
SYST=${SYST:-`uname -s`}
DIST=${DIST:-}
if [ ! -e /bin/bash ]
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'..."
/bin/bash -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
sed -i '1,/connection: close/d' $output
tail -n +2 $output > $output.temp
mv $output.temp $output
}
help() {
echo Done.
echo
echo To run just execute:
echo
echo " ---> $IPATH/ojob ojob.io <---"
echo
echo "To auto-complete 'ojob ojob.io' in bash just execute:"
echo
echo " export PATH=$(realpath $IPATH):\$PATH && . $IPATH/autoComplete.sh"
echo
echo --------------------------------------
}
# Determine architecture
case $ARCH in
x86_64)
if [ "$SYST" = "Darwin" ]
then
TARCH="M64"
IPATH=${IPATH:-/Applications/OpenAF}
else
TARCH="64"
fi
;;
aarch64_be | aarch64 | armv8b | armv8l | arm64)
if [ "$SYST" = "Darwin" ]
then
TARCH="MA"
IPATH=${IPATH:-/Applications/OpenAF}
else
TARCH="A64"
fi
;;
arm | armv7l)
TARCH="A32"
;;
*)
echo -n "Architecture $ARCH on $SYST not recognized."
esac
IPATH=${IPATH:-oaf}
# Downloads
# ---------
echo -----------------------
echo Creating sub-folder oaf
mkdir $IPATH
cd $IPATH
JAVA=false
if java -version >/dev/null 2>&1; then
JAVA=true
else
echo -------------------
echo Downloading java...
url=http://openaf.io/java/java17_$TARCH.tgz
output=jre.tgz
downloadURL
fi
echo ---------------------
echo Downloading openaf...
url=http://openaf.io/$DIST/openaf.jar
output=openaf.jar.orig
downloadURL
url=http://openaf.io/$DIST/openaf.jar.repacked
output=openaf.jar
downloadURL
url=http://ojob.io/autoComplete.sh
output=autoComplete.sh
downloadURL
echo ------------
echo Unpacking...
if [ "$JAVA" = "false" ]; then
tar xzf jre.tgz
mv *jdk* jre
`find . | egrep /bin/java$` -jar openaf.jar --install
rm jre.tgz
echo
help
else
java -jar openaf.jar --install
echo
help
fi