forked from jfroment/seedbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig-updater.sh
executable file
·120 lines (105 loc) · 3.49 KB
/
config-updater.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
#!/bin/bash
set -e
################################################################################
### === config-updater.sh === ###
### Script which takes as input the old format config file (services.conf) ###
### and transforms it in the new format in yaml, using jq and yq ###
################################################################################
cleanup_on_exit() {
rm -f tmp.json config.json
}
trap cleanup_on_exit EXIT
# Load common functions
source config/tools.sh
# Check that required tools are installed
check_utilities
if [[ ! -f services.conf ]]; then
echo "[$0] ERROR. Could nof find services.conf. Exiting."
exit 1
fi
jq -n '{"services": []}' > config.json
# First, add Traefik as it was not explicitely set by default in old config file (services.conf)
if ! grep -q "traefik" services.conf; then
jq -r '.services[.services| length] |= . +
{
"name": "traefik",
"enabled": true,
"traefik": {
"enabled": true,
"rules": [
{
"host": "traefik.'$(echo '${TRAEFIK_DOMAIN}')'",
"service": "api@internal",
"httpAuth": true,
}
]
}
}' config.json > tmp.json
rm -f config.json
mv tmp.json config.json
fi
cat services.conf | while read line || [[ -n $line ]]; do
key=$(echo $line | sed -r "s/^(.*):.*$/\1/")
enabled="true"
if grep -q "disable" <<< $line; then
enabled="false"
fi
# Compatibility for services.conf already on dev (with temporary syntax -vpn)
if grep -q "\-vpn" <<< $line; then continue; fi
enableVpn="false"
# If this service is disabled AND another one in the file is enabled with VPN mode, keep that information
if grep -q "$key-vpn: enable" services.conf; then
if [[ enabled="false" ]]; then
#echo "[$0] $key => another service detected enabled with vpn..."
enableVpn="true"
enabled="true"
fi
fi
if grep -q "\-hardware-transcoding" <<< $line; then continue; fi
# Define if Traefik should be enabled on the service
case $key in
flaresolverr|gluetun)
enableTraefik="false"
rules=$(jq -n '[]')
;;
*)
enableTraefik="true"
# If Traefik enabled => define if http auth Traefik middleware must be set by default
case $key in
kavita|komga|nextcloud|ombi|overseerr|plex|portainer|tautulli)
defaultHttpAuth="false"
;;
*)
defaultHttpAuth="true"
;;
esac
# Define scheme // For nextcloud, scheme must be https
internalScheme="http"
[[ $key == "nextcloud" ]] && internalScheme="https"
# Define service default port from bundled config file
internalPort=$(cat config/ports | { grep $key || true; } | sed -r "s/^${key}: (.*)$/\1/")
rules=$(jq -n '[
{
"host": "'"$key"'.'$(echo '${TRAEFIK_DOMAIN}')'",
"httpAuth": '"${defaultHttpAuth}"',
"internalPort": '"${internalPort}"',
"internalScheme": "'"${internalScheme}"'"
}
]')
;;
esac
jq -r --argjson RULES "$rules" '.services[.services| length] |= . +
{
"name": "'"$key"'",
"enabled": '"${enabled}"',
"vpn": '"${enableVpn}"',
"traefik": {
"enabled": '"${enableTraefik}"',
"rules": $RULES
}
}' config.json > tmp.json
rm -f config.json
mv tmp.json config.json
done
# Transform json into yaml, easier to manipulate for the user
cat config.json | yq e -P - > config.yaml