-
Notifications
You must be signed in to change notification settings - Fork 50
/
install.sh
executable file
·213 lines (172 loc) · 5.7 KB
/
install.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/sh
SOURCE_DIR=/usr/src
LUA_VERSION=5.4.4
CWD=$(pwd)
install_luaoauth_var="false"
rhel_based="false"
debian_based="false"
alpine_based="false"
lua_installed="false"
lua_dep_dir=/usr/local/share/lua/5.4/
if [ -f /etc/redhat-release ]; then
echo "Red Hat based system detected"
rhel_based="true"
elif [ -f /etc/debian_version ]; then
echo "Debian based system detected"
debian_based="true"
elif [ -f /etc/alpine-release ]; then
echo "Alpine based system detected"
alpine_based="true"
fi
if [ ! -e $SOURCE_DIR ]; then
mkdir -p $SOURCE_DIR;
fi;
cd $SOURCE_DIR
display_working() {
pid=$1
spin='-\|/'
i=0
while kill -0 "$pid" 2>/dev/null
do
i=$(( (i+1) %4 ))
printf "\r${spin:$i:1}"
sleep .1
done
}
# ----------------------------
# Functions not currently used
# ----------------------------
download_rhel_lua() {
printf "\r[+] Downloading Lua\n"
cd $SOURCE_DIR
curl -sLO https://www.lua.org/ftp/lua-$LUA_VERSION.tar.gz
tar xf lua-$LUA_VERSION.tar.gz && rm lua-$LUA_VERSION.tar.gz
}
install_yum_deps() {
printf "\r[+] Installing yum dependencies\n"
yum -y install dnf gcc openssl-devel readline-devel systemd-devel unzip >/dev/null 2>&1
}
build_lua() {
printf "\r[+] Building Lua\n"
cd $SOURCE_DIR/lua-$LUA_VERSION
make linux test >/dev/null
}
install_rhel_lua() {
printf "\r[+] Installing Lua\n"
cd $SOURCE_DIR/lua-$LUA_VERSION
make install >/dev/null
}
install_deb_lua() {
printf "\r[+] Installing Lua\n"
apt-get update >/dev/null 2>&1
apt-get install -y software-properties-common unzip build-essential libssl-dev lua5.4 liblua5.4-dev >/dev/null 2>&1
}
install_alpine_lua() {
printf "\r[+] Installing Lua\n"
apk add --no-cache lua5.4 lua5.4-dev openssl-dev gcc libc-dev git make automake libtool curl unzip >/dev/null 2>&1
#?? build-base libc-dev liblua5.4-dev unzip
}
# ----------------------------
# ----------------------------
install_luaoauth_deps_alpine() {
printf "\r[+] Installing haproxy-lua-oauth dependencies\n"
if [ ! -e $lua_dep_dir ]; then
mkdir -p $lua_dep_dir;
fi;
apt-get update >/dev/null 2>&1
apk add --no-cache lua5.4 lua5.4-dev openssl-dev gcc libc-dev git make automake libtool curl unzip >/dev/null 2>&1
cd $SOURCE_DIR
curl -sLO https://github.com/rxi/json.lua/archive/refs/heads/master.zip
unzip -qo master.zip && rm master.zip
mv json.lua-master/json.lua $lua_dep_dir
curl -sLO https://github.com/lunarmodules/luasocket/archive/refs/heads/master.zip
unzip -qo master.zip && rm master.zip
cd luasocket-master/
make clean all install-both LUAINC=/usr/include/lua5.4/ >/dev/null
cd ..
curl -sLO https://github.com/wahern/luaossl/archive/refs/heads/master.zip
unzip -qo master.zip && rm master.zip
cd luaossl-master/
make install >/dev/null
cd ..
}
install_luaoauth_deps_debian() {
printf "\r[+] Installing haproxy-lua-oauth dependencies\n"
if [ ! -e $lua_dep_dir ]; then
mkdir -p $lua_dep_dir;
fi;
apt-get update >/dev/null 2>&1
apt-get install -y build-essential liblua5.4-dev libssl-dev unzip >/dev/null 2>&1
cd $SOURCE_DIR
curl -sLO https://github.com/rxi/json.lua/archive/refs/heads/master.zip
unzip -qo master.zip && rm master.zip
cp json.lua-master/json.lua $lua_dep_dir
curl -sLO https://github.com/lunarmodules/luasocket/archive/refs/heads/master.zip
unzip -qo master.zip && rm master.zip
cd luasocket-master/
make clean all install-both LUAINC=/usr/include/lua5.4/ >/dev/null
cd ..
curl -sLO https://github.com/wahern/luaossl/archive/refs/heads/master.zip
unzip -qo master.zip && rm master.zip
cd luaossl-master/
make install >/dev/null
cd ..
}
install_luaoauth_deps_rhel() {
printf "\r[+] Installing haproxy-lua-oauth dependencies\n"
if [ ! -e $lua_dep_dir ]; then
mkdir -p $lua_dep_dir;
fi;
yum -y install dnf
dnf -y install dnf-plugins-core
dnf config-manager --set-enabled powertools
dnf update >/dev/null 2>&1
dnf install -y gcc openssl-devel lua-devel make readline-devel systemd-devel unzip >/dev/null 2>&1
cd $SOURCE_DIR
curl -sLO https://github.com/rxi/json.lua/archive/refs/heads/master.zip
unzip -qo master.zip && rm master.zip
mv json.lua-master/json.lua $lua_dep_dir
curl -sLO https://github.com/lunarmodules/luasocket/archive/refs/heads/master.zip
unzip -qo master.zip && rm master.zip
cd luasocket-master/
make clean all install-both LUAINC=/usr/include/ >/dev/null
cd ..
curl -sLO https://github.com/wahern/luaossl/archive/rel-20181207.zip
unzip -qo rel-20181207.zip && rm rel-20181207.zip
cd luaossl-rel-20181207/
make install >/dev/null
cd ..
}
install_luaoauth() {
printf "\r[+] Installing haproxy-lua-oauth\n"
if [ ! -e $lua_dep_dir ]; then
mkdir -p $lua_dep_dir;
fi;
cp "$CWD"/lib/*.lua $lua_dep_dir
}
case $1 in
luaoauth)
install_luaoauth_var="true"
;;
*)
echo "Usage: install.sh luaoauth"
exit 1
;;
esac
echo "$rhel_based"
if $install_luaoauth_var; then
if $rhel_based; then
echo "RHEL based system detected"
download_and_install_luaoauth="install_luaoauth_deps_rhel install_luaoauth"
elif $debian_based; then
echo "Debian based system detected"
download_and_install_luaoauth="install_luaoauth_deps_debian install_luaoauth"
elif $alpine_based; then
echo "Alpine based system detected"
download_and_install_luaoauth="install_luaoauth_deps_alpine install_luaoauth"
fi
for func in $download_and_install_luaoauth; do
"$func" &
display_working "$!"
done
fi