#! /bin/sh # # Download magnetic models for use by GeographicLib::MagneticModel. # # Copyright (c) Charles Karney (2011-2019) and # licensed under the MIT/X11 License. For more information, see # https://geographiclib.sourceforge.io/ DEFAULTDIR="/usr/local/share/GeographicLib" SUBDIR=magnetic NAME=magnetic MODEL=magneticmodel CLASS=MagneticModel TOOL=MagneticField EXT=wmm.cof usage() { cat <&2; exit 1 ;; esac done shift `expr $OPTIND - 1` if test $# -eq 0; then usage 1>&2; exit 1 fi test -d "$PARENTDIR"/$SUBDIR || mkdir -p "$PARENTDIR"/$SUBDIR 2> /dev/null if test ! -d "$PARENTDIR"/$SUBDIR; then echo Cannot create directory $PARENTDIR/$SUBDIR 1>&2 exit 1 fi TEMP= if test -z "$DEBUG"; then trap 'trap "" 0; test "$TEMP" && rm -rf "$TEMP"; exit 1' 1 2 3 9 15 trap 'test "$TEMP" && rm -rf "$TEMP"' 0 fi TEMP=`mktemp -d -q -t $NAME-XXXXXXXX` if test -z "$TEMP" -o ! -d "$TEMP"; then echo Cannot create temporary directory 1>&2 exit 1 fi WRITETEST="$PARENTDIR"/$SUBDIR/write-test-`basename $TEMP` if touch "$WRITETEST" 2> /dev/null; then rm -f "$WRITETEST" else echo Cannot write in directory $PARENTDIR/$SUBDIR 1>&2 exit 1 fi set -e cat > $TEMP/all < /dev/null; then echo $1 else case "$1" in all ) cat $TEMP/all ;; minimal ) echo wmm2020; echo igrf12 ;; * ) if test -n "$FORCE"; then echo $1 else echo Unknown $MODEL $1 1>&2 exit 1 fi ;; esac fi shift done > $TEMP/list sort -u $TEMP/list > $TEMP/todo while read file; do if test -z "$FORCE" -a -s $PARENTDIR/$SUBDIR/$file.$EXT; then echo $PARENTDIR/$SUBDIR/$file.$EXT already installed, skipping $file... echo $file >> $TEMP/skip continue fi echo download $file.tar.bz2 ... echo $file >> $TEMP/download URL="https://downloads.sourceforge.net/project/geographiclib/$SUBDIR-distrib/$file.tar.bz2?use_mirror=autoselect" ARCHIVE=$TEMP/$file.tar.bz2 wget -O$ARCHIVE $URL echo unpack $file.tar.bz2 ... tar vxojf $ARCHIVE -C $PARENTDIR echo $MODEL $file installed. done < $TEMP/todo if test "$DEBUG"; then echo Saving temporary directory $TEMP fi echo if test -s $TEMP/download; then n=`wc -l < $TEMP/download` s=; test $n -gt 1 && s=s cat <