TV Host Mac PKG Install BASH Script

This will use expect to enter in the admin password for you when sudo is invoked. You can deploy this to your users via ARD if you like. You need to Add Host via teamviewer.com and download the generic pkg and assignment_tool files just like my PowerShell script.

#!/bin/bash

# Usage: bash Download-TV.sh -pkg_file="http://website.com/TeamViewer_Host.pkg" -assignment_tool="http://website.com/OSX/TeamViewer_Assignment" -config_id="$config_id" -api_token="$api_token" -sudo_account="admin" -sudo_password="adminpw"

for i in "$@"
do
case $i in
-pkg_file=*)
PKG_FILE="${i#*=}"
shift # past argument=value
;;
-config_id=*)
CONFIG_ID="${i#*=}"
shift # past argument=value
;;
-assignment_tool=*)
ASSIGNMENT_TOOL="${i#*=}"
shift # past argument=value
;;
-api_token=*)
API_TOKEN="${i#*=}"
shift # past argument=value
;;
-sudo_account=*)
SUDO_ACCOUNT="${i#*=}"
shift # past argument=value
;;
-sudo_password=*)
SUDO_PASSWORD="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
;;
esac
done

TMP_DIR="/tmp/"

PKG_SAVE=$TMP_DIR"Install_TeamViewerHost-idc"$CONFIG_ID".pkg"
ASSIGNMENT_SAVE=$TMP_DIR"TeamViewer_Assignment"

# echo "Dowloading TeamViewer Host from $PKG_FILE saving as Install $PKG_SAVE"

/usr/bin/curl -o "$PKG_SAVE" "$PKG_FILE"
/usr/bin/curl -o "$ASSIGNMENT_SAVE" "$ASSIGNMENT_TOOL"

# cd $TMPDIR
echo "Making TeamViewer_Assignment POSIX executable...$ASSIGNMENT_SAVE"
/bin/chmod +x $ASSIGNMENT_SAVE

# now we need to tickle because we need sudo privs here
echo "creating tickle file to run installer stuff sudo"
cat >/tmp/expect.exp <<EOL
#!/usr/bin/expect

## Access CLI

spawn /usr/bin/su "$SUDO_ACCOUNT"
expect "*?assword:*"
send -- "$SUDO_PASSWORD\r"

send -- /usr/bin/sudo\ /usr/sbin/installer\ -pkg\ "$PKG_SAVE"\ -target\ /\ -verboseR\r

expect "*?assword:*"
send -- "$SUDO_PASSWORD\r"

expect "The upgrade was successful."

send -- /usr/bin/sudo\ $ASSIGNMENT_SAVE\ -wait=5\ -verbose\ -apitoken\ "$API_TOKEN"\ -datafile\ "/Library/Application\ Support/TeamViewer\ Host/Custom\ Configurations/$CONFIG_ID/AssignmentData.json"\r

expect "*?assword:*"
send -- "$SUDO_PASSWORD\r"
expect elf
EOL

echo "running the tickle file (goochie goochie goo)"
/usr/bin/expect /tmp/expect.exp

echo "cleanup now"
/bin/rm -rf /tmp/expect.exp

 

Tagged: