Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install Script not Parsing Spotify Password into mopidy.conf correctly #1420

Closed
Jdiesel87 opened this issue May 18, 2021 · 6 comments · Fixed by #2315
Closed

Install Script not Parsing Spotify Password into mopidy.conf correctly #1420

Jdiesel87 opened this issue May 18, 2021 · 6 comments · Fixed by #2315

Comments

@Jdiesel87
Copy link

I have confirmed this with both the master and develop releases.

When you enter your Spotify credentials during the install script it results in a mopify login error. When viewing the mopidy.conf the spotify password field has incorrectly inserted "spotify_password" into the center of the correct password text. It must be edited in the config manually to authenticate with Spotify.

@s-martin s-martin added the bug label May 19, 2021
@s-martin s-martin added this to the 2.3 milestone May 19, 2021
@s-martin
Copy link
Collaborator

this should happen here:

if [ "${SPOTinstall}" == "YES" ]; then
local etc_mopidy_conf="/etc/mopidy/mopidy.conf"
local mopidy_conf="${HOME_DIR}/.config/mopidy/mopidy.conf"
echo "Configuring Spotify support..."
sudo systemctl disable mpd
sudo systemctl enable mopidy
# Install Config Files
sudo cp "${jukebox_dir}"/misc/sampleconfigs/locale.gen.sample /etc/locale.gen
sudo cp "${jukebox_dir}"/misc/sampleconfigs/locale.sample /etc/default/locale
sudo locale-gen
mkdir -p "${HOME_DIR}"/.config/mopidy
sudo cp "${jukebox_dir}"/misc/sampleconfigs/mopidy-etc.sample "${etc_mopidy_conf}"
cp "${jukebox_dir}"/misc/sampleconfigs/mopidy.sample "${mopidy_conf}"
# Change vars to match install config
sudo sed -i 's/%spotify_username%/'"$SPOTIuser"'/' "${etc_mopidy_conf}"
sudo sed -i 's/%spotify_password%/'"$SPOTIpass"'/' "${etc_mopidy_conf}"
sudo sed -i 's/%spotify_client_id%/'"$SPOTIclientid"'/' "${etc_mopidy_conf}"
sudo sed -i 's/%spotify_client_secret%/'"$SPOTIclientsecret"'/' "${etc_mopidy_conf}"
# for $DIRaudioFolders using | as alternate regex delimiter because of the folder path slash
sudo sed -i 's|%DIRaudioFolders%|'"$DIRaudioFolders"'|' "${etc_mopidy_conf}"
sed -i 's/%spotify_username%/'"$SPOTIuser"'/' "${mopidy_conf}"
sed -i 's/%spotify_password%/'"$SPOTIpass"'/' "${mopidy_conf}"
sed -i 's/%spotify_client_id%/'"$SPOTIclientid"'/' "${mopidy_conf}"
sed -i 's/%spotify_client_secret%/'"$SPOTIclientsecret"'/' "${mopidy_conf}"
# for $DIRaudioFolders using | as alternate regex delimiter because of the folder path slash
sudo sed -i 's|%DIRaudioFolders%|'"$DIRaudioFolders"'|' "${mopidy_conf}"

by just looking at it I can’t see an obvious problem.

@UbiGIT89
Copy link

Same issue with my config.

For me it seems that the trigger is a dollar sign ($) in the password.
The "$" and the next character are missing in the mopidy.conf and have to be added manually.

It doesn't matter if I ran automated or interactiv installation.

@Jdiesel87
Copy link
Author

There is know $ in my password but I do have a & if that helps with troubleshooting. I haven't had a chance to rerun the installer script to see exactly what is happening yet.

@s-martin s-martin modified the milestones: 2.3, 2.4 Aug 10, 2021
@s-martin s-martin removed this from the 2.4 milestone Mar 23, 2022
@AlvinSchiller
Copy link
Collaborator

This will be fixes with #2315

@AlvinSchiller AlvinSchiller linked a pull request Apr 10, 2024 that will close this issue
@kingosticks
Copy link

Did you identify the issue and is there a fix somewhere for this in #2315 ? To me,

echo "SPOTIpass=\"$SPOTIpass\"";
looks like the problem when the value contains a dollar sign (or double-quotes, maybe other special characters too). I can't see a fix for it so I had a go. Apologies if there was already something in place, in which case please disregard all this!

e.g.

> mypass='hello$world'
> echo mypass
hello$world
> echo "SPOTIpass=\"$mypass\"" > test.conf && source test.conf && echo $SPOTIpass
hello
> cat test.conf
SPOTIpass="hello$world"

You lose everything after the dollar because the double quotes inserted into test.conf tell bash to interpolate the variable $world (which is empty in this case). Using single quotes would avoid this and still prevent unwanted word-splitting e.g.

> echo "SPOTIpass='$mypass'" > test.conf && source test.conf && echo $SPOTIpass
hello$world
> cat test.conf
SPOTIpass='hello$world'

But you'd still have a problem with any quote characters in there:

> mypass="hello'world"
> echo mypass
hello'world
> echo "SPOTIpass='$mypass'" > test.conf && source test.conf && echo $SPOTIpass
bash: ./test.conf: line 1: unexpected EOF while looking for matching `''
bash: ./test.conf: line 2: syntax error: unexpected end of file
> cat test.conf
SPOTIpass='hello'world'

They need to be escaped. And maybe also consider switching to the bash literal syntax ($'mystring'). The following seems more robust and hopefully not much more painful to read/comprehend:

# Helper function to escape single quotes by prefixing them them with a slash.
> esq() { printf "%s" ${1//\'/\\\'}; }
> mypass="hello'world\$again"
> echo mypass
hello'world$again
> echo $(esq $mypass)
hello\'world$again
> echo "SPOTIpass=\$'$(esq $mypass)'" > test.conf && source test.conf && echo $SPOTIpass
hello'world$again
> cat test.conf
SPOTIpass=$'hello\'world$again'

You'd need to do this everywhere the user's input might contain problematic characters (i.e. not just the Spotify password).

@kingosticks
Copy link

haha, you have a fix now. I shouldn't have gone for lunch before submitting that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants