Skip to content

Commit

Permalink
use jq instead of grep
Browse files Browse the repository at this point in the history
  • Loading branch information
cartfisk committed Mar 11, 2024
1 parent 7c9cc02 commit a96e3bc
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions root/etc/s6-overlay/s6-rc.d/init-transmission-config/run
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

SETTINGS=/config/settings.json

# copy config
if [[ ! -f $SETTINGS ]]; then
cp /defaults/settings.json $SETTINGS
if [[ ! -f /config/settings.json ]]; then
cp /defaults/settings.json /config/settings.json
fi

# Default values
DOWNLOAD_DIR="/downloads/complete"
INCOMPLETE_DIR="/downloads/incomplete"

# Check `settings.json` for custom download/incomplete directories
settings_download_dir=$(grep -o '"download-dir": "[^"]*' "$SETTINGS" | sed 's/"download-dir": "//')
settings_download_dir=$(jq -r '."download-dir" | select( . != null )' /config/settings.json)
if [ ! -z "$settings_download_dir" ]; then
DOWNLOAD_DIR="$settings_download_dir"
fi
settings_incomplete_dir=$(grep -o '"incomplete-dir": "[^"]*' "$SETTINGS" | sed 's/"incomplete-dir": "//')
settings_incomplete_dir=$(jq -r '."incomplete-dir" | select( . != null )' /config/settings.json)
if [ ! -z "$settings_incomplete_dir" ]; then
INCOMPLETE_DIR="$settings_incomplete_dir"
fi
Expand Down

0 comments on commit a96e3bc

Please sign in to comment.