Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JDownloader EvenScripter Config Generator
#!/bin/sh
#
# Convert an Event Scripter source to a config JSON
# $1: location of EventScripter files
# Need 'gsed' on macOS to behave like its Linux counterpart
if [[ $(uname) == "Darwin" ]]; then
SED="gsed"
else
SED="sed"
fi
realpath() {
OURPWD=$PWD
cd "$(dirname "$1")"
LINK=$(readlink "$(basename "$1")")
while [ "$LINK" ]; do
cd "$(dirname "$LINK")"
LINK=$(readlink "$(basename "$1")")
done
REALPATH="$PWD/$(basename "$1")"
cd "$OURPWD"
echo "$REALPATH"
}
oneline() {
# https://stackoverflow.com/a/48486375/899954
"${SED}" -e ':a; N; $!ba; s/\n/\n/g' "$1"
}
TEMPLATE="EventScripter.template.json"
PACKAGE_FINISHED="PackageFinished.js"
ARCHIVE_EXTRACTED="ArchiveExtracted.js"
JSON="org.jdownloader.extensions.eventscripter.EventScripterExtension.scripts.json"
# Convert tabs to \t; convert newlines to \n
PACKAGE_FINISHED_1=$(oneline $(realpath "$PACKAGE_FINISHED"))
ARCHIVE_EXTRACTED_1=$(oneline $(realpath "$ARCHIVE_EXTRACTED"))
# Because of various quoting problems, better to pass converted script
# as a parameter into jq
jq --arg S0 "$PACKAGE_FINISHED_1" \
--arg S1 "$ARCHIVE_EXTRACTED_1" \
'.[0].script = $S0 | .[1].script = $S1' \
$(realpath "$1")/"$TEMPLATE" > $(realpath "$1")/"$JSON"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.