Skip to content

Commit

Permalink
fixes #127 - Configure tool param handling
Browse files Browse the repository at this point in the history
Configure tool will now surround parameters by double quotes to avoid
commas in password or email or devicename to break JSON format. With
this change, spaces before and after the semicolumn separator in
MyJDownloader configuration JSON file are forbidden (therefore, changed
in the dist default file).

This new behaviour, however, is buggy with double quotes in password.
This is a limitation of sed that does not allow non greedy regexp. This
means if a password contains a double quote, it will be correctly handle
the first time only and will break everything on password change. Same
for devicename or email.

Let's pray for JDownloader to NOT change back with the space on the
semicolumn separator or everything will be broken again.

I know this is not perfect but fixes 99% of issues to avoid
recompiling the universe or adding a thousand dependencies.
  • Loading branch information
jaymoulin committed Sep 1, 2023
1 parent 7f8ae29 commit 38a099b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
6 changes: 4 additions & 2 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ if [ ! $# -eq 2 ]; then
echo "$usage"
exit 1
fi
password=`echo $2 | sed 's/"/\\\\\\\\"/g'`
email=`echo $1 | sed 's/"/\\\\\\\\"/g'`

if [ ! -f /opt/JDownloader/app/cfg/org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json ]; then
cp /opt/JDownloader/org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json.dist /opt/JDownloader/app/cfg/org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json
fi

sed -Ei "s/\"password\" : .+\"(,?)/\"password\" : \"$2\"\1/" /opt/JDownloader/app/cfg/org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json && \
sed -Ei "s/\"email\" : .+\"(,?)/\"email\" : \"$1\"\1/" /opt/JDownloader/app/cfg/org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json
sed -Ei "s/\"password\":\"[^\"]*\"/\"password\":\"$password\"/" /opt/JDownloader/app/cfg/org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json && \
sed -Ei "s/\"email\":\"[^\"]*\"/\"email\":\"$email\"/" /opt/JDownloader/app/cfg/org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json
(pkill -f "JDownloader" || reboot)
2 changes: 1 addition & 1 deletion daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fi

# Defining device name to jdownloader interface - please prefer this method than changing on MyJDownloader to keep correct binding
if [ -n "$MYJD_DEVICE_NAME" ]; then
sed -Ei "s/\"devicename\" : .+\"(,?)/\"devicename\" : \"$MYJD_DEVICE_NAME\"\1/" /opt/JDownloader/app/cfg/org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json
sed -Ei "s/\"devicename\":\"[^\"]*\"/\"devicename\":\"$MYJD_DEVICE_NAME\"/" /opt/JDownloader/app/cfg/org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json
fi

# Debugging helper - if the container crashes, create a file called "jdownloader-block.txt" in the download folder
Expand Down
7 changes: 1 addition & 6 deletions default-config.json.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
{
"autoconnectenabledv2" : true,
"password" : "",
"email" : "",
"devicename" : ""
}
{"autoconnectenabledv2":true,"password":"","email":"","devicename":""}

0 comments on commit 38a099b

Please sign in to comment.