#!/bin/bash # This installsardata script: # 1) Verifies the latest SearchAndRescue datafile or a link to it is # located in the current directory # 2) Checks whether it has been run with root privileges # 3) Verifies the datafile is not corrupted # 4) Creates the data installation directory if it doesn't exist # 5) Deletes old datafiles if there are any # 6) Installs the latest datafiles #Definitions # !!! Update line below for each new data file release !!! sar_datafile=SearchAndRescue-data-1.6.1.tar.gz sar_data_install_dir="/usr/share/games/searchandrescue" sar_data_source_directory="" # Check SearchAndRescue Datafile is in local directory if !([ -f $sar_datafile ]) then echo "Please check that $sar_datafile or a link to it is in the current directory" exit 2 fi # Verify SearchAndRescue datafile is not corrupted if !( tar tzf $sar_datafile &>/dev/null ) then echo "$sar_datafile is corrupted, please get another copy and re-run this script" exit 3 fi # Have we been invoked with root privileges? eval `id | sed 's/[^a-z0-9=].*//'` if [ "${uid:=0}" -ne 0 ] then echo "Data installation requires root privileges. For Debian based distros (e.g. Ubuntu), use sudo $0 ." echo "For other distros, type su , then $0 ." exit 4 fi #Remember current directory sar_data_source_directory=`pwd` # Check if there is already a SearchAndRescue datafile directory and if so, delete all contents # Otherwise, create the directory if [ -d $sar_data_install_dir ] then rm -fr $sar_data_install_dir/* >/dev/null echo "Old Datafiles deleted in $sar_data_install_dir" else mkdir -p $sar_data_install_dir fi #Extract datafile to the final location and report success or otherwise cd $sar_data_install_dir if ( tar xzf $sar_data_source_directory/$sar_datafile &>/dev/null ) then echo "$sar_datafile successfully extracted to $sar_data_install_dir" else echo "Error extracting $sar_datafile to $sar_data_install_dir" fi