Skip to content

Instantly share code, notes, and snippets.

@bonelifer
Last active January 2, 2025 03:10
Show Gist options
  • Save bonelifer/9d12e13b8465c213d2d2 to your computer and use it in GitHub Desktop.
Save bonelifer/9d12e13b8465c213d2d2 to your computer and use it in GitHub Desktop.
Replace Pandora's old tls fingerprint with new one in pianobar config
#!/bin/bash
##
## A simple shell script that returns the current
## fingerprint on the SSL certificate and replaces it in
## pianobar's config file automatically.
##
## Author: William Jacoby (bonelifer)
##
## Based on the Github Gist by Bob Saska at: https://gist.github.com/r35krag0th/4173333
##
# Function to install openssl if it's not installed
install_openssl() {
echo "openssl is not installed. Installing..."
sudo apt update
sudo apt install -y openssl
}
# Check if openssl is installed
if ! command -v openssl &> /dev/null; then
install_openssl
fi
# Retrieve the SSL certificate fingerprint from tuner.pandora.com
c=$(openssl s_client -connect tuner.pandora.com:443 < /dev/null 2> /dev/null | \
openssl x509 -noout -fingerprint | tr -d ':' | cut -d'=' -f2)
# Check if the openssl command succeeded
if [ $? -ne 0 ]; then
echo "Error: Failed to retrieve the SSL fingerprint."
exit 1
fi
# Debug output (uncomment to use)
# echo "Current TLS Fingerprint: $c"
# Define the path to the pianobar config file using $HOME
file="$HOME/.config/pianobar/config"
# Ensure the config file exists before trying to modify it
if [ ! -f "$file" ]; then
echo "Error: Config file $file not found."
exit 1
fi
# Check if tls_fingerprint exists in the config file and update it, otherwise append it
if grep -q "^tls_fingerprint =" "$file"; then
sed -i "s/^tls_fingerprint =.*/tls_fingerprint = $c/" "$file"
else
echo "tls_fingerprint = $c" >> "$file"
fi
# Output the fingerprint and confirm success
echo "Current TLS Fingerprint: $c"
echo "tls_fingerprint updated successfully in $file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment