-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathstart.sh
71 lines (60 loc) · 1.99 KB
/
start.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
if command -v rclone &> /dev/null
then
echo "Rclone executable found (global)"
RCLONE_COMMAND="rclone"
else
RCLONE_COMMAND="./rclone"
if [ ! -f rclone ]; then
echo "No rclone executable found, installing first (binary)"
curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip
unzip rclone-current-linux-amd64.zip
cp rclone-*-linux-amd64/rclone .
rm -rf rclone-*
chmod +x rclone
else
echo "Rclone executable found (binary)"
fi
fi
if [ -z "${PORT}" ]; then
echo "No PORT env var, using 8080 port"
PORT=8080
else
echo "PORT env var found, using $PORT port"
fi
if [ -n "${CONFIG_BASE64}" ] || [ -n "${CONFIG_URL}" ]; then
echo "Rclone config found"
if [ -n "${CONFIG_BASE64}" ]; then
echo "${CONFIG_BASE64}" | base64 -d > rclone.conf
echo "Base64-encoded config is used"
elif [ -n "${CONFIG_URL}" ]; then
curl "$CONFIG_URL" > rclone.conf
echo "Gist link config is used"
fi
contents=$(cat rclone.conf)
if ! echo "$contents" | grep -q "\[combine\]"; then
remotes=$(echo "$contents" | grep '^\[' | sed 's/\[\(.*\)\]/\1/g')
upstreams=""
for remote in $remotes; do
upstreams+="$remote=$remote: "
done
upstreams=${upstreams::-1}
echo -e "\n\n[combine]\ntype = combine\nupstreams = $upstreams" >> rclone.conf
fi
else
echo "No Rclone config URL found, serving blank config"
touch rclone.conf
echo -e "[combine]\ntype = alias\nremote = dummy" > rclone.conf
fi
CMD="${RCLONE_COMMAND} serve http combine: --addr=:$PORT --read-only --config rclone.conf"
if [ -n "${USERNAME}" ] && [ -n "${PASSWORD}" ]; then
CMD="${CMD} --user=\"$USERNAME\" --pass=\"$PASSWORD\""
echo "Authentication is set"
fi
if [ "${DARK_MODE,,}" = "true" ]; then
CMD="${CMD} --template=templates/dark.html"
echo "Template is set to dark"
else
echo "Template is set to light"
fi
echo "Running rclone index"
eval $CMD