#!/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 # ---------------------------------------------------------------------- set prog = `basename $0` set hostname = afni.nimh.nih.gov set hostproto = https:// set hostsite = $hostproto$hostname set sysname = `uname -s` if ( $status ) then echo "** command failure: uname -s" set sysname = "" endif # ---------------------------------------------------------------------- # history section goto POST_HIST SHOW_HIST: cat << EOF ------------------------------------------------------------------------------- history for $prog : ... : a few updates 1.0 07 Mar 2012 : existing package and install dir no longer required for -d 13 Sep 2012 : download and run the current version on the website - added option -no_recur 21 Dec 2012 : do rehash before apsearch - check download by looking for string in this file 01 Nov 2013 : Darwin defaults to 10.7 package 01 Dec 2013 : added -prog_list for Ziad 18 Dec 2013 : added check for system programs, -sys_ok and -help_system_progs 14 Jan 2014 : added more system programs 01 May 2014 : added -quick option; fixed sync of backup, was nesting 15 Jan 2015 : if bad option and current version, fail after version check 08 Apr 2015 : added -revert (zsaad and rickr) 25 Aug 2015 : update path and AFNI tab completion on initial install 2.0 08 Feb 2016 : access afni site via https protocol 2.1 16 Feb 2016 : added -ver and initial statement of version 2.2 19 Feb 2016 : minor text changes (note get_prog and appease dglen) 2.3 29 Mar 2016 : added -no_cert_verify to omit certificate verification 2.4 30 Mar 2016 : possibly udpate .bashrc after .cshrc 2.5 07 Apr 2016 : added -proto and -test_protos options 2.6 08 Apr 2016 : save -test_protos results 2.7 28 Apr 2016 : added -local_package option 2.8 04 May 2016 : added -do_dotfiles and -do_extras (dot files and apsearch are now only done on request) 2.9 05 May 2016 : -defaults implies -do_dotfiles and -apsearch yes 3.0 02 Feb 2017 : default OS X package is macosx_10.7_local 3.1 08 Feb 2017 : (by David Abbott) fix crash in and finish case of -local_package with updated install script 3.2 23 Jun 2017 : unalias grep; only update cur_afni if not abin 3.3 10 Jul 2017 : if bindir is relative, fail without -no_recur 3.4 21 Jul 2017 : oops, apparently that needs quotes to block eval 3.5 04 Apr 2018 : missed sysname 3.6 16 Oct 2018 : default OS X package is macos_10.12_local - add newline before dotfile appends 3.7 22 Jan 2019 : check for obsolete packages - add -show_obsoletes, -show_obsoletes_grep and -show_system_progs ------------------------------------------------------------------------------- EOF exit POST_HIST: # end history section # ---------------------------------------------------------------------- set aub_version = "3.7, January 22, 2019" # make a growing list of obsolete packages, particularly in case the user # tries to upgrade one of them and fails (at "no update needed") set obsolete_list = ( \ linux_gcc32 linux_gcc33_64 linux_glibc22 \ NIH.openSUSE.11.4_64 \ linux_fedora_21_64 linux_fedora_25_64 \ solaris29_suncc solaris29_suncc_64 \ macosx_10.5_Intel_64 macosx_10.6_Intel_64 \ macosx_10.7_Intel_64 macosx_10.7_local \ macosx_10.8_gcc macosx_10.8_icc \ ) # ---------------------------------------------------------------------- # apply any options # initialize options to 'unset' set abin = "" set package = "" set local_package = "" # existing .tgz package to use (no download) set prog_list = () # update programs or entire package set tmp_dir = ".tmp.install" # should start with '.' set make_backup = 1 # backup previous binaries set sys_ok = 0 # OK to update having system programs # if any $system_progs are in the abin, updates # should not go through this script set system_progs = ( apt-get at cc cpp cmp diff du gcc less man md5sum od \ passwd perl python scp srm sudo vi vim wc xterm yum ) set show_system_progs = 0 set show_obsoletes = 0 set show_obsoletes_grep = 0 # greppable if ( $#argv == 0 ) then set help = 1 else set help = 0 endif set testing = 0 set test_protos = 0 # test download protocols set use_curl = 0 set do_extras = 0 # possibly include apearch and dotfiles set do_apsearch = 0 # run apserach -update_all_afni_help set do_dotfiles = 0 # if needed, initialize dotfiles set do_recur = 1 # download a new version of @uab, first set quick = 0 # no fancies (recur, apsearch) set revert = 0 # revert binaries to those in backup directory set cert_verify = 1 # whether to verify CA certificate via SSL/TLS set use_curl = 0 set bad_opt = '' # if bad_opt and do_recur, see if we continue set ac = 1 while ( $ac <= $#argv ) if ( "$argv[$ac]" == "-apsearch" ) then @ ac ++ if ( $ac > $#argv ) then echo "** missing parameter for option '-apsearch'" exit 1 endif set resp = `echo $argv[$ac] | cut -b1` if ( $resp == 'N' || $resp == 'n' ) then set do_apsearch = 0 else set do_apsearch = 1 endif else if ( "$argv[$ac]" == "-bindir" ) then @ ac ++ if ( $ac > $#argv ) then echo "** missing parameter for option '-bindir'" exit 1 endif set abin = $argv[$ac] else if ( "$argv[$ac]" == "-curl" ) then set use_curl = 1 else if ( "$argv[$ac]" == "-d" || "$argv[$ac]" == "-defaults" ) then set defaults = 1 set do_apsearch = 1 set do_dotfiles = 1 else if ( "$argv[$ac]" == "-do_dotfiles" ) then set do_dotfiles = 1 else if ( "$argv[$ac]" == "-do_extras" ) then set do_apsearch = 1 set do_dotfiles = 1 else if ( "$argv[$ac]" == "-help" ) then set help = 1 else if ( "$argv[$ac]" == "-help_sys_progs" ) then echo "" echo "system programs that would prevent an update:" echo " $system_progs" echo "" exit 0 else if ( "$argv[$ac]" == "-hist" ) then goto SHOW_HIST else if ( "$argv[$ac]" == "-local_package" ) then @ ac ++ if ( $ac > $#argv ) then echo "** missing parameter for option '-local_package'" exit 1 endif set local_package = $argv[$ac] # allow missing .tgz if ( ! -f $local_package && -f $local_package.tgz ) then set local_package = $local_package.tgz endif if ( ! -f $local_package ) then echo "** missing -local_package file '$local_package'" exit 1 endif else if ( "$argv[$ac]" == "-package" ) then @ ac ++ if ( $ac > $#argv ) then echo "** missing parameter for option '-package'" exit 1 endif set package = $argv[$ac] else if ( "$argv[$ac]" == "-prog_list" ) then @ ac ++ set resp = '' while ( $ac <= $#argv ) set resp = `echo $argv[$ac] | cut -b1` if ( "$resp" == '-' ) break set prog_list = ( $prog_list $argv[$ac] ) @ ac ++ end if ( $#prog_list == 0 ) then echo "** missing parameter(s) for option '-prog_list'" exit 1 endif # decide on increment here, and continue continue else if ( "$argv[$ac]" == "-proto" ) then @ ac ++ if ( $ac > $#argv ) then echo "** missing parameter for option '-proto'" exit 1 endif if ( $argv[$ac] == http || $argv[$ac] == https ) then set hostproto = ${argv[$ac]}:// else if ( $argv[$ac] == NONE ) then set hostproto = '' else # use as is set hostproto = $argv[$ac] endif else if ( "$argv[$ac]" == "-revert" ) then set revert = 1 else if ( "$argv[$ac]" == "-no_cert_verify" ) then # add options to turn verification off set cert_verify = 0 else if ( "$argv[$ac]" == "-no_recur" ) then set do_recur = 0 else if ( "$argv[$ac]" == "-quick" ) then set quick = 1 else if ( "$argv[$ac]" == "-show_obsoletes" ) then set show_obsoletes = 1 else if ( "$argv[$ac]" == "-show_obsoletes_grep" ) then set show_obsoletes = 1 set show_obsoletes_grep = 1 else if ( "$argv[$ac]" == "-show_system_progs" ) then set show_system_progs = 1 else if ( "$argv[$ac]" == "-sys_ok" ) then set sys_ok = 1 else if ( "$argv[$ac]" == "-ver" ) then echo $aub_version exit 0 else if ( "$argv[$ac]" == "-test" ) then set testing = 1 else if ( "$argv[$ac]" == "-test_protos" ) then set test_protos = 1 else # allow unknown options if $do_recur, but THEY MUST BE LAST if ( $do_recur ) then # check later, if we do not actually recur echo "** unknown option $argv[$ac], but might work in newer version" set bad_opt = "$argv[$ac]" else echo "** unknown option $argv[$ac]" exit 1 endif endif @ ac ++ end set tmpsite = $hostproto$hostname if ( $tmpsite != $hostsite ) then set hostsite = $tmpsite echo "-- updating hostsite to $hostsite" endif # in quick mode, turn off fancies, even if requested 1 May, 2014 [rickr] if ( $quick ) then set do_recur = 0 set do_apsearch = 0 set do_dotfiles = 0 endif # if abin and do_recur, abin must be absolute if ( $abin != "" && $do_recur ) then set c1 = `echo $abin | cut -b 1` if ( "$c1" != "/" ) then echo "** when -bindir is relative, please include -no_recur" echo " have -bindir = '$abin'" exit 1 endif endif # if requested, show help and exit if ( $help ) then cat << EOF ------------------------------------------------------------ $prog - upgrade AFNI binaries Update the AFNI binaries, either via '-defaults' or by the '-bindir' and/or '-package' options. examples: individual user: initial install or udpate The default package is linux_openmp_64 (Linux) or macos_10.12_local (OS X). The default binary directory is ~/abin. $prog -defaults -do_extras root user: initial install or udpate $prog -package linux_openmp_64 -bindir /usr/local/AFNIbin $prog -local_package linux_openmp_64.tgz -bindir /usr/local/AFNIbin other examples: $prog -defaults $prog -defaults -package macos_10.12_local $prog -package linux_openmp_64 $prog -package linux_openmp_64 -bindir ~/abin $prog -package linux_openmp_64 -programs suma 3dRSFC $prog -package linux_openmp_64 -programs file_tool python_scripts/*.py $prog -show_obsoletes $prog -local_package macos_10.12_local.tgz options: -help : show this help -help_sys_progs : list system programs that block update See -sys_ok for details. -apsearch yes/no : specify getting apsearch updates -bindir ABIN : set AFNI binary directory to ABIN -curl : default to curl instead of wget -defaults : install current package into abin -d : (short for -defaults) This would be the method to 'update the package that I am currently using'. This option implies -do_dotfiles and -apsearch yes. The package would be decided by 'afni -ver' and the directory would come from 'which afni'. If either of these is not appropriate, the package would be determined by the OS (Linux or OSX allowed, 32 or 64-bits), and the install dir would be ~/abin. If -bindir or -package cannot be determined, it must be supplied by the user. 26 Sep 2012 : -update_apsearch is applied by default (if installed afni is in PATH) -do_dotfiles : if needed, try to initialize dot files If .cshrc (or maybe .tcshrc) or .bashrc do not have the AFNI binary directory in the file (grep), add a line to update the PATH in each file. Both files are updated (if need be). * This option has no effect for the root user. -do_extras : do extra niceties (beyond simple install) This is a convenience option that implies: -apsearch yes -do_dotfiles -no_cert_verify : do not verify the server CA certificate This option is regarding SSL/TLS Certificate Verification via some CA (certificate authority) list. It may be needed if the client CA list does not recognize the certificate provided by the afni server. For curl, this appends the '--insecure' option. For wget, this appends the '--no-check-certificate' option. To check whether curl requires this, look for WinSSL in the output from: curl -V See https://curl.haxx.se/docs/sslcerts.html for details. -no_recur : do not download and run new @uab script -local_package PACKAGE : install local PACKAGE.tgz package This is a way to install an existing tgz file without needed to download it. -prog_list PROGRAMS : install given programs, not whole PACKAGE With this option, the listed programs would be installed, rather than the entire PACKAGE. Note: directories are not allowed (e.g. meica.libs) -package PACKAGE : install distribution package PACKAGE (see also -local_package) -prog_list PROGRAMS : install given programs, not whole PACKAGE With this option, the listed programs would be installed, rather than the entire PACKAGE. Note: directories are not allowed (e.g. meica.libs) For example, consider: -prog_list suma python_scripts/*.py In this case, suma and the individual python files would all end up in abin, with no directories. -proto PROTOCOL : access afni host via this PROTOCOL e.g. -proto http default: https Use this option to specify the download protocol. PROTOCOL may https, http or NONE (meaning not to prefix site name with any). -quick : quick mode, no fancies This option blocks unwanted or unneeded actions, mostly for testing. It basically applies: -no_recur -apsearch no -show_obsoletes : list any obsolete packages Display the set of AFNI packages that are no longer being updated. This is a terminal option. -show_obsoletes_grep : list any obsolete packages (easy to grep) Display the set of AFNI packages that are no longer being updated. This is the same as -show_obsoletes, but each line with a package name will start with "obsolete:", as in: obsolete: linux_gcc32 obsolete: linux_gcc33_64 obsolete: macosx_10.7_Intel_64 obsolete: macosx_10.7_local This is a terminal option. -show_system_progs : show system programs that do no belong in abin Display the set of system utilities that suggest afni is in a system binary directory, rather than a user's abin. If any such program is in the AFNI binaries directory, an update will not be allowed. This was introduced to protect from 'afni' being in under /usr/bin in Neurodebian. -sys_ok : OK to update, even if system progs found If any system program (e.g. man, sudo, xterm, yum) is found, the default behavior is not to continue the update. Note that if 'afni -ver' shows a Debian package, then updates should be done via apt-get, not this program. Use -sys_ok to all the update to proceed. See -help_sys_progs for a list of checked system programs. -test : just attempt the download and quit -test_protos : test download protocols and exit -revert : revert binaries to previous version Revert the AFNI binaries to those in directory ABIN/auto_backup.PACKAGE, where ABIN would otherwise be considered the installation directory. Use this option if the last update of the binaries got you a lump of coal. There should be only 1 backup to revert to. One cannot revert back 2 levels, say. Note that the user must have write permissions in the ABIN directory. EOF exit endif echo "-- running $prog version $aub_version" # note any current AFNI location which afni >& /dev/null if ( $status ) then echo "-- no current AFNI package found in path..." set cur_afni = "" else set cur_afni = `which afni` set cur_afni = $cur_afni:h echo "-- have AFNI binaries under $cur_afni" endif # possibly apply default binary directory if ( $abin == "" ) then if ( $cur_afni == "" ) then echo "-- install dir: using default ~/abin" set abin = ~/abin else # have program, remove trailing 'afni' to get directory set abin = $cur_afni echo "-- install dir: using existing $abin" endif endif # check on -local_package (require $package == "") # file will be at: $local_package_dir/$local_package if ( $local_package != "" ) then if ( $package != "" ) then echo "** cannot use -local_package with -package" exit 1 endif if ( ! -f $local_package ) then echo "** -local_package file does not seem to exist: $local_package" exit 1 endif # get the directory of the file if ( $local_package == $local_package:h ) then set local_package_dir = `pwd` else if ( -d $local_package:h ) then # path to file cd $local_package:h set local_package_dir = `pwd` cd - # and clear the path set local_package = $local_package:t else echo "** cannot determine path to -local_package file, $local_package" exit 1 endif # use package for extensionless name set package = $local_package:r echo "-- will install from local package file: $local_package" endif # possibly apply default package if ( $package == "" ) then if ( $cur_afni != "" ) then set package = `afni -ver | \grep binary | awk '{print $3}' | sed 's/://g'` if ( $status || "$package" == "" ) then echo "** failed setting package from 'afni -ver'" exit 1 endif else # pick package based on OS (sysname is set above) set errs = 0 set cpuname = `uname -p` if ( $status ) then @ errs ++ set cpuname = "" endif if ( $errs > 0 ) then echo "** failed to note system and cpu, must specify -package" exit endif # simple cases for now, can expand later if ( $sysname == Linux ) then if ( $cpuname == x86_64 ) then set package = linux_openmp_64 else set package = linux_openmp endif else if ( $sysname == Darwin ) then # default to no.omp.glib for now set package = macos_10.12_local else @ errs ++ endif if ( $errs > 0 ) then echo "** unknown system $sysname/$cpuname, must specify -package" exit endif 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 " $hostsite/afni/community/board" echo "" exit 1 endif # default to wget, else use curl set get_prog = ( "wget" ) if ( $use_curl || $missing_wget ) set get_prog = ( curl -O -f ) # do we verify certificates via CA list? if not, speicify if ( ! $cert_verify ) then if ( $get_prog[1] == "wget" ) then set get_prog = ( $get_prog --no-check-certificate ) else if ( $get_prog[1] == "curl" ) then set get_prog = ( $get_prog --insecure ) else echo "** cert_verify: confused about get_prog: $get_prog" exit 1 endif endif echo "-- any downloads will be from $hostsite via $get_prog" echo "" # make sure package is set to the base name if ( $package =~ *.tgz ) set package = $package:r # rcr - entire package or just prog_list (though prog_list requires package) echo "-- attempting to install package $package under" if ( $#prog_list > 0 ) echo " (including only $#prog_list programs)" echo " install dir: $abin..." # ---------------------------------------------------------------------- # if the install dir does not exist, create it if ( -d $abin ) then echo "-- have install dir" else if ( $revert == 1 ) then echo "** error: no install directory to revert from" exit 1 endif echo "++ creating install dir" mkdir -pv $abin if ( $status ) then echo "** failed to create install dir, $abin" exit endif echo "" sleep 1 endif # note appropriate backup directory set date = `date +%Y_%m_%d` set backup_dir = auto_backup.$package # ---------------------------------------------------------------------- # go to the binary directory and check that we can write cd $abin # check permissions before doing anything if ( ! -w . ) then echo "** you do not have write permissions in the install directory" echo " (install dir = `pwd`)" exit 1 endif # ---------------------------------------------------------------------- # check to see if this is someplace that we should not be writing to # - if any of these programs exist, maybe this script is not appropriate set nerr = 0 foreach cprog ( $system_progs ) if ( -e $cprog ) then if ( $nerr == 0 ) echo "** found system program '$cprog'" @ nerr ++ endif end if ( $nerr > 0 && ! $revert ) then echo "** found $nerr system program(s)" if ( $sys_ok ) then echo "continuing from -sys_ok..." echo "" else echo "" echo "** error: refusing to update potential system directory" echo " (see -sys_ok in the -help output for details)" echo "" exit 1 endif endif # ====================================================================== # begin work (most work from temp dir) # ====================================================================== # ---------------------------------------------------------------------- # remove any old package if ( ! $revert && ( -f $package.tgz || -d $package ) ) then echo deleting old package $package.tgz ... \rm -fr $package $package.tgz if ( $status ) then echo "** failed to remove old package $package" exit 1 endif endif # remove any temp install directory if ( -d $tmp_dir ) then echo deleting old temporary directory... \rm -fr $tmp_dir endif # ---------------------------------------------------------------------- # create and enter temporary working directory; test whether update is needed echo "++ working in new temp dir, $tmp_dir" mkdir $tmp_dir if ( $status ) then echo "** failed to create new or remove old temp dir, $tmp_dir" exit 1 endif cd $tmp_dir # ---------------------------------------------------------------------- # first, make sure we run the latest @update.afni.binaries: # get a new version of this script to make sure we are current... # (sneaky suggestion by Bob) # download to a temp name, though if ( $do_recur ) then set temp_prog = tmp.$prog # temp name to run with set retry = 0 # use multiple attempts to get this set bin_root = $hostsite/pub/dist/bin set get_package = $bin_root/$package/$prog echo "++ getting install prog: $get_prog $package/$prog ..." echo $get_prog $get_package $get_prog $get_package # ----- might not exist: try twice and skip if fail 26 Sep 2012 if ( $status ) then set retry = 1 else # see if we have this text (and therefore the actual program) \grep 'upgrade the AFNI binaries' $prog > /dev/null if ( $status ) then set retry = 1 \rm -f $prog endif endif if ( $retry ) then set retry = 0 set ppp = linux_openmp_64 echo "** failed, trying $ppp/$prog ..." $get_prog $bin_root/$ppp/$prog if ( $status ) then set retry = 1 else # see if we have this text (and therefore the actual program) \grep 'upgrade the AFNI binaries' $prog > /dev/null if ( $status ) then set retry = 1 \rm -f $prog endif endif if ( $retry ) then echo "** failed again, skipping check for new installer" goto SKIP_RECUR endif endif # ----- okay, we have a new installer to check on # make sure it is executable if ( ! -x $prog ) then echo "-- fixing lost permissions on $prog" chmod +x $prog endif # see if there are any changes to apply cmp -s $prog ../$prog if ( $status ) then # use new version! echo "++ using updated $prog, instead..." echo "" # move it up to a temp name and run it (without further recursion) if ( -f ../$temp_prog ) \rm -f ../$temp_prog \mv $prog ../$temp_prog cd .. # so we don't sit in deleted directory # if local_package, we need to change the path to the file set args = ( $argv ) if ( $local_package != "" ) then set ind = 1 while ( $ind < $#args ) if ( "$args[$ind]" == "-local_package" ) then @ ind += 1 set args[$ind] = $local_package_dir/$local_package break else @ ind += 1 endif end endif echo "++ running: tcsh $temp_prog -no_recur $args" tcsh $temp_prog -no_recur $args set ss = $status if ( ! $ss ) then echo "...finished, removing temp version, $temp_prog" \rm -f $temp_prog endif exit $ss # exit with status of called program else echo "-- $prog is current, continuing with this version..." if ( "$bad_opt" != "" ) then echo "** unknown option $bad_opt" exit 1 endif endif else echo "-- skipping update of $prog" endif SKIP_RECUR: # ---------------------------------------------------------------------- # maybe we want to get local information and quit # (put this after recur, so that we still get updates, first) # system programs (that should not be in abin) if ( $show_system_progs ) then echo "" echo "the following programs should not appear in AFNI binary directory:" echo "" echo -n " " echo $system_progs | sed "s/ /\n /g" echo "" exit 0 endif # obsoletes if ( $show_obsoletes ) then echo "" echo "the following packages are no longer being updated/compiled:" echo "" # possibly allow the user easier way to grep for results if ( $show_obsoletes_grep ) then set space_str = " obsolete: " else set space_str = " " endif # This \n does not work on macs, so be slow for now... # echo -n "$space_str" # echo $obsolete_list | sed "s/ /\n$space_str/g" foreach oname ( $obsolete_list ) echo "$space_str$oname" end echo "" exit 0 endif # warn the user if the package is obsolete foreach oname ( $obsolete_list ) if ( "$package" == $oname ) then echo "" echo "** warning: package $package is no longer being updated" echo "" endif end # ---------------------------------------------------------------------- # maybe we want to test protocols and exit if ( $test_protos ) then echo "" echo "++ testing protocols from temp dir, `pwd`" set plist = ( http https '' ) # protocols set slist = () # status values set ind = 1 while ( $ind <= $#plist ) set pshort = $plist[$ind] if ( $pshort == '' ) then set proto = '' else set proto = ${pshort}:// endif set tmpsite = $proto$hostname set tmpprog = $tmpsite/pub/dist/bin/$package/$prog echo $get_prog $tmpprog $get_prog $tmpprog set st = $status # make sure we have a good download, even if $status is okay if ( ! $st ) then \grep 'upgrade the AFNI binaries' $prog > /dev/null set st = $status if ( $st ) then echo "** okay status but bad download" endif endif echo "" # rename old one if ( -f $prog ) \mv $prog save.$prog.$pshort set slist = ( $slist $st ) @ ind += 1 end echo "" set ind = 1 while ( $ind <= $#plist ) if ( $slist[$ind] ) then echo "failure ($slist[$ind]) for proto '$plist[$ind]'" else echo "success for proto '$plist[$ind]'" endif @ ind += 1 end echo "" exit 0 endif # ---------------------------------------------------------------------- # revert to previous version, if requrested if ( $revert ) then # revert to backup if ( ! -d ../$backup_dir ) then echo "** failed to find backup directory ../$backup_dir" exit 1 else echo "++ revert: under `pwd`, running:" echo " rsync -av ../$backup_dir/ ../" rsync -av ../$backup_dir/ ../ if ( $status ) then echo "** rsync failed" exit 1 else echo "-- binaries now replaced with those from $abin/$backup_dir" endif endif exit 0 endif # ---------------------------------------------------------------------- # just download single afni binary and compare # (if prog_list, use first prog in list) if ( $local_package == "" ) then if ( $#prog_list > 0 ) then set pp = $prog_list[1]:t # directories are not allowed (harder to download) foreach ppp ( $prog_list ) set prog = $ppp:t if ( -d ../$prog ) then echo "** error: $prog is a directory" exit endif end else set pp = afni endif set get_package = $hostsite/pub/dist/bin/$package/$pp echo "++ downloading test file: $get_prog $package/$pp ..." $get_prog $get_package cmp -s $pp ../$pp if ( ! $status ) then echo "++ no update needed" # warn the user if the package is obsolete foreach oname ( $obsolete_list ) if ( "$package" == $oname ) then echo "" echo "** warning: package $package is no longer being updated" echo "" # special case suggestions if ( "$package" == "macosx_10.7_local" || \ "$package" == "macosx_10.7_Intel_64" ) then echo "-- consider using package: macos_10.12_local" echo "" endif break endif end cd .. \rm -fr $tmp_dir exit else if ( $#prog_list > 0 ) then echo "-- overwriting test update file, $pp" chmod a+x $pp else \rm $pp endif # if just testing, we are done if ( $testing ) then echo "++ install needed, but just testing download via '$get_prog', done" echo "(temp download in `pwd`)" exit endif endif # no local_package echo "" echo "++ update needed, installing..." echo "" sleep 1 # ---------------------------------------------------------------------- # an update is needed, download full package # download the full binary set or list of programs if ( $#prog_list == 0 ) then # if local, nothing to download if ( $local_package == "" ) then echo "++ downloading full package: $get_prog $package.tgz ..." set get_package = $hostsite/pub/dist/tgz/$package.tgz $get_prog $get_package if ( $status ) then echo "** failed to download package $get_package" exit 1 endif endif else # prog_list, get each file if ( $#prog_list > 1 ) echo "++ downloading remaining files ..." foreach pp ( $prog_list[2-] ) set prog = $pp:t set get_package = $hostsite/pub/dist/bin/$package/$prog $get_prog $get_package set ss = $status if ( $ss ) then echo "** failed to download package file:" echo " $get_package" exit 1 endif chmod a+x $prog end endif # if no prog_list, extract package if ( $#prog_list == 0 ) then if ( $local_package != "" ) then set pfile = $local_package_dir/$local_package echo "++ extracting local package $package from $pfile..." else set pfile = $package.tgz echo "++ extracting package $pfile..." endif tar xfz $pfile if ( $status ) then echo "** failed to extract package $pfile" exit 1 endif endif # ---------------------------------------------------------------------- # delete any previous auto-backup and install the new binaries # if not making a backup dir, use rsync for install # (since there might be new and unknown directories) set use_rsync = 1 # if the directory is empty, no rsync or backup set nfiles = `\ls .. | wc -l` # make a backup directory (first under 'hidden' temp dir) if ( $nfiles == 0 ) then set use_rsync = 0 # now do not need rsync echo "-- nothing to back up or sync" else if ( $make_backup ) then # create new auto-backup directory mkdir $backup_dir if ( $status ) then echo "** failed to make backup directory $backup_dir, exiting..." exit 1 endif echo "++ backing up current binaries to $backup_dir" # if prog_list, only backup those programs if ( $#prog_list ) then foreach pp ( $prog_list ) set prog = $pp:t if ( -f ../$prog ) \mv ../$prog $backup_dir end else # might nest backups here, check on remove \mv ../* $backup_dir endif # delete previous auto-backup directory if ( -d ../$backup_dir ) then echo deleting old backup directory, $backup_dir ... \rm -fr ../$backup_dir else if ( -d $backup_dir/$backup_dir ) then echo deleting previous backup directory, $backup_dir ... \rm -fr $backup_dir/$backup_dir endif \mv $backup_dir .. set use_rsync = 0 # now do not need rsync endif # abin may have sub-directories 17 Oct 2011 [rickr] # actually install the new binaries if ( $use_rsync ) then echo "++ synching new binaries..." # either sync package or files if ( $#prog_list > 0 ) then rsync -av * .. set ss = $status else rsync -a $package/ .. set ss = $status endif if ( $ss ) then echo "** failed to overwrite existing package, exiting..." exit endif else echo "++ installing new binaries..." if ( $#prog_list > 0 ) then \mv * .. set ss = $status else \mv $package/* .. set ss = $status endif if ( $ss ) then echo "** failed to overwrite existing package, exiting..." exit endif endif # if this is a new install and we are not root, update .cshrc set rcfile = ~/.cshrc if ( $do_dotfiles && -d $abin && $?USER ) then if ( $USER != root ) then if ( -f ~/.tcshrc ) then set rcfile = ~/.tcshrc else if ( -f ~/.cshrc ) then set rcfile = ~/.cshrc else set rcfile = ~/.cshrc echo ++ creating empty $rcfile touch $rcfile endif \grep $abin:t $rcfile >& /dev/null if ( $status ) then # finally, update .csrhc and our current path echo "++ adding $abin to path in $rcfile ..." # newline, in case they are missing one? echo '' >> $rcfile echo 'set path = ( $path ' $abin ' ) ' >> $rcfile set path = ( $path $abin ) endif # if cur_afni_does not point to abin, reset it if ( $cur_afni != $abin ) then set path = ( $abin $path ) rehash set cur_afni = `which afni` set cur_afni = $cur_afni:h endif # --------------------------- # do this for .bashrc, too... set brcfile = ~/.bashrc # to simplify, make sure the file exists if ( ! -f $brcfile ) touch $brcfile # and possibly edit \grep $abin:t $brcfile >& /dev/null if ( $status ) then # not found, so append to file echo "++ adding $abin to PATH in $brcfile ..." # add a newline, just in case echo '' >> $brcfile echo 'export PATH=$PATH:'$abin >> $brcfile endif # --------------------------- # and .bash_profile, but only if it exists set brcfile = ~/.bash_profile if ( -f $brcfile ) then \grep $abin:t $brcfile >& /dev/null if ( $status ) then # $abin not found, so append to file echo "++ adding $abin to PATH in $brcfile ..." echo 'export PATH=$PATH:'$abin >> $brcfile endif else if ( $sysname == Darwin ) then echo "++ will source .bashrc from newly created .bash_profile" echo '' >> $brcfile echo '. $HOME/.bashrc' > $brcfile endif # so... what about .profile? endif endif # and possibly run apsearch if ( $do_apsearch && $cur_afni == $abin && $#prog_list == 0 ) then rehash set cmd = "apsearch -update_all_afni_help" echo "++ running $cmd ..." $cmd \grep all_progs.COMP $rcfile >& /dev/null if ( $status && -f $rcfile ) then cat << EOF >> $rcfile if ( -f \$HOME/.afni/help/all_progs.COMP ) then source \$HOME/.afni/help/all_progs.COMP endif EOF endif endif # maybe they need to set the DYLD_F_L_P if ( $package == macosx_10.7_Intel_64 && $#prog_list > 0 ) then echo "" echo "-- remember to set the DYLD_FALLBACK_LIBRARY_PATH, e.g." echo " setenv DYLD_FALLBACK_LIBRARY_PATH $abin" echo "" endif # finally remove any leftovers cd .. \rm -fr $tmp_dir echo "done, yay (binaries are under $abin)" exit 0