#!/bin/tcsh # ---------------------------------------------------------------------- # upgrade the AFNI binaries # # Update the package specified by "afni -ver" in the directory # specified by "which afni". Allow for overriding options of: # # -package PACKAGE # -bindir DIRECTORY # # terminate on any error, and be clear about which command failed # ---------------------------------------------------------------------- # apply any options # initialize options to 'unset' set abin = "" set package = "" if ( $#argv == 0 ) then set help = 1 else set help = 0 endif set testing = 0 set use_curl = 0 set ac = 1 while ( $ac <= $#argv ) if ( "$argv[$ac]" == "-bindir" ) then @ ac ++ if ( $ac > $#argv ) then echo "** missing parameter for option '-bindir'" exit endif set abin = $argv[$ac] else if ( "$argv[$ac]" == "-curl" ) then set use_curl = 1 else if ( "$argv[$ac]" == "-test" ) then set testing = 1 else if ( "$argv[$ac]" == "-package" ) then @ ac ++ if ( $ac > $#argv ) then echo "** missing parameter for option '-package'" exit endif set package = $argv[$ac] else if ( "$argv[$ac]" == "-help" ) then set help = 1 endif @ ac ++ end # if requested, show help and exit if ( $help ) then set prog = `basename $0` echo "------------------------------------------------------------" echo "$prog - upgrade AFNI binaries" echo "" echo "Update the AFNI binaries, either via '-defaults' or by the" echo "'-bindir' and/or '-package' options." echo "" echo "examples:" echo "" echo " $prog -defaults" echo " $prog -package linux_xorg7" echo " $prog -package linux_xorg7 -bindir ~/abin" echo "" echo "options:" echo "" echo " -help : show this help" echo "" echo " -bindir ABIN : set AFNI binary directory to ABIN" echo " -curl : default to curl instead of wget" echo " -defaults : install current package into abin" echo "" echo " This would be the method to 'update the package that I" echo " am currently using'." echo "" echo " The package would be decided by 'afni -ver' and the" echo " directory would come from 'which afni'. If either of" echo " these is not appropriate, please specify them as below." echo "" echo " -package PACKAGE : install distribution package PACKAGE" echo " -testing : just attempt the download and quit" echo "" echo "Note that the user must have write permissions in the ABIN" echo "directory." echo "" exit endif # possibly apply default binary directory if ( $abin == "" ) then set abin = `which afni` if ( $status ) then echo "** failed 'which afni'" exit endif # and nuke the trailing 'afni' set abin = $abin:h endif # possibly apply default package if ( $package == "" ) then set package = `afni -ver | grep binary | awk '{print $3}' | sed 's/://g'` if ( $status ) then echo "** failed setting package from 'afni -ver'" exit endif endif # test for existence of wget or curl which wget >& /dev/null set missing_wget = $status which curl >& /dev/null set missing_curl = $status if ( $testing ) echo "-- wget, curl status = $missing_wget, $missing_curl" if ( $missing_wget && $missing_curl ) then echo "" echo "** programs wget and curl are missing, please install *either*," echo " or look it up on the AFNI message board:" echo " http://afni.nimh.nih.gov/afni/community/board" echo "" exit endif # default to wget, else use curl set prog = ( "wget" ) if ( $use_curl || $missing_wget ) set prog = ( "curl" "-O" ) # make sure package is set to the base name if ( $package =~ *.tgz ) set package = $package:r echo "-- attempting to install package $package under $abin..." # ---------------------------------------------------------------------- # go to the binary directory and try to download the current package cd $abin # remove any old package if ( -f $package.tgz || -d $package ) then echo nuking old package... \rm -fr $package $package.tgz if ( $status ) then echo "** failed to remove old package $package" exit endif endif echo "++ downloading package $package..." $prog http://afni.nimh.nih.gov/pub/dist/tgz/$package.tgz if ( $status ) then echo "** failed to download package $package.tgz" exit endif if ( $testing ) then echo "just testing download via '$prog' done" exit endif echo "++ extracting package $package..." tar xfz $package.tgz if ( $status ) then echo "** failed to download package $package.tgz" exit endif # ---------------------------------------------------------------------- # if this package is actually new, install it cmp -s afni $package/afni if ( ! $status ) then echo "++ no update needed" \rm -fr $package $package.tgz exit endif echo "++ update needed, installing..." \mv $package/* . if ( $status ) then echo "** failed to overwrite existing package, exiting..." exit endif rmdir $package \rm -f $package.tgz echo "done, yay"