Can't get PIN for Ecobee binding

As I just ran into this issue again, with needing to re-authorize the ecobee binding, I did some looking on here before recalling that I already made a script to fix this for myself.

This is on a Raspberry Pi, but this should work for most linux installations.
I’m pasting the script below. You may possibly need to modify the path (/var/lib/openhab2/.java
) to match your setup.

echo "Script to stop openhab, clear the java temp files, and then restart openhab.  This will result in the ecobee binding sending an ecobee pin request.  Watch the log output for ecobee items to catch this.  Should be run by a user with sudo ability."
echo  "Stopping Openahab"

systemctl stop openhab2.service
cd /var/lib/openhab2/.java
sudo rm .userPrefs -R
sudo mkdir .userPrefs
sudo chown openhab:openhab .userPrefs
sudo chmod o-x .userPrefs

echo "Starting openhab service"
systemctl start openhab2.service

echo "Now look through your logs, filtering for EcobeeBinding - you will find a PIN"
echo "Login to www.ecobee.com, go to My Apps, and validate the PIN within 900 minutes"

If you’re going to use this script, rather than simply extract the useful commands, you will need to put in a location you’re likely to find it again, and chmod +x it as well.