#!/bin/tcsh -f
#(ie run the tshell on this but don't read the .cshrc or .tcshrc)

echo version = 1.01 of getdelilabundle 2024 Mar 15
# 2024 Mar 15, 1.01: clean up, handle block
# 2018 Nov 22, 1.00: origin 

echo 'useage: delilabundle'
echo 'Get the delila bundle of programs and unpack them in ~/bin'
set url = https://alum.mit.edu/www/toms/delilabundle.zip 
set db  = delilabundle
set dbz = delilabundle.zip
set dbsize = 7459416 # current size as of 2024 Mar 15

cd /tmp
echo "Working in `pwd`"
curl --location -o $dbz $url
if (-f $dbz) then
   if (`file $dbz | grep -i 'Zip archive' | wc -l` > 0) then
      echo "Got the zip archive:"
      ls -lt $dbz
   else
      echo "Failed to get the zip archive $dbz"
      if (`file $dbz | grep -i 'text' | wc -l` > 0) then
         set blockmsg = 'Content blocked by DHHS/NIH'
         if (`grep "$blockmsg" $dbz|wc -l` > 0) then
            echo $blockmsg
            exit
         else
            echo "************** text of $dbz: **************"
            cat $dbz
            echo "************** Unknown download blockage **************"
            exit
         endif
      endif
   endif
   if (`cat $dbz |  wc -c` < $dbsize) then
      echo "The $dbz is too small\! Something is wrong."
      exit
   endif

   echo "got delilabundle.zip in /tmp"
   if (-d ~/bin) then
      cd ~/bin
      mv /tmp/delilabundle.zip .
      unzip delilabundle.zip
      mv delilabundle/* ~/bin
      rmdir delilabundle
      # file * |grep -v 64-bit
   else
      echo "you need a ~/bin directory to store the delila programs"
   endif
else
   echo "failed to get delilabundle.zip from $url"
endif
