#!/bin/bash #------ Global configuration section ---------# TMP_DIR=/tmp BIN_DIR=/usr/local/bin #------ Utility Functions ---------# # Column number to place the status message RES_COL=70 # Command to move out to the configured column number MOVE_TO_COL="echo -en \\033[${RES_COL}G" # Command to set the color to SUCCESS (Green) SETCOLOR_SUCCESS="echo -en \\033[1;32m" # Command to set the color to FAILED (Red) SETCOLOR_FAILURE="echo -en \\033[1;31m" # Command to set the color back to normal SETCOLOR_NORMAL="echo -en \\033[0;39m" # Function to print the SUCCESS status echo_success() { $MOVE_TO_COL echo -n "[" $SETCOLOR_SUCCESS echo -n $" OK " $SETCOLOR_NORMAL echo -n "]" echo -ne "\r" echo return 0 } # Function to print the FAILED status message echo_failure() { $MOVE_TO_COL echo -n "[" $SETCOLOR_FAILURE echo -n $"FAILED" $SETCOLOR_NORMAL echo -n "]" echo -ne "\r" echo } # Function to print the FAILED status message and exit echo_fatal() { $MOVE_TO_COL echo -n "[" $SETCOLOR_FAILURE echo -n $"FAILED" $SETCOLOR_NORMAL echo -n "]" echo -ne "\r" echo exit 1 } #------ Set up bash strict mode ---------# #makes xtrace output more useful export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' #error out on undefined variables set -o nounset #prevent errors in a pipeline from being masked set -o pipefail #trap errors so they can't fail silently trap 'ERRNO=$?; echo "$0: line $LINENO: [!] ERROR executing $BASH_COMMAND" 1>&2; exit $ERRNO' ERR # check for root; if not run as root the script will restart itself as through sudo [[ $UID = 0 ]] || exec sudo "$0" cd $TMP_DIR || exit 1 echo -n "Downloading TrID..." if wget -O trid_linux_64.zip "http://mark0.net/download/trid_linux_64.zip" &>/dev/null ; then echo_success else echo_fatal fi echo -n "Unzipping TrID..." if unzip -o -qq trid_linux_64 -d $BIN_DIR &>/dev/null ; then echo_success else echo_fatal fi echo -n "Making TrID executable..." if chmod +x $BIN_DIR/trid &>/dev/null ; then echo_success else echo_fatal fi #clean up zip file rm -r trid_linux_64.zip echo -n "Downloading TrID definitions..." if wget -O triddefs.zip "http://mark0.net/download/triddefs.zip" &>/dev/null ; then echo_success else echo_fatal fi echo -n "Unzipping TrID definitions..." if unzip -o -qq triddefs -d $BIN_DIR ; then echo_success else echo_fatal fi #clean up zip file rm -r triddefs.zip echo "" echo 'Done installing TrID \( ゚ヮ゚)/'