#!/bin/tcsh # .cp.files # # copy afni data from /mnt/cdrom # # usage: tcsh cp.files source_dir dest_dir # e.g. : tcsh /mnt/cdrom/cp.files /mnt/cdrom ~ # ------------------------------------------------------------ set get_dotfiles = 1 # default to not copying them if ( $#argv < 2 ) then echo usage : "$0 source_dir dest_dir" echo example : $0 /mnt/cdrom '~' exit endif set uber_dirs = ( group_results subject_results tool_results ) # make a list of directories to nuke set nukedirs = ( AFNI_data{1,2,4,5} suma_demo std_meshes \ AFNI.ad2 MEMRI_data connectAna svm_example{1,2} \ $uber_dirs \ ) # set nukedirs = ( $nukedirs freesurfer abin.prev linux_gcc32 ) # check source dir set sourced = $argv[1] if ( ! -d $sourced ) then echo "error: source directory does not exist: $sourced" exit endif # reassign using full path cd $sourced set sourced = `pwd` cd - # check dest dir set destd = $argv[2] if ( ! -d $destd ) then echo "error: destination directory does not exist: $destd" exit else if ( ! -w $destd ) then echo "error: destination directory is not writable: $destd" exit endif # reassign using full path cd $destd set destd = `pwd` cd - # work from destination so we don't have to copy tgz files cd $destd # now, nuke em from orbit; it's the only way to be sure foreach dir ( $nukedirs ) if ( -d $dir ) then echo "-- nuking directory, $dir..." \rm -fr $dir endif end set perm_dlist = () foreach file ( $sourced/*.tgz ) # set name = `tar tfz $file | head -1 | sed 's/\///g'` set name = $file:t:r # can now rely on dir name = tgz name echo -n "getting $name ... " # add to perm_dlist set perm_dlist = ( $perm_dlist $name ) # remove anything already here if ( -d $name ) then echo -n "removing old" \rm -fr $name echo -n " ... " endif # unpack the archive tar xfz $file # if new binaries, try to put into abin if ( $name == linux_gcc32 ) then if ( -d abin ) then echo moving binaries to $destd/abin cd $name \mv * $destd/abin cd $destd \rmdir $name else echo renaming $name to abin mv $name abin endif endif echo done end # get the dot files (cd to src, get them, cd back) if ( $get_dotfiles && -d $sourced/dotfiles ) then cd $sourced/dotfiles set dfiles = ( .??* ) echo getting dotfiles: $dfiles foreach file ( $dfiles ) # if one exists but differs, make a backup and then copy if ( -f $destd/$file ) then cmp -s $file $destd/$file if ( $status ) then \mv -v $destd/$file $destd/bak$file \cp -v $file $destd endif else \cp -v $file $destd endif end cd $destd endif echo setting write permissions... cd $destd chmod -R +w $perm_dlist