-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathibrafunc.sh
More file actions
executable file
·327 lines (306 loc) · 8.63 KB
/
ibrafunc.sh
File metadata and controls
executable file
·327 lines (306 loc) · 8.63 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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#!/bin/bash
######################################################################
# Title : IBRAFUNC - IBRAMENU functions
# By : Sycotix, DiscDuck, Taos15
# License : General Public License GPL-3.0-or-later
# Another fine product brought to you by IBRACORP™
######################################################################
# functions
# profile file
source /opt/ibracorp/ibramenu/.profile
if [ -f /opt/appdata/.traefik.env ]; then
source /opt/appdata/.traefik.env
fi
if [[ -n "${IBRAMENU_DOCKER_NETWORK:-}" ]]; then
dockernet="$IBRAMENU_DOCKER_NETWORK"
fi
log_debug() {
if [[ -n "${IBRAMENU_DEBUG:-}" ]]; then
mkdir -p /opt/appdata/ibramenu
echo "$(date -Iseconds) [DEBUG] $*" >>/opt/appdata/ibramenu/ibramenu.log
fi
}
require_command() {
local command_name=$1
if ! command -v "$command_name" >/dev/null 2>&1; then
msgbox "Missing dependency: $command_name"
echo "Please install '$command_name' and re-run ibramenu."
exit 1
fi
}
# message box
msgbox() {
# function expects a message and optional parameters
# msgbox <Text> <width of box> <horizontal character for the box> <vertical character for the box>
# If the box parameters are not given the full width will be used and = for horizontal and | for vertical character
# checking if message is specified
if [[ -z $1 ]]; then
message="Your message could be here"
else
message=$1
fi
# checking if message box width is specified
if [[ -z $2 ]]; then
box_width=$(tput cols)
else
box_width=$2
fi
# checking if horizontal character is specified
if [[ -z $3 ]]; then
box_hor="="
else
box_hor=$3
fi
# checking if vertical charater is specified
if [[ -z $4 ]]; then
box_vert="|"
else
box_vert=$4
fi
# calculating message box parameters
msg_length=${#message}
msg_half=$(($msg_length / 2))
msg_start=$(((($box_width - 2) / 2) - $msg_half))
msg_fill_left=$(($msg_start))
msg_fill_right=$((($box_width - 2) - $msg_start - $msg_length))
# generating strings for box
box_outline_hor=$(printf %"$box_width"s | tr ' ' "$box_hor")
msg_space_left=$(printf %"$msg_fill_left"s)
msg_space_right=$(printf %"$msg_fill_right"s)
# output
echo
echo $box_outline_hor
echo "$box_vert$msg_space_left$message$msg_space_right$box_vert"
echo $box_outline_hor
echo
}
# ibracorp logo
ibralogo() {
version=$(cat "/opt/ibracorp/ibramenu/version")
tput clear
tput bold
tput setaf 1
tee <<-EOF
___ ____ ____ _ ____ ___ ____ ____ ™
|_ _| __ )| _ \ / \ / ___/ _ \| _ \| _ \
| || _ \| |_) | / _ \| | | | | | |_) | |_) |
| || |_) | _ < / ___ \ |__| |_| | _ <| __/ Public
|___|____/|_| \_\/_/ \_\____\___/|_| \_\_| Version $version
$(lsb_release -sd) | CPU Threads: $(lscpu | grep "CPU(s):" | tail +1 | head -1 | awk '{print $2}') | IP: $(hostname -I | awk '{print $1}') | RAM: $(free -m | grep Mem | awk 'NR=1 {print $2}') MB
Become a Member and sponsor us: https://ibracorp.io/memberships
EOF
tput sgr0
}
# disclaimer
disclaimer() {
ibralogo
if [ -f "/opt/ibracorp/IBRADISCLAIMER" ]; then
if grep -q "IBRADISCLAIMER=accepted" "/opt/ibracorp/IBRADISCLAIMER"; then
:
# Has already been accepted
else
rm "/opt/ibracorp/IBRADISCLAIMER"
exit
fi
else
tee <<-EOF
Please take a moment and read our IBRACORP Disclaimer:
https://docs.ibracorp.io/ibracorp/
EOF
read -p "Do you accept our Disclaimer? y/N: " accept
case "$accept" in
[yY])
echo "Thank you for accepting the IBRACORP Disclaimer."
echo
stamp=$(date)
tee <<-EOF >/opt/ibracorp/IBRADISCLAIMER
IBRADISCLAIMER=accepted
$stamp
EOF
;;
*)
echo "IBRACORP Disclaimer has not been accepted. Exiting..."
echo
exit 0
;;
esac
fi
}
environment_check() {
require_command docker
require_command mdless
if ! docker compose version >/dev/null 2>&1; then
msgbox "Missing dependency: docker compose"
echo "Please install the Docker Compose plugin and re-run ibramenu."
exit 1
fi
if ! docker info >/dev/null 2>&1; then
msgbox "Docker daemon not accessible"
echo "Start the Docker daemon and ensure your user has Docker permissions."
exit 1
fi
# Check for environment files or otherwise create them with defaults
if [ ! -d "/opt/appdata" ]; then
mkdir -p /opt/appdata
fi
# Timezone
if [ ! -f "/opt/appdata/.timezone.env" ]; then
echo "TZ=UTC" >"/opt/appdata/.timezone.env"
fi
# PUID and PGID
if [ ! -f "/opt/appdata/.id.env" ]; then
echo "PUID=1000" >"/opt/appdata/.id.env"
echo "PGID=1000" >>"/opt/appdata/.id.env"
fi
# traefik environment
if [ ! -f "/opt/appdata/.traefik.env" ]; then
echo " " >"/opt/appdata/.traefik.env"
fi
# theme.park
if [ ! -f "/opt/appdata/.themepark.env" ]; then
echo "DOCKER_MODS=ghcr.io/gilbn/theme.park:\${TP_APP}" >"/opt/appdata/.themepark.env"
echo "TP_THEME=plex" >>"/opt/appdata/.themepark.env"
fi
if ! docker network inspect "$dockernet" >/dev/null 2>&1; then
msgbox "Creating Docker network: $dockernet"
docker network create "$dockernet" >/dev/null
fi
log_debug "Environment check complete. Network: $dockernet"
}
# launch docker compose container
launchdocker() {
target_folder=$1
if [ ! -d "$target_folder" ]; then
mkdir -p "$target_folder"
fi
cp -R * "$target_folder"
docker compose -f "$target_folder/compose.yaml" up -d
}
# display README.md
readme() {
if [ -f "README.md" ]; then
mdless -P "README.md"
read -p "Do you want to continue (y)? " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
return
else
return 1
fi
fi
}
# check if ibramenu is up-to-date
checkupdate() {
if [[ -n "${IBRAMENU_UPDATE_CHECKED:-}" ]]; then
return
fi
IBRAMENU_UPDATE_CHECKED=1
version=$(cat "/opt/ibracorp/ibramenu/version")
current=$(curl -fsSL --max-time 5 https://raw.githubusercontent.com/ibracorp/ibramenu/main/version || true)
if [[ -n "$current" && "$version" != "$current" ]]; then
msgbox "Your IBRAMENU is not up-to-date. Use 'ibraupdate' to update."
fi
}
# IBRACORP motd
ibramotd() {
if [ -d /etc/update-motd.d ]; then
chmod -x /etc/update-motd.d/* 2>/dev/null || true
fi
cat >/etc/update-motd.d/01-ibracorp <<'MOTDSCRIPT'
#!/bin/bash
######################################################################
# Title : IBRACORP MOTD
# By : Sycotix, DiscDuck, Taos15
# License : General Public License GPL-3.0-or-later
# Another fine product brought to you by IBRACORP
######################################################################
echo " ___ ____ ____ _ ____ ___ ____ ____ (tm)"
echo " |_ _| __ )| _ \ / \ / ___/ _ \| _ \| _ \ "
echo " | || _ \| |_) | / _ \| | | | | | |_) | |_) |"
echo " | || |_) | _ < / ___ \ |__| |_| | _ <| __/ "
echo " |___|____/|_| \_\/_/ \_\____\___/|_| \_\_| "
echo "$(lsb_release -sd 2>/dev/null || echo Linux) | CPU Threads: $(nproc) | IP: $(hostname -I | awk '{print $1}') | RAM: $(free -m | awk '/Mem/{print $2}') MB"
echo "Become a Member and sponsor us: https://ibracorp.io/memberships"
echo "Type 'ibramenu' to launch IBRAMENU."
MOTDSCRIPT
chmod +x /etc/update-motd.d/01-ibracorp
}
# App Greetings
appgreetings() {
ibralogo
msgbox "$title Installer"
}
# App
appcreate() {
msgbox "Installing $title..."
mkdir -p "/opt/appdata/$app" && cd "/opt/appdata/$app"
tee <<-EOF >.env
APP_NAME=$app
IMAGE=$image
TP_APP=$tp_app
PORTE=$porte
PORTI=$porti
PORTE2=$porte2
PORTI2=$porti2
PORTE3=$porte3
PORTI3=$porti3
EOF
tee <<-EOF >compose.yaml
services:
service-name:
image: \${IMAGE:?err}
container_name: \${APP_NAME:?err}
env_file:
- /opt/appdata/.id.env
- /opt/appdata/.timezone.env
- /opt/appdata/.traefik.env
EOF
if [ ! -z "$tp_app" ]; then
echo " - /opt/appdata/.themepark.env" >>compose.yaml
fi
if [ ! -z "$volumes" ]; then
echo "$volumes" >>compose.yaml
fi
if [ ! -z "$porti" ]; then
tee <<-EOF >>compose.yaml
ports:
- \${PORTE:?err}:\${PORTI:?err}
EOF
fi
if [ ! -z "$porti2" ]; then
tee <<-EOF >>compose.yaml
- \${PORTE2:?err}:\${PORTI2:?err}
EOF
fi
if [ ! -z "$porti3" ]; then
tee <<-EOF >>compose.yaml
- \${PORTE3:?err}:\${PORTI3:?err}
EOF
fi
tee <<-EOF >>compose.yaml
networks:
- $dockernet
restart: unless-stopped
security_opt:
- apparmor:unconfined
$extrapayload
networks:
$dockernet:
driver: bridge
external: true
EOF
docker compose up -d --force-recreate
}
# List Links
appfinalization() {
ibralogo
msgbox "All Done! Here is the link to $title:"
echo
ip=$(hostname -I | awk '{print $1}')
echo "$title: http://$ip:$porte/"
}
# App Complete
app() {
appgreetings
appcreate
appfinalization
}