2022-07-14 23:04:14 +00:00
|
|
|
#!/usr/bin/with-contenv sh
|
|
|
|
# shellcheck shell=sh
|
|
|
|
|
2022-11-25 20:37:33 +00:00
|
|
|
# One-shot service
|
|
|
|
# https://github.com/just-containers/s6-overlay/issues/86
|
|
|
|
|
|
|
|
s6-svc -O /var/run/service/setup
|
|
|
|
|
|
|
|
echo "
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
SETUP
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
AUTOCONFIG=$AUTOCONFIG
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
"
|
|
|
|
|
2022-07-15 12:22:04 +00:00
|
|
|
url="http://localhost:8686"
|
|
|
|
urlPlugin="https://github.com/ta264/Lidarr.Plugin.Deemix"
|
|
|
|
|
|
|
|
# string, route
|
|
|
|
isPresent() {
|
|
|
|
apiCall "GET" "$2" | grep -q "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
# method, route, payload
|
|
|
|
apiCall() {
|
|
|
|
curl \
|
|
|
|
-s \
|
|
|
|
-X "$1" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-H "X-Api-Key: $apiKey" \
|
|
|
|
-d "$3" \
|
|
|
|
$url/api/v1/"$2"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2022-07-16 22:40:04 +00:00
|
|
|
if [ "$(stat -c '%g' /usr/local/bin/clean-downloads.sh)" != "$PGUID" ]; then
|
|
|
|
echo "Changing ownership on scripts."
|
|
|
|
chown "$PUID:$PGID" /usr/local/bin/*.sh
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -x /usr/local/bin/clean-downloads.sh ]; then
|
|
|
|
echo "Making scripts executable."
|
|
|
|
chmod +x /usr/local/bin/*.sh
|
|
|
|
fi
|
|
|
|
|
2022-11-25 20:37:14 +00:00
|
|
|
if [ "$(stat -c '%g' /music)" != "$PGUID" ]; then
|
|
|
|
echo "Changing ownership of /music"
|
|
|
|
chown "$PUID:$PGID" /music
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$(stat -c '%g' /downloads)" != "$PGUID" ]; then
|
|
|
|
echo "Changing ownership of /downloads"
|
|
|
|
chown "$PUID:$PGID" /downloads
|
|
|
|
fi
|
|
|
|
|
2022-11-25 20:37:33 +00:00
|
|
|
if [ "$AUTOCONFIG" != "true" ]; then
|
|
|
|
exit
|
|
|
|
fi
|
2022-11-25 20:37:14 +00:00
|
|
|
|
2022-07-14 23:04:14 +00:00
|
|
|
echo "
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
LIDARR SETUP
|
|
|
|
----------------------------------------------------------------------
|
2022-07-15 12:22:04 +00:00
|
|
|
PluginSource=$urlPlugin
|
2022-07-14 23:04:14 +00:00
|
|
|
----------------------------------------------------------------------
|
|
|
|
"
|
2022-11-25 20:37:33 +00:00
|
|
|
echo "[autoconfig] Waiting Lidarr to launch on 8686..."
|
|
|
|
while ! nc -z localhost 8686; do
|
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
apiKey="$(curl \
|
|
|
|
-sS \
|
|
|
|
--retry-all-errors \
|
|
|
|
--retry 10 \
|
|
|
|
$url/initialize.js |
|
|
|
|
sed -n "s/apiKey: '\(.*\)'.*/\1/p")"
|
|
|
|
|
2022-11-26 12:07:13 +00:00
|
|
|
plugin=$(apiCall "GET" "system/plugins" | jq '.[]|select(.name=="Deemix")')
|
|
|
|
|
|
|
|
if [ -z "$plugin" ] || [ "$(echo "$plugin" | jq .updateAvailable)" = "true" ]; then
|
|
|
|
echo "[autoconfig] Installing / Updating Deemix plugin"
|
2022-11-25 20:37:33 +00:00
|
|
|
githubRate=$(curl -s https://api.github.com/rate_limit | jq .rate)
|
2022-11-27 20:55:31 +00:00
|
|
|
if [ "$(echo "$githubRate" | jq .remaining)" = "0" ]; then
|
|
|
|
deltaGithubResetTime=$(( $(echo "$githubRate" | jq .reset) - $(date +%s) + 5 ))
|
|
|
|
echo "[autoconfig] Waiting github rate limit reset : $deltaGithubResetTime seconds"
|
|
|
|
sleep $deltaGithubResetTime
|
2022-07-15 12:22:04 +00:00
|
|
|
fi
|
2022-11-25 20:37:33 +00:00
|
|
|
apiCall "POST" "command" '{"name":"InstallPlugin","githubUrl":"'$urlPlugin'"}'
|
2022-11-26 12:07:13 +00:00
|
|
|
|
2022-11-26 19:32:48 +00:00
|
|
|
while [ -z "$plugin" ] || [ "$(echo "$plugin" | jq .updateAvailable)" = "true" ]; do
|
|
|
|
sleep 1
|
|
|
|
plugin=$(apiCall "GET" "system/plugins" | jq '.[]|select(.name=="Deemix")')
|
2022-11-26 12:07:13 +00:00
|
|
|
done
|
|
|
|
echo "[autoconfig] Stopping"
|
|
|
|
/run/s6/basedir/bin/halt
|
2022-11-25 20:37:33 +00:00
|
|
|
fi
|
|
|
|
if ! isPresent "path" "rootFolder"; then
|
|
|
|
echo "[autoconfig] Setting /music rootFolder"
|
|
|
|
apiCall "POST" "rootFolder" '{"defaultTags":[],"defaultQualityProfileId":1,"defaultMetadataProfileId":1,"path":"/music","name":"Music"}'
|
|
|
|
fi
|
|
|
|
loginPath="/config_deemix/login.json"
|
|
|
|
echo "[autoconfig] Waiting for $loginPath to be filled..."
|
|
|
|
while [ -z "$arl" ]; do
|
|
|
|
sleep 1
|
|
|
|
arl=$(sed -n 's/.*arl.*"\(.*\)"/\1/p' "$loginPath" 2>/dev/null)
|
|
|
|
done
|
|
|
|
if [ "$(apiCall "GET" "delayprofile" | jq .[0].items[2].allowed)" = "false" ]; then
|
|
|
|
echo "[autoconfig] Allowing Deemix in default delay profile"
|
|
|
|
apiCall "PUT" "delayprofile/1" \
|
|
|
|
'{"name":"Default","items":[{"name":"Usenet","protocol":"UsenetDownloadProtocol","allowed":true,"delay":0},{"name":"Torrent","protocol":"TorrentDownloadProtocol","allowed":true,"delay":0},{"name":"Deemix","protocol":"DeemixDownloadProtocol","allowed":true,"delay":0}],"tags":[],"id":1}'
|
|
|
|
fi
|
|
|
|
if ! isPresent "Deemix" "indexer"; then
|
2022-07-14 23:04:14 +00:00
|
|
|
loginPath="/config_deemix/login.json"
|
2022-11-25 20:37:33 +00:00
|
|
|
echo "[autoconfig] Updating indexer"
|
|
|
|
apiCall "POST" "indexer" \
|
|
|
|
'{"enableRss":true,"enableAutomaticSearch":true,"enableInteractiveSearch":true,"supportsRss":true,"supportsSearch":true,"protocol":"DeemixDownloadProtocol","priority":25,"downloadClientId":0,"name":"Deemix","fields":[{"name":"baseUrl","value":"http://localhost:6595"},{"name":"arl","value":"'"$arl"'"},{"name":"earlyReleaseLimit"}],"implementationName":"Deemix","implementation":"Deemix","configContract":"DeemixIndexerSettings","infoLink":"https://wiki.servarr.com/lidarr/supported#deemix","tags":[]}'
|
|
|
|
fi
|
|
|
|
if ! isPresent "Deemix" "downloadclient"; then
|
|
|
|
echo "[autoconfig] Updating download client"
|
|
|
|
apiCall "POST" "downloadclient" \
|
|
|
|
'{"enable":true,"protocol":"DeemixDownloadProtocol","priority":1,"removeCompletedDownloads":true,"removeFailedDownloads":true,"name":"Deemix","fields":[{"name":"host","value":"localhost"},{"name":"port","value":6595},{"name":"urlBase"},{"name":"useSsl","value":false},{"name":"arl","value":"'"$arl"'"}],"implementationName":"Deemix","implementation":"Deemix","configContract":"DeemixSettings","infoLink":"https://wiki.servarr.com/lidarr/supported#deemix","tags":[]}'
|
2022-07-14 23:04:14 +00:00
|
|
|
fi
|
2022-11-25 20:37:33 +00:00
|
|
|
echo "[autoconfig] Configuration is up to date"
|
2022-07-16 10:31:16 +00:00
|
|
|
|
|
|
|
echo "
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
Flac2MP3 SETUP
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
PUID=$PUID
|
|
|
|
PGID=$PGID
|
|
|
|
FLAC2CUSTOM_ARGS=$FLAC2CUSTOM_ARGS
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
"
|
|
|
|
|
2022-11-25 20:37:33 +00:00
|
|
|
if [ -n "$FLAC2CUSTOM_ARGS" ]; then
|
|
|
|
echo "[autoconfig] FLAC2CUSTOM_ARGS is set"
|
|
|
|
if ! isPresent "flac2" "notification"; then
|
|
|
|
echo "[autoconfig] Configuring flac2custom.sh custom script"
|
|
|
|
apiCall "POST" "notification" '{"onGrab":false,"onReleaseImport":true,"onUpgrade":true,"onRename":false,"onHealthIssue":false,"onDownloadFailure":false,"onImportFailure":false,"onTrackRetag":false,"onApplicationUpdate":false,"supportsOnGrab":true,"supportsOnReleaseImport":true,"supportsOnUpgrade":true,"supportsOnRename":true,"supportsOnHealthIssue":true,"includeHealthWarnings":false,"supportsOnDownloadFailure":false,"supportsOnImportFailure":false,"supportsOnTrackRetag":true,"supportsOnApplicationUpdate":true,"name":"Flac2Custom","fields":[{"name":"path","value":"/usr/local/bin/flac2custom.sh"},{"name":"arguments"}],"implementationName":"Custom Script","implementation":"CustomScript","configContract":"CustomScriptSettings","infoLink":"","message":{"message":"","type":"warning"},"tags":[]}'
|
2022-07-16 10:31:16 +00:00
|
|
|
fi
|
|
|
|
fi
|
2022-07-16 22:20:38 +00:00
|
|
|
|
|
|
|
echo "
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
Utilities SETUP
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
"
|
2022-07-16 22:40:04 +00:00
|
|
|
|
2022-11-25 20:37:33 +00:00
|
|
|
if ! isPresent "Clean Downloads" "notification"; then
|
|
|
|
echo "[autoconfig] Configuring flac2custom.sh custom script"
|
|
|
|
apiCall "POST" "notification" '{"onGrab":false,"onReleaseImport":true,"onUpgrade":true,"onRename":false,"onHealthIssue":false,"onDownloadFailure":false,"onImportFailure":false,"onTrackRetag":false,"onApplicationUpdate":false,"supportsOnGrab":true,"supportsOnReleaseImport":true,"supportsOnUpgrade":true,"supportsOnRename":true,"supportsOnHealthIssue":true,"includeHealthWarnings":false,"supportsOnDownloadFailure":false,"supportsOnImportFailure":false,"supportsOnTrackRetag":true,"supportsOnApplicationUpdate":true,"name":"Clean Downloads","fields":[{"name":"path","value":"/usr/local/bin/clean-downloads.sh"},{"name":"arguments"}],"implementationName":"Custom Script","implementation":"CustomScript","configContract":"CustomScriptSettings","infoLink":"","message":{"message":"","type":"warning"},"tags":[]}'
|
2022-07-16 22:20:38 +00:00
|
|
|
fi
|
2022-11-25 20:37:33 +00:00
|
|
|
|
|
|
|
echo "
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
AUTOCONFIG COMPLETE
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
"
|