#!/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 distdir = pub/dist 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 update .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 3.8 15 Mar 2019 : comment that dotfile updates were done by @uab 3.9 14 Jun 2019 : add -hostname and -distdir 3.10 26 Jul 2019 : add -make_backup and -echo 3.11 6 Sep 2019 : if afni -ver fails, fall back to AFNI_version.txt 3.12 13 Sep 2019 : set DYLD_LIBRARY_PATH on mac 3.13 24 Sep 2019 : missed endif, extra ] 3.14 29 Apr 2020 : default recur from pub/dist/bin/misc - terminate on failed test download 3.15 4 May 2020 : fixed download of test file 3.16 16 Sep 2020 : populate .zshrc like .bashrc, and with autoload commands 3.17 21 Oct 2021 : allow for previously set DYLD_LIBRARY_PATH in tcsh 3.18 10 Jan 2022 : if no .tcshrc, create one to source .cshrc 3.19 11 Jan 2022 : if not found, init .afnirc/.sumarc 3.20 3 May 2022 : for anyos packages, test update with AFNI_version.txt 3.21 22 Jul 2022 : add linux_fedora_28_shared to obsolete_list 3.22 5 May 2023 : fix setting cur_afni 3.23 27 Nov 2023 : add some comments about build_afni.py 3.24 7 Dec 2023 : add -overwrite_build (required for that operation) ------------------------------------------------------------------------------- EOF exit POST_HIST: # end history section # ---------------------------------------------------------------------- set aub_version = "3.24, December 7, 2023" # 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 \ linux_fedora_28_shared \ 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 # ---------------------------------------------------------------------- # option-controlled variables (initialize to 'unset') set abin = "" set flatdir = /opt/X11/lib/flat_namespace set package = "" set local_package = "" # existing .tgz package to use (no download) set overwrite_build = 0 # do we allow overwriting build_afni.py set prog_list = () # update programs or entire package set tmp_dir = ".tmp.install" # should start with '.' 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 ) if ( $#argv == 0 ) then set help = 1 else set help = 0 endif # ---------------------------------------------------------------------- # other option-controlled variables set cert_verify = 1 # whether to verify CA certificate via SSL/TLS set do_apsearch = 0 # run apserach -update_all_afni_help set do_dotfiles = 0 # if needed, initialize dotfiles set do_extras = 0 # possibly include apearch and dotfiles set do_recur = 1 # download a new version of @uab, first set make_backup = 0 # backup previous binaries set quick = 0 # no fancies (recur, apsearch) set revert = 0 # revert binaries to those in backup directory set testing = 0 set test_protos = 0 # test download protocols set show_system_progs = 0 # as it says set show_obsoletes = 0 # as it says set show_obsoletes_grep = 0 # include greppable text set use_curl = 0 # use curl or wget # ---------------------------------------------------------------------- # other non-option globals (non-locally used) variables # # backup_dir # directory to run backup under # build_label # AFNI_WHOMADEIT: line 4 of AFNI_version.txt # cur_afni # path to current set of binaries # date # the current date 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 set make_backup = 1 else if ( "$argv[$ac]" == "-distdir" ) then @ ac ++ if ( $ac > $#argv ) then echo "** missing parameter for option '-distdir'" exit 1 endif set distdir = $argv[$ac] 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 set make_backup = 1 else if ( "$argv[$ac]" == "-echo" ) then set echo 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]" == "-hostname" ) then @ ac ++ if ( $ac > $#argv ) then echo "** missing parameter for option '-hostname'" exit 1 endif set hostname = $argv[$ac] 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]" == "-make_backup" ) then @ ac ++ if ( $ac > $#argv ) then echo "** missing parameter for option '-make_backup'" exit 1 endif set resp = `echo $argv[$ac] | cut -b1` if ( $resp == 'N' || $resp == 'n' ) then set make_backup = 0 else set make_backup = 1 endif else if ( "$argv[$ac]" == "-overwrite_build" ) then set overwrite_build = 1 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 ~1~ Install or update the AFNI binaries, either via '-defaults' or by the '-bindir' and/or '-package' options. Note: one can use build_afni.py to compile locally examples: individual user: initial install or update The default package is linux_openmp_64 (Linux) or macos_10.12_local (OS X). The default binary directory is ~/abin. @update.afni.binaries -defaults root user: initial install or update @update.afni.binaries -package linux_openmp_64 \\ -bindir /usr/local/AFNIbin @update.afni.binaries -local_package linux_openmp_64.tgz \\ -bindir /usr/local/AFNIbin other examples: @update.afni.binaries -defaults @update.afni.binaries -defaults -package macos_10.12_local @update.afni.binaries -package linux_openmp_64 @update.afni.binaries -package linux_openmp_64 -bindir ~/abin @update.afni.binaries -package linux_openmp_64 -programs suma 3dRSFC @update.afni.binaries -package linux_openmp_64 \\ -programs file_tool python_scripts/*.py @update.afni.binaries -show_obsoletes @update.afni.binaries -local_package macos_10.12_local.tgz examples to install packages without compiled binaries: @update.afni.binaries -no_recur -package anyos_text -bindir anyos_text @update.afni.binaries -no_recur -package anyos_text_atlas \\ -bindir anyos_text_atlas ------------------------------------------------------------ options: ~1~ -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, -apsearch yes, and -make_backup 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 or .zshrc do not have the AFNI binary directory in the file (grep), add a line to update the PATH in each file. All files are updated (if need be). Also, if on a mac, set DYLD_LIBRARY_PATH in similar files. Also, init .afnirc and .sumarc if they do not yet exist. * 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 -make_backup yes This has come full-circle to be the same as -defaults. -echo : turn on shell command echo This will be like running the script with "tcsh -x". -make_backup yes/no : make a backup of binaries before replacing default: no (but it is 'yes' with -do_extras or -defaults) Specify whether to make a backup of the current binaries. Since the default is currently yes, the likely use would be 'no'. -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 # if cur_afni, note the build label: NONE, official, build, ... # (see AFNI_WHOMADEIT) set build_label = NONE set vfile = $cur_afni/AFNI_version.txt if ( $cur_afni != "" && -f $vfile ) then set blab = `awk '{ if(NR == 4) print $1 }' $vfile` set rv = $status if ( ! $rv && blab != "" ) then set build_label = $blab echo "-- have current build label $build_label" endif endif # warn if the current package was made by build_afni.py if ( $build_label == build ) then if ( $overwrite_build ) then echo "-- will overwrite local build_afni.py package at user's request" else echo "" echo "** error: the current package was made by build_afni.py" echo "" echo " refusing to overwrite it without -overwrite_build" echo "" echo " note: the typical update method in this case would be:" echo "" echo " build_afni.py -build_root ~/afni_build" echo "" exit 1 endif 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 set vfile = AFNI_version.txt echo "** failed setting package from 'afni -ver'" echo " checking $vfile instead..." set package = `column_cat -line 2 $cur_afni/$vfile` if ( $status || ! -f $vfile || "$package" == "" ) then echo "** failed setting package from '$vfile', failing" exit 1 endif 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 ) then set get_prog = ( curl -O -f ) endif # do we verify certificates via CA list? if not, specify 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 ) then set package = $package:r endif # 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 # Try pub/dist/bin/misc first, then go after the package version 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/$distdir/bin set get_package = $bin_root/misc/$prog echo "++ getting install prog: $get_prog bin/misc/$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 = $package 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. Was: # 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/$distdir/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 requested 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 if ( $package =~ anyos* ) then set pp = AFNI_version.txt else set pp = afni endif set get_package = $hostsite/$distdir/bin/$package/$pp echo "++ downloading test file: $get_prog $package/$pp ..." $get_prog $get_package # if downloading fails, ... if ( $status ) then echo "** failed to download test file" echo " (maybe package $package is not available)" # provide extra comment(s) based on the build label if ( $build_label == "official" ) then echo " (but package is official, how strange...)" # warn if user should probably be using build_afni.py else if ( $build_label == "build" ) then echo "" if ( -d ~/afni_build ) then echo "note: current package was built by build_afni.py, consider:" echo "" echo ' build_afni.py -build_root ~/afni_build' else echo "note: current package was built by build_afni.py, but it is" echo " not clear what -build_root should be, consider:" echo "" echo ' build_afni.py -build_root SOME_DIRECTORY' endif else echo " (package is not official, so it is either old" \ "or from an unknown source)" endif echo "" exit 1 endif 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/$distdir/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/$distdir/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 "++ syncing 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 no .tcshrc, make one set make_tcshrc = 0 # if .tcshrc, use it, else .cshrc if ( -f ~/.tcshrc ) then set rcfile = ~/.tcshrc else if ( -f ~/.cshrc ) then set rcfile = ~/.cshrc set make_tcshrc = 1 else set rcfile = ~/.cshrc echo ++ creating empty $rcfile touch $rcfile set make_tcshrc = 1 endif # if no .tcshrc, make a .tcshrc file to source .cshrc if ( $make_tcshrc ) then set rctmp = ~/.tcshrc echo "++ will source .cshrc from newly created $rctmp" echo '' > $rctmp echo '# auto-inserted by @update.afni.binaries :' >> $rctmp echo 'source $HOME/.cshrc' >> $rctmp endif # tcsh: set path \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 '# auto-inserted by @update.afni.binaries :' >> $rcfile echo 'set path = ( $path ' $abin ' ) ' >> $rcfile set path = ( $path $abin ) rehash endif # tcsh: set DYLD_LIBRARY_PATH on macs if ( $sysname == Darwin ) then \grep $flatdir $rcfile >& /dev/null if ( $status ) then # finally, update .csrhc and our current path echo "++ setting DYLD_LIBRARY_PATH in $rcfile ..." # newline, in case they are missing one? echo '' >> $rcfile echo '# auto-inserted by @update.afni.binaries :' >> $rcfile echo 'if ( $?DYLD_LIBRARY_PATH ) then' >> $rcfile echo ' setenv DYLD_LIBRARY_PATH ${DYLD_LIBRARY_PATH}:'"$flatdir" \ >> $rcfile echo 'else' >> $rcfile echo ' setenv DYLD_LIBRARY_PATH' "$flatdir" >> $rcfile echo 'endif' >> $rcfile endif 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` if ( ! $status ) then set cur_afni = $cur_afni:h else # no afni found set cur_afni = "" endif endif # --------------------------- # do this for .bashrc and .zshrc, too... # (be lazy and just populate) foreach brcfile ( ~/.bashrc ~/.zshrc ) # 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 '# auto-inserted by @update.afni.binaries :' >> $brcfile echo 'export PATH=$PATH:'$abin >> $brcfile endif # bash: set DYLD_LIBRARY_PATH on macs (.bashrc) if ( $sysname == Darwin ) then \grep $flatdir $brcfile >& /dev/null if ( $status ) then # finally, update .csrhc and our current path echo "++ setting DYLD_LIBRARY_PATH in $brcfile ..." # newline, in case they are missing one? echo '' >> $brcfile echo '# auto-inserted by @update.afni.binaries :' >> $brcfile echo 'export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:'$flatdir \ >> $brcfile endif endif end # .bashrc/.zshrc loop # --------------------------- # and .bash_profile, but only if it exists (unless on a mac, sigh) # (same for .profile, since many now use sh) foreach brcfile ( ~/.bash_profile ~/.profile ) # if might already be sourcing .bashrc, skip if ( -f $brcfile ) then \grep '\.bashrc' $brcfile >& /dev/null if ( ! $status ) then echo "-- seem be be sourcing .bashrc from $brcfile" continue endif endif if ( -f $brcfile ) then # do we need abin in PATH? \grep $abin:t $brcfile >& /dev/null set bstatus = $status if ( $bstatus ) then echo "++ adding $abin to PATH in $brcfile ..." endif # do we need flat_namespace in DYLD_LIBRARY_PATH? set fstatus = 0 if ( $sysname == Darwin ) then \grep $flatdir $brcfile >& /dev/null set fstatus = $status if ( $fstatus ) then echo "++ setting DYLD_LIBRARY_PATH in $brcfile ..." endif endif # in either case, add header if ( $bstatus || $fstatus ) then echo '' >> $brcfile echo '# auto-inserted by @update.afni.binaries :' >> $brcfile endif # then add path and/or flat if ( $bstatus ) then echo 'export PATH=$PATH:'$abin >> $brcfile endif if ( $fstatus ) then echo 'export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:'$flatdir \ >> $brcfile endif else if ( $sysname == Darwin ) then echo "++ will source .bashrc from newly created $brcfile" echo '' > $brcfile echo '# auto-inserted by @update.afni.binaries :' >> $brcfile echo '. $HOME/.bashrc' >> $brcfile endif end # if .afnirc or .sumarc are not present, initialize them set rcfile = ~/.afnirc if ( ! -f $rcfile ) then echo "++ initializing .afnirc from AFNI.afnirc" \cp $abin/AFNI.afnirc $rcfile endif set rcfile = ~/.sumarc if ( ! -f $rcfile ) then echo "++ initializing .sumarc via 'suma -update_env'" $abin/suma -update_env endif endif endif # and possibly run apsearch if ( $do_apsearch && $cur_afni == $abin && $#prog_list == 0 ) then # update dotfiles *before* running apsearch, so apsearch/@clean_help_dir # do not suggest the user do it, too 3 Mar 2021 [rickr] \grep all_progs.COMP $rcfile >& /dev/null if ( $status && -f $rcfile ) then echo "++ adding source of all_progs.COMP to $rcfile" cat << EOF >> $rcfile # auto-inserted by @update.afni.binaries : # set up tab completion for AFNI programs if ( -f \$HOME/.afni/help/all_progs.COMP ) then source \$HOME/.afni/help/all_progs.COMP endif EOF endif set brcfile = ~/.bashrc \grep all_progs.COMP.bash $brcfile >& /dev/null set pstatus = $status if ( -f $brcfile && $pstatus ) then echo "++ adding source of all_progs.COMP.bash to $brcfile" cat << EOF >> $brcfile # auto-inserted by @update.afni.binaries : # set up tab completion for AFNI programs if [ -f \$HOME/.afni/help/all_progs.COMP.bash ] then source \$HOME/.afni/help/all_progs.COMP.bash fi EOF endif set brcfile = ~/.bash_profile \grep all_progs.COMP.bash $brcfile >& /dev/null set pstatus = $status \grep '\.bashrc' $brcfile >& /dev/null set bstatus = $status if ( -f $brcfile && $pstatus && $bstatus ) then echo "++ adding source of all_progs.COMP.bash to $brcfile" cat << EOF >> $brcfile # auto-inserted by @update.afni.binaries : # set up tab completion for AFNI programs if [ -f \$HOME/.afni/help/all_progs.COMP.bash ] then source \$HOME/.afni/help/all_progs.COMP.bash fi EOF endif # updates for zsh set brcfile = ~/.zshrc \grep all_progs.COMP.zsh $brcfile >& /dev/null set pstatus = $status if ( -f $brcfile && $pstatus ) then echo "++ adding source of all_progs.COMP.zsh to $brcfile" cat << EOF >> $brcfile # auto-inserted by @update.afni.binaries : # set up tab completion for AFNI programs if [ -f \$HOME/.afni/help/all_progs.COMP.zsh ] then autoload -U +X bashcompinit && bashcompinit autoload -U +X compinit && compinit \\ && source \$HOME/.afni/help/all_progs.COMP.zsh fi EOF endif # zsh: warn user if all_progs.COMP.bash is sourced \grep all_progs.COMP.bash $brcfile >& /dev/null if ( ! $status ) then echo "" echo "**************************************************************" echo "** warning: all_progs.COMP.bash is sourced from $brcfile," echo "** please remove bash version" echo "**" echo "** -> so keep all_progs.COMP.zsh, but not all_progs.COMP.bash" echo "**************************************************************" echo "" endif # dot files are good, now run apsearch rehash set cmd = "apsearch -update_all_afni_help" echo "++ running $cmd ..." $cmd # end for running apsearch 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