1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#!/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.3.0.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 <Enter>."
echo "For other distros, type su <Enter>, then $0 <Enter>."
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
|