Linux ts3client_runscript.sh improvement(?)

For those of us who prefer to open TeamSpeak3 through the terminal (because of reasons). You might enjoy the changes I made to ts3client_runscript.sh (as an extension, I don’t actually change the existing script).

I have the personal preference of placing TeamSpeak3 under /opt/teamspeak3/, but in doing so I realised adding this directory to my PATH results in all kinds of things ‘leaking’ into the shell’s aliases (which we really do not care about).
To fix this, I created the dir: /opt/teamspeak3/bin/, copied said runscript into it and changed it into the following:

/opt/teamspeak3/bin/ts3

#!/bin/bash

cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"

#If the bundled openssl is used, the app needs to find out where the CA certs
#are located. This needs to be done with the help of openssl installed on the
#system, before we include "." in the LD_LIBRARY_PATH.

#First test if the bundled libssl is used
#If bundeled libssl is used and SSL_CERT_FILE and SSL_CERT_DIR are not already set. 
TS3_PATH="/opt/teamspeak3/"
if [ -f "${TS3_PATH}/libssl.so.1.0.0" -a -x "$(command -v openssl)" -a -z "${SSL_CERT_FILE+x}" -a -z "${SSL_CERT_DIR+x}" ]
then
  #Set them to sane defaults.

  #Get ssl dir according to system openssl
  OPENSSL_DIR="$(openssl version -d | grep -Po '(?<=\").*(?=\")')"

  #Is cert.pem located there?
  if [ -f "${OPENSSL_DIR}/cert.pem" ]
  then
    #Use this file
    export SSL_CERT_FILE="${OPENSSL_DIR}/cert.pem"

  #Is certs dir located there?
  elif [ -d "${OPENSSL_DIR}/certs" ]
  then
    #Use this dir
    export SSL_CERT_DIR="${OPENSSL_DIR}/certs"
  else
    #An unknown configuration was found. Or openssl/ca certificates were not
    #installed
    echo "Could not find CA certificates location"
    exit 3
  fi
fi

export KDEDIRS=
export KDEDIR=
export QTDIR="${TS3_PATH}"
export QT_PLUGIN_PATH="${TS3_PATH}"
export LD_LIBRARY_PATH="${TS3_PATH}:${LD_LIBRARY_PATH}"

# Enable logging to stdout when '--log' is provided
ENABLE_STDOUT_LOG=0
if [ -n "${1+x}" ] && [ "${1}" == "--log" ]; then
    ENABLE_STDOUT_LOG=1
fi

if [ -e "${TS3_PATH}/ts3client_linux_x86" ]; then
    if [ "${ENABLE_STDOUT_LOG}" -eq "0" ]; then
        sh -c "${TS3_PATH}/ts3client_linux_x86" [email protected] &> /dev/null &
    else
        sh -c "${TS3_PATH}/ts3client_linux_x86" [email protected]
    fi  
else
    if [ "${ENABLE_STDOUT_LOG}" -eq "0" ]; then
        sh -c "${TS3_PATH}/ts3client_linux_amd64" [email protected] &> /dev/null &
    else
        sh -c "${TS3_PATH}/ts3client_linux_amd64" [email protected]
    fi  
fi

What this allows you to do, once /opt/teamspeak3/bin is added to PATH, is run TeamSpeak from the terminal, where it doesn’t ‘eat up your terminal’ - or have the program running in the terminal for as long as the process is active - and it lets you not care about the logs which are spit out to stdout.

To run TeamSpeak: ts3
To run TeamSpeak with logs in stdout (aka normal behaviour): ts3 --log

If it’s useful to anyone, great! If not, oh well. :slight_smile:

Quick edit: if you have a preference to place (run) scripts under, don’t be afraid to place it there.
The paths to binaries are corrected to not use a relative path from where the script is, but the absolute path specified @ line 11 (a.k.a. please change TS3_PATH="/opt/teamspeak3/" to wherever you placed TeamSpeak3).

1 Like
twitch instagram twitter facebook