-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
executable file
·113 lines (88 loc) · 2.9 KB
/
setup.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
#!/bin/bash
# -= boilerplate =-
# exit on errors
set -euo pipefail
# for any relative paths
script_dir=$(dirname "$(realpath $0)")
echo "script_dir=$script_dir"
# -= ensure `shepherd.config.json` exists =-
config_file="$script_dir/addons/nsfw/shepherd.config.json"
if [ ! -f "$config_file" ]; then
echo "$config_file not found. creating default..." 2>&1 | tee -a setup.log
cat <<EOF > "$config_file"
{
"plugins": [
"shepherd-plugin-nsfw@latest"
],
"lowmem": false
}
EOF
fi
# -= import .env vars =-
if [ -f ".env" ]; then
export $(grep -Ev '^#' .env | xargs)
# check vars
extra_queues_checker=${EXTRA_QUEUES:-}
if [[ -z $extra_queues_checker ]]; then
echo "INFO: EXTRA_QUEUES undefined"
else
echo "EXTRA_QUEUES=$EXTRA_QUEUES"
fi
echo "BLACKLIST_ALLOWED=${BLACKLIST_ALLOWED:-}"
echo "GW_URLS=${GW_URLS:-}"
# make sure .env ends in newline
lastchar=$(tail -c 1 .env)
if [ "$lastchar" != "" ]; then
echo >> .env
fi
else
echo "continuing without .env file."
fi
# import `.RANGELIST_ALLOWED.json` as a string
if [ ! -f ".RANGELIST_ALLOWED.json" ]; then
echo "WARNING: .RANGELIST_ALLOWED.json not found"
else
export RANGELIST_ALLOWED=$(cat ./.RANGELIST_ALLOWED.json | tr -d ' \n\t')
echo "RANGELIST_ALLOWED=$RANGELIST_ALLOWED"
fi
##########################################
# -= generate compose file to be used =- #
##########################################
# copy override file to generated file
generated_file="$script_dir/docker-compose.override.yml"
echo "# WARNING! this file is automatically generated from 'docker-compose.local.yml'" > $generated_file
echo "# DO NOT EDIT DIRECTLY. any changes will be overwritten" >> $generated_file
cat "$script_dir/docker-compose.local.yml" >> $generated_file
# function to generate the sevice entry for an addon
function generate_service_entry {
local addon_name=$1
echo "generating service entry for [$addon_name]"
cat << EOF >> $generated_file
# automatically generated service entry
$addon_name:
extends:
file: ./addons/$addon_name/docker-compose.local.yml
service: $addon_name
EOF
}
# import ADDONS, generate service entries for them
addons_checker=${ADDONS:-}
if [[ -z $addons_checker ]]; then
echo "INFO: ADDONS=undefined." #TODO: add default behaviour here
else
echo "ADDONS=$ADDONS"
IFS=',' read -r -a addons_dirs <<< "$ADDONS" # addons_dirs = ADDONS.split(',')
for addon_name in "${addons_dirs[@]}"; do
addon_name=$(echo $addon_name | tr -d '[:space:]') # remove whitespace
generate_service_entry $addon_name
done
fi
# ##########################################
# # -= finally run the compose commands =- #
# ##########################################
# command_string="docker compose -f $script_dir/docker-compose.yml -f $generated_file "
# echo "command_string=$command_string"
# echo "cd to $script_dir"
# cd "$script_dir"
# eval "$command_string up --build -d "
# eval "$command_string logs -f"