| 1 | #!/bin/bash |
| 2 | |
| 3 | # This installsardata script: |
| 4 | # 1) Verifies the latest SearchAndRescue datafile or a link to it is |
| 5 | # located in the current directory |
| 6 | # 2) Checks whether it has been run with root privileges |
| 7 | # 3) Verifies the datafile is not corrupted |
| 8 | # 4) Creates the data installation directory if it doesn't exist |
| 9 | # 5) Deletes old datafiles if there are any |
| 10 | # 6) Installs the latest datafiles |
| 11 | |
| 12 | #Definitions |
| 13 | # !!! Update line below for each new data file release !!! |
| 14 | sar_datafile=SearchAndRescue-data-1.6.1.tar.gz |
| 15 | sar_data_install_dir="/usr/share/games/searchandrescue" |
| 16 | sar_data_source_directory="" |
| 17 | |
| 18 | # Check SearchAndRescue Datafile is in local directory |
| 19 | if !([ -f $sar_datafile ]) |
| 20 | then |
| 21 | echo "Please check that $sar_datafile or a link to it is in the current directory" |
| 22 | exit 2 |
| 23 | fi |
| 24 | |
| 25 | |
| 26 | # Verify SearchAndRescue datafile is not corrupted |
| 27 | if !( tar tzf $sar_datafile &>/dev/null ) |
| 28 | then echo "$sar_datafile is corrupted, please get another copy and re-run this script" |
| 29 | exit 3 |
| 30 | fi |
| 31 | |
| 32 | |
| 33 | # Have we been invoked with root privileges? |
| 34 | eval `id | sed 's/[^a-z0-9=].*//'` |
| 35 | if [ "${uid:=0}" -ne 0 ] |
| 36 | then |
| 37 | echo "Data installation requires root privileges. For Debian based distros (e.g. Ubuntu), use sudo $0 <Enter>." |
| 38 | echo "For other distros, type su <Enter>, then $0 <Enter>." |
| 39 | exit 4 |
| 40 | fi |
| 41 | |
| 42 | |
| 43 | #Remember current directory |
| 44 | sar_data_source_directory=`pwd` |
| 45 | |
| 46 | # Check if there is already a SearchAndRescue datafile directory and if so, delete all contents |
| 47 | # Otherwise, create the directory |
| 48 | if [ -d $sar_data_install_dir ] |
| 49 | then |
| 50 | rm -fr $sar_data_install_dir/* >/dev/null |
| 51 | echo "Old Datafiles deleted in $sar_data_install_dir" |
| 52 | else |
| 53 | mkdir -p $sar_data_install_dir |
| 54 | fi |
| 55 | |
| 56 | |
| 57 | #Extract datafile to the final location and report success or otherwise |
| 58 | cd $sar_data_install_dir |
| 59 | if ( tar xzf $sar_data_source_directory/$sar_datafile &>/dev/null ) |
| 60 | then echo "$sar_datafile successfully extracted to $sar_data_install_dir" |
| 61 | else |
| 62 | echo "Error extracting $sar_datafile to $sar_data_install_dir" |
| 63 | fi |
| 64 |