File ts3-reset-query-admin.sh of Package teamspeak3-server

#!/bin/sh

username='serveradmin'
db="/var/lib/teamspeak3-server/ts3server.sqlitedb"

if [ ! -x /usr/bin/openssl ]; then
  echo "/usr/bin/openssl not found - please install openssl!"
  exit 1
fi

# create random password with 12 characters
pw=$(tr -dc "A-Za-z0-9_!%=+" < /dev/urandom | head -c 12)
echo "Resetting Teamspeak 'serveradmin' password..."

encoded=$(echo -n "$pw" | openssl dgst -binary -sha1 | openssl base64)

if sqlite3 "$db" "UPDATE clients SET client_login_password='$encoded' WHERE client_login_name='$username'"; then
  s=$(sqlite3 "$db" "SELECT client_login_password from clients WHERE client_login_name='$username'")
  if [ "$encoded" = "$s" ]; then
    echo "Success! Write down the new password for $username:"
    echo "$pw"
  else
    echo "Database update failed. The update command seems to have succeeded, but the new password was not saved!"
    echo "tried to set encoded password='$encoded'"
    echo "encoded password in database='$s'"
  fi
else
  echo "Database update failed!"
fi
openSUSE Build Service is sponsored by