From 81d086323e4bd9e15c7576f6304e706deaf87f1e Mon Sep 17 00:00:00 2001 From: Harrison Nicholls Date: Fri, 19 Jul 2024 09:44:11 +0100 Subject: [PATCH] Updated downloader script to check for already-existing files --- get_data.sh | 118 +++++++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 51 deletions(-) diff --git a/get_data.sh b/get_data.sh index e315b14d..c05b3157 100755 --- a/get_data.sh +++ b/get_data.sh @@ -2,6 +2,9 @@ # Download and unpack required and/or optional data # All files can be found on OSF at https://osf.io/8dumn/ +# Exit script if any of the commands fail +set -e + # Check that curl is installed if ! [ -x "$(command -v curl)" ]; then echo 'ERROR: curl is not installed.' >&2 @@ -47,64 +50,77 @@ function osf { # target file path tgt="$2/$3" - rm -f $tgt - echo " $1 > $tgt" + + # exists? + if [[ -f "$tgt" ]]; then + echo " $1 > file already exists" + return 0 + fi # get data + echo " $1 > $tgt" mkdir -p $2 curl -LsS "https://osf.io/download/$1/" > $tgt -} - -# Handle user input -case $1 in - "basic") - echo $help_basic - - osf qmp4e $res/spectral_files/Oak/318/ Oak.sf - osf 5fxr7 $res/spectral_files/Oak/318/ Oak.sf_k - - osf heuza $res/spectral_files/Dayspring/48/ Dayspring.sf - osf c5jv3 $res/spectral_files/Dayspring/48/ Dayspring.sf_k - - osf b5gsh $res/spectral_files/Dayspring/256/ Dayspring.sf - osf dn6wh $res/spectral_files/Dayspring/256/ Dayspring.sf_k - osf 2qdu8 $res/stellar_spectra sun.txt - ;; - - "highres") - echo $help_highres - - osf p672d $res/spectral_files/Honeyside/4096/ Honeyside.sf - osf ujb4z $res/spectral_files/Honeyside/4096/ Honeyside.sf_k - ;; - - "steam") - echo $help_steam - - osf 6rvfe $res/spectral_files/Frostflow/16/ Frostflow.sf - osf kxve8 $res/spectral_files/Frostflow/16/ Frostflow.sf_k - - osf 9n6mw $res/spectral_files/Frostflow/48/ Frostflow.sf - osf xfap8 $res/spectral_files/Frostflow/48/ Frostflow.sf_k - - osf mnvyq $res/spectral_files/Frostflow/256/ Frostflow.sf - osf tzsgc $res/spectral_files/Frostflow/256/ Frostflow.sf_k - ;; + return 0 +} - "stellar") - echo $help_stellar - osf mabp2 $res/stellar_spectra trappist-1.txt - osf rk7mj $res/stellar_spectra eps-eri.txt - osf agsrq $res/stellar_spectra hd97658.txt - osf ehfsy $res/stellar_spectra gj1214.txt - ;; +# Handle request for downloading a group of data +function handle_request { + case $1 in + "basic") + echo $help_basic + + osf qmp4e $res/spectral_files/Oak/318/ Oak.sf + osf 5fxr7 $res/spectral_files/Oak/318/ Oak.sf_k + + osf heuza $res/spectral_files/Dayspring/48/ Dayspring.sf + osf c5jv3 $res/spectral_files/Dayspring/48/ Dayspring.sf_k + + osf b5gsh $res/spectral_files/Dayspring/256/ Dayspring.sf + osf dn6wh $res/spectral_files/Dayspring/256/ Dayspring.sf_k + + osf 2qdu8 $res/stellar_spectra sun.txt + ;; + + "highres") + echo $help_highres + + osf p672d $res/spectral_files/Honeyside/4096/ Honeyside.sf + osf ujb4z $res/spectral_files/Honeyside/4096/ Honeyside.sf_k + ;; + + "steam") + echo $help_steam + + osf 6rvfe $res/spectral_files/Frostflow/16/ Frostflow.sf + osf kxve8 $res/spectral_files/Frostflow/16/ Frostflow.sf_k + + osf 9n6mw $res/spectral_files/Frostflow/48/ Frostflow.sf + osf xfap8 $res/spectral_files/Frostflow/48/ Frostflow.sf_k + + osf mnvyq $res/spectral_files/Frostflow/256/ Frostflow.sf + osf tzsgc $res/spectral_files/Frostflow/256/ Frostflow.sf_k + ;; + + "stellar") + echo $help_stellar + osf mabp2 $res/stellar_spectra trappist-1.txt + osf rk7mj $res/stellar_spectra eps-eri.txt + osf agsrq $res/stellar_spectra hd97658.txt + osf ehfsy $res/stellar_spectra gj1214.txt + osf 2qdu8 $res/stellar_spectra sun.txt + ;; + + *) + echo "$help" + return 0 + ;; + esac + return 0 +} - *) - echo "$help" - exit 1 - ;; -esac +handle_request $1 echo "Done!"