|
1 | 1 | #!/usr/bin/with-contenv bash |
2 | 2 | # shellcheck shell=bash |
3 | 3 |
|
4 | | -# make folders |
| 4 | +# make folders |
5 | 5 | mkdir -p \ |
6 | 6 | /downloads/{complete,incomplete} /watch |
7 | 7 |
|
8 | | -# copy config |
| 8 | +# copy config |
9 | 9 | if [[ ! -f /config/settings.json ]]; then |
10 | 10 | cp /defaults/settings.json /config/settings.json |
11 | 11 | fi |
12 | 12 |
|
13 | | -if [[ -n "$USER" ]] && [[ -n "$PASS" ]]; then |
14 | | - sed -i '/rpc-authentication-required/c\ "rpc-authentication-required": true,' /config/settings.json |
15 | | - sed -i "/rpc-username/c\ \"rpc-username\": \"$USER\"," /config/settings.json |
16 | | - sed -i "/rpc-password/c\ \"rpc-password\": \"$PASS\"," /config/settings.json |
| 13 | +if [[ -n "${USER}" ]] && [[ -n "${PASS}" ]]; then |
| 14 | + echo -E "$(jq -r '.["rpc-authentication-required"] = true' /config/settings.json)" >/config/settings.json |
17 | 15 | else |
18 | | - sed -i '/rpc-authentication-required/c\ "rpc-authentication-required": false,' /config/settings.json |
19 | | - sed -i "/rpc-username/c\ \"rpc-username\": \"$USER\"," /config/settings.json |
20 | | - sed -i "/rpc-password/c\ \"rpc-password\": \"$PASS\"," /config/settings.json |
| 16 | + echo -E "$(jq -r '.["rpc-authentication-required"] = false' /config/settings.json)" >/config/settings.json |
21 | 17 | fi |
| 18 | +echo -E "$(jq -r --arg user "${USER}" '.["rpc-username"] = $user' /config/settings.json)" >/config/settings.json |
| 19 | +echo -E "$(jq -r --arg pass "${PASS}" '.["rpc-password"] = $pass' /config/settings.json)" >/config/settings.json |
22 | 20 |
|
23 | | -if [[ -n "$WHITELIST" ]]; then |
24 | | - sed -i '/rpc-whitelist-enabled/c\ "rpc-whitelist-enabled": true,' /config/settings.json |
25 | | - sed -i "/\"rpc-whitelist\"/c\ \"rpc-whitelist\": \"$WHITELIST\"," /config/settings.json |
| 21 | +if [[ -n "${WHITELIST}" ]]; then |
| 22 | + echo -E "$(jq -r '.["rpc-whitelist-enabled"] = true' /config/settings.json)" >/config/settings.json |
26 | 23 | else |
27 | | - sed -i '/rpc-whitelist-enabled/c\ "rpc-whitelist-enabled": false,' /config/settings.json |
28 | | - sed -i "/\"rpc-whitelist\"/c\ \"rpc-whitelist\": \"$WHITELIST\"," /config/settings.json |
| 24 | + echo -E "$(jq -r '.["rpc-whitelist-enabled"] = false' /config/settings.json)" >/config/settings.json |
29 | 25 | fi |
| 26 | +echo -E "$(jq -r --arg whitelist "${WHITELIST}" '.["rpc-whitelist"] = $whitelist' /config/settings.json)" >/config/settings.json |
30 | 27 |
|
31 | | -if [[ -n "$HOST_WHITELIST" ]]; then |
32 | | - sed -i '/rpc-host-whitelist-enabled/c\ "rpc-host-whitelist-enabled": true,' /config/settings.json |
33 | | - sed -i "/\"rpc-host-whitelist\"/c\ \"rpc-host-whitelist\": \"$HOST_WHITELIST\"," /config/settings.json |
| 28 | +if [[ -n "${HOST_WHITELIST}" ]]; then |
| 29 | + echo -E "$(jq -r '.["rpc-host-whitelist-enabled"] = true' /config/settings.json)" >/config/settings.json |
34 | 30 | else |
35 | | - sed -i '/rpc-host-whitelist-enabled/c\ "rpc-host-whitelist-enabled": false,' /config/settings.json |
36 | | - sed -i "/\"rpc-host-whitelist\"/c\ \"rpc-host-whitelist\": \"$HOST_WHITELIST\"," /config/settings.json |
| 31 | + echo -E "$(jq -r '.["rpc-host-whitelist-enabled"] = false' /config/settings.json)" >/config/settings.json |
37 | 32 | fi |
| 33 | +echo -E "$(jq -r --arg host_whitelist "${HOST_WHITELIST}" '.["rpc-host-whitelist"] = $host_whitelist' /config/settings.json)" >/config/settings.json |
38 | 34 |
|
39 | 35 | if [[ -n "${PEERPORT}" ]]; then |
40 | | - sed -i "/\"peer-port\"/c\ \"peer-port\": ${PEERPORT}," /config/settings.json |
41 | | - sed -i '/peer-port-random-on-start/c\ "peer-port-random-on-start": false,' /config/settings.json |
| 36 | + echo -E "$(jq -r --arg peerport "${PEERPORT}" '.["peer-port"] = $peerport' /config/settings.json)" >/config/settings.json |
| 37 | + echo -E "$(jq -r '.["peer-port-random-on-start"] = false' /config/settings.json)" >/config/settings.json |
42 | 38 | fi |
43 | 39 |
|
44 | 40 | if [[ -n "${UMASK}" ]]; then |
45 | | - sed -i "/\"umask\"/c\ \"umask\": \"${UMASK}\"," /config/settings.json |
| 41 | + echo -E "$(jq -r --arg umask "${UMASK}" '.["umask"] = $umask' /config/settings.json)" >/config/settings.json |
46 | 42 | fi |
47 | 43 |
|
48 | 44 | # Handle old theme locations |
49 | 45 | mkdir -p {/transmissionic,/combustion-release,/flood-for-transmission,/kettu,/transmission-web-control} |
50 | 46 | echo /transmissionic /combustion-release /flood-for-transmission /kettu /transmission-web-control | xargs -n1 ln -s /defaults/index.html |
51 | 47 |
|
52 | | -# permissions |
| 48 | +# permissions |
53 | 49 | lsiown abc:abc \ |
54 | 50 | /config/settings.json |
55 | 51 |
|
|
0 commit comments