#!/bin/bash # This script should clean up any 'build_all' generated files, # either a simple build (with corsika-*, sim_telarray, and hessioxxx # directly under this directory) or a multiple build ('prod3-all' or # 'prod3-la-palma'). # What is typically left are the original tar files (unless they are # symlinks), produced data files, and any modified files (which may # include a few files missed by 'make clean' etc.). if [ "$1" = "--help" -o "$1" = "" ]; then echo "Clean up the 'build_all' generated files under the given" echo "(build_all top-level) directories (that is where you find the" echo "original tar packages used by build_all)." echo "Syntax: $0 . [ or other directories ]" exit fi bdir="$(/bin/pwd)" for f in "$@"; do cd "${bdir}" cd "${f}" && echo "Now cleaning up in $f" || exit 1 if [ ! -f hessioxxx.tar.gz ]; then exit 1; fi if [ ! -f sim_telarray.tar.gz ]; then exit 1; fi if [ -d std ]; then for d in demo/ lp-all/ lp-sct/ lp-std/ max/ mrg/ sct/ std/ pa-baseline lp-baseline mini3; do if [ -d $d ]; then echo "Cleaning files built in ${bdir}/${f}/${d}/" (cd $d for f in $(find . -maxdepth 1 -name 'corsika-[67]*[0-9]'); do if [ -d "$f" ]; then (cd $f && make clean && make distclean) (cd $f && /bin/rm -f lib/*/lib*.a) (cd $f && /bin/rm -f run/corsika[67]* run/corsikaread* run/plottracks) (cd $f && /bin/rm -f src/corsikacompilefile.f) # Not removing patched corsika.F; could have been modified. fi done if [ -d sim_telarray ]; then (cd sim_telarray && make clean && make distclean) (cd sim_telarray && /bin/rm -f telarray_rand.conf.used* ) fi if [ -d hessioxxx ]; then (cd hessioxxx && make clean) (cd hessioxxx && /bin/rm -f Makefile.depend) fi if [ -d iactio ]; then (cd iactio && make clean && make distclean) fi if [ -d stdtools ]; then (cd stdtools && make clean && make distclean) fi ) fi done else echo "Cleaning files generated by build_all." for f in $(find . -maxdepth 1 -name 'corsika-[67]*[0-9]' -type d); do if [ -d "$f" ]; then (cd $f && make clean && make distclean) (cd $f && /bin/rm -f lib/*/lib*.a) (cd $f && /bin/rm -f run/corsika[67]* run/corsikaread* run/plottracks) (cd $f && /bin/rm -f src/corsikacompilefile.f) # Not removing patched corsika.F; could have been modified. # The huge qgsdat cross section files are never modified and can go. (cd $f && /bin/rm -f run/qgsdat-II-0[34]) fi done if [ -d sim_telarray ]; then (cd sim_telarray && make clean && make distclean) fi if [ -d hessioxxx ]; then (cd hessioxxx && make clean && make distclean) (cd hessioxxx && /bin/rm -f Makefile.depend) fi if [ -d iactio ]; then (cd iactio && make clean && make distclean) fi if [ -d stdtools ]; then (cd stdtools && make clean && make distclean) fi fi if [ "$(which md5deep 2>/dev/null)" = "" ]; then find . -name Data -type l -ls >> .data-links echo "Remove all symbolic links." find . -type l -delete echo "No md5deep checksum program found. Giving up now." exit 1 fi mkdir .clean-tmp echo "Extracting tar packages for relevant file check sums." cd .clean-tmp || exit 1 for t in ../*.tar.gz; do echo " Extract tar package $t" tar zxf "${t}" done tgzlist="$(find . -name '*.tar.gz')" if [ ! -z "${tgzlist}" ]; then for t in ${tgzlist}; do echo " Also extract $t" td="$(dirname $t)" tb="$(basename $t)" (cd ${td} && tar zxf ${tb}) done fi # No point in calculating checksum for that file: /bin/rm -f corsika-*/run/qgsdat-II-0[34] cd .. find . -name Data -type l -ls >> .data-links echo "Remove all symbolic links." find . -type l -delete echo "Evaluating check sums of all files in tar packages." find .clean-tmp -type l -delete md5deep -r .clean-tmp > .clean-hash || exit 1 echo "Removing temporary files extracted from tar packages." rm -rf .clean-tmp echo "Which files have check sums identical to files in tar packages?" md5deep -r -m .clean-hash -o f . > .clean-same echo "And which have check sums not found in the tar packages?" md5deep -r -x .clean-hash -o f . > .clean-keep # set -x if [ -f .clean-same ]; then n="$(cat .clean-same | egrep -v '\.(patch|[Bb][AaCc][Kk]|~)$' | wc -l)" m="$(cat .clean-same | wc -l)" echo "Delete (almost) all files ($n of $m) with check sums identical in tar packages." if [ "$n" != "0" ]; then /bin/rm -f `cat .clean-same | egrep -v '\.(patch|[Bb][AaCc][Kk]|~)$'` # 2>/dev/null fi fi if [ -f .clean-same ]; then n="$(cat .clean-same | egrep '/bernlohr/.*\.patch' | wc -l)" if [ "$n" != "0" ]; then echo "Delete $n included CORSIKA patches." /bin/rm -f `cat .clean-same | egrep '/bernlohr/.*\.patch'` # 2>/dev/null fi fi echo "Remove empty directories" find . -type d -empty -delete # echo "Really remove also tar packages? There is no way back!" # /bin/rm *.tar.gz for c in `find . -maxdepth 1 -name 'corsika-[67]*[0-9].tar.gz' -o -name 'corsika-[67]*[0-9]-nqd.tar.gz' -o -name 'qgsdat-II-0[34]'`; do if [ -f ${c} -a -r ../${c} ]; then if cmp ${c} ../${c} 2>&1 >/dev/null; then /bin/rm ${c} && ln -s ../${c} echo "Replaced ${c} with symlink to ../${c}" fi fi done nd="$(find . -type d | wc -l)" nf="$(find . -type f | wc -l)" sp="$(du -s -h . | sed 's/[ \t].*//' | sed 's/\([kMG]\)/ \1/')" sd="$(du -s -h Data 2>/dev/null | sed 's/[ \t].*//' | sed 's/\([kMG]\)/ \1/')" if [ -z "$sd" ]; then echo "Left with $nf files in $nd directories (taking up a total of ${sp}iB; no Data)." else echo "Left with $nf files in $nd directories (taking up a total of ${sp}iB; ${sd}iB in Data)." fi done cd "${bdir}"