#! /bin/sh #***************************************************************************** # # $Id: install_beam,v 1.12 2011/05/27 16:26:37 ftessier Exp $ # # Copyright Blake Walters and the National Research Council of Canada # # This script is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # #============================================================================= # Installs the BEAMnrc package and configures it for the same system- # compiler combination that you are running EGSnrc on. # # Do not redirect the output of this script as in past versions of the # BEAMnrc install scripts because these are interactive. # Log messages and information about the progress of the installation # is echoed to the files install_beam.status and install_beam.log in the # directory where you executed this script. # Please read these files carefully if the installation fails since most # errors/problems should be identified here. # # To execute this script, one needs to have the # distribution file: # # ${my_version}_BEAMnrc.tar[ | .Z | .gz | .bz2] # # #***************************************************************************** my_version=V4 file_list="BEAMnrc BEAMnrc_phsp BEAMnrc_CT" my_name=`echo "$0" |sed 's,.*[\\/],,'` #define the two log files for creating a record of the installation exec 3>install_beam.status exec 4>install_beam.log cat >&4 <<_ACEOF This file contains error messages and output from programs run during the installation process of BEAMnrc $my_version _ACEOF # echo stuff # shamelessly stolen from autoconf generated scripts. # case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in *c*,-n*) ECHO_N= ECHO_C=' ' ECHO_T=' ' ;; *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;; *) ECHO_N= ECHO_C='\c' ECHO_T= ;; esac cat <<_ACEOF ****************************************************************************** This script will install the BEAMnrc $my_version system. ******************************************************************************* hit return to continue. _ACEOF read response beamnrc_files= found_beamnrc=no while true; do echo $ECHO_N "Source directory: $ECHO_C" >&3 echo $ECHO_N "Input directory where you stored the BEAMnrc distribution files [./]: $ECHO_C" >&2 read response if test "x$response" = x; then srcdir="./" elif test "x$response" = xhelp; then cat >&2 <<_ACEOF To install the BEAMnrc system you must download the file ${my_version}_BEAMnrc.tar or compressed/zipped version ${my_version}_BEAMnrc.tar.Z or ${my_version}_BEAMnrc.tar.gz or ${my_version}_BEAMnrc.tar.bz2 from the BEAMnrc distribution site. You have to input here the directory where you have stored this file. If you just hit the enter key, this script will look in the current working directory for the files. _ACEOF continue else srcdir="$response" fi cur_dir=`pwd` cd $srcdir srcdir=`pwd` cd $cur_dir test_srcdir=`echo $srcdir | sed 's,.*[\\/],,'` if test "x$test_srcdir" != x; then srcdir="$srcdir/" fi echo $srcdir >&3 for file in $file_list; do the_file="$my_version"_"$file" the_full_file="$srcdir$the_file" for ext in .tar .tar.Z .tar.gz .tar.bz2; do echo $ECHO_N "Looking for $the_full_file$ext ... $ECHO_C" >&3 if test -f "$the_full_file$ext"; then echo "yes" >&3 beamnrc_files="$beamnrc_files $the_full_file$ext" if test "x$file" = xBEAMnrc; then found_beamnrc=yes fi break else echo "no" >&3 fi done done if test "x$beamnrc_files" = x; then echo "Did not find any distribution files in $srcdir !" >&3 echo "Did not find any distribution files in $srcdir !" >&2 echo >&2 elif test "x$found_beamnrc" = xno; then echo "Did not find" "$my_version""_BEAMnrc.tar[.Z | .gz | .bz2]" >&3 echo "Did not find" "$my_version""_BEAMnrc.tar[.Z | .gz | .bz2]" >&2 echo "This file is essential" >&2 echo >&2 else break fi done #find out if HEN_HOUSE, EGS_HOME and EGS_CONFIG have already been defined #AND exist. If not, the user must have not installed properly or installation #is incomplete egs_installed=yes if test ! -d "$HEN_HOUSE"; then echo "HEN_HOUSE is not defined." >&3 echo "HEN_HOUSE is not defined." >&2 egs_installed=no fi if test ! -d "$EGS_HOME"; then echo "EGS_HOME is not defined." >&3 echo "EGS_HOME is not defined." >&2 egs_installed=no fi if test ! -f "$EGS_CONFIG"; then echo "EGS_CONFIG is not defined." >&3 echo "EGS_CONFIG is not defined." >&2 egs_installed=no fi if test "x$egs_installed" = xno; then echo "BEAMnrc installation will quit because EGSnrcMP is not installed" >&3 echo "BEAMnrc installation will quit because EGSnrcMP is not installed" >&2 echo "properly. Check your EGSnrcMP installation and try again." >&3 echo "properly. Check your EGSnrcMP installation and try again." >&2 exit 1 fi # copy the distribution .tar file into $HEN_HOUSE if test "$srcdir" != "$HEN_HOUSE"; then for file in $beamnrc_files; do echo $ECHO_N "Copying $file to $HEN_HOUSE ... $ECHO_C" >&2 echo $ECHO_N "Copying $file to $HEN_HOUSE ... $ECHO_C" >&3 echo "********** Copy $file to HEN_HOUSE ********* " >&4 if { cp "$file" "$HEN_HOUSE" 2>&4; mystatus=$?; (exit $mystatus); }; then echo "OK" >&2 echo "OK" >&3 else echo "failed" >&2 echo "failed" >&3 echo "Failed program was 'cp $beamnrc_file $HEN_HOUSE'" >&4 exit 1 fi done fi if cd "$HEN_HOUSE"; then #echo >&2 echo >&3 #echo "Now in HEN_HOUSE directory " >&2 echo "Now in HEN_HOUSE directory " >&3 echo "*************** cd $HEN_HOUSE ******************" >&4 else echo "Failed to change directory to $HEN_HOUSE" >&2 echo "Failed to change directory to $HEN_HOUSE" >&3 echo "Failed program was 'cd $HEN_HOUSE'" >&4 exit 1 fi echo >&2 echo >&3 echo "OMEGA_HOME will be ${HEN_HOUSE}omega." >&3 echo "OMEGA_HOME will be ${HEN_HOUSE}omega." >&2 echo >&2 echo >&3 for file in $beamnrc_files; do testfile=`echo "$file" | sed 's,.*[\\/],,'` case $file in *.Z) prog_message="Uncompressing" prog="uncompress" tarfile=`echo "$testfile" | sed 's/.Z//'` thefile=$tarfile.Z ;; *.gz) prog_message="Unzipping" prog="gunzip" tarfile=`echo "$testfile" | sed 's/.gz//'` thefile=$tarfile.gz ;; *.bz2) prog_message="b-Unzipping" prog="bunzip2" tarfile=`echo "$testfile" | sed 's/.bz2//'` thefile=$tarfile.bz2 ;; *) tarfile="$testfile"; prog= ;; esac if test "x$prog" != x; then echo $ECHO_N "$prog_message $thefile ... $ECHO_C" >&3 echo $ECHO_N "$prog_message $thefile ... $ECHO_C" >&2 echo "********** $prog_message $thefile ***********" >&4 if { $prog $thefile >&4 2>&4; mystatus=$?; echo "status: $mystatus" >&4; (exit $mystatus); }; then echo "OK" >&3 echo "OK" >&2 else echo "failed" >&3 echo "failed" >&2 echo "Failed program was \'$prog $thefile\'" >&4 cat >&2 <<_ACEOF You have to install the $prog utility first. Alternatively, you can download uncompressed .tar files from the EGSnrc home page. _ACEOF exit 1 fi #echo >&2 echo >&3 fi echo $ECHO_N "Untarring file $tarfile ... $ECHO_C" >&2 echo $ECHO_N "Untarring file $tarfile ... $ECHO_C" >&3 echo "********** Untar $tarfile **************" >&4 if { tar -xvf $tarfile >&4 2>&4; mystatus=$?; (exit $mystatus); }; then echo "OK" >&2 echo "OK" >&3 else echo "failed" >&2 echo "failed" >&3 echo "Failed program was 'tar -xvf $tarfile'" exit 1 fi rm -f $tarfile done # OK, the tar file is now unpacked in HEN_HOUSE, # OMEGA_HOME="`pwd`/omega" export OMEGA_HOME # Check which make utility to use with this config # make_prog=`cat $EGS_CONFIG | grep "make_prog = " | sed "s/make_prog = //g"` if test "x$make_prog" = x; then echo "make_prog is not set in your config file? " >&2 echo "make_prog is not set in your config file? " >&3 echo "will try to use make " >&2 echo "will try to use make " >&3 make_prog=make fi # keep track of failed operations install_complete=yes # compile the beam_build tool if cd "$OMEGA_HOME/beamnrc/tools"; then #echo >&2 echo >&3 #echo "Now in OMEGA_HOME/beamnrc/tools directory " >&2 echo "Now in OMEGA_HOME/beamnrc/tools directory " >&3 echo "*************** cd $OMEGA_HOME/beamnrc/tools ******************" >&4 echo $ECHO_N "Compiling beam_build ... $ECHO_C" >&2 echo $ECHO_N "Compiling beam_build ... $ECHO_C" >&3 echo "********** Compiling beam_build **************" >&4 if { $make_prog >&4 2>&4; mystatus=$?; (exit $mystatus); }; then echo "OK" >&2; echo "OK" >&3 else echo "Failed compiling beam_build" >&2 echo "Failed compiling beam_build" >&3 install_complete=no fi else echo "Failed to change directory to $OMEGA_HOME/beamnrc/tools" >&2 echo "Failed to change directory to $OMEGA_HOME/beamnrc/tools" >&3 echo "Failed program was 'cd $OMEGA_HOME/beamnrc/tools'" >&4 install_complete=no fi # Now see if there is a C compiler with this config # and create read_write_pardose.o and load_vculib if yes. # my_machine=`cat $EGS_CONFIG | grep "my_machine = " | sed "s/my_machine = //g"` echo " my_machine = $my_machine" >&4 pardose_object= vculib_object= CC=`cat $EGS_CONFIG | grep "CC = " | sed "s/CC = //g"` echo $ECHO_N "Checking for a C compiler ... $ECHO_C" >&2 echo $ECHO_N "Checking for a C compiler ... $ECHO_C" >&3 echo "********** Checking for a C compiler **********" >&4 if test "x$CC" = x; then have_c_compiler=no echo "no" >&2; echo "no" >&3 else echo "$CC" >&2; echo "$CC" >&3 echo "********** C compiler options: " >&4 echo " CC = $CC" >&4 have_c_compiler=yes C_FLAGS=`cat $EGS_CONFIG | grep "C_FLAGS = " | grep -v "FCFLAGS" | sed "s/C_FLAGS = //g"` echo " C_FLAGS = $C_FLAGS" >&4 COUT=`cat $EGS_CONFIG | grep "COUT = " | sed "s/COUT = //g"` echo " COUT = $COUT" >&4 if cd "${HEN_HOUSE}lib/$my_machine"; then echo $ECHO_N "Compiling read_write_pardose ... $ECHO_C" >&2 echo $ECHO_N "Compiling read_write_pardose ... $ECHO_C" >&3 echo "********** Compiling read_write_pardose **********" >&4 testc_compile='$CC $C_FLAGS -c -I. ${COUT}read_write_pardose.o ../../user_codes/dosxyznrc/read_write_pardose.c >&4' if { (eval $testc_compile) 2>&4; test_status=$?; (exit $test_status); }; then echo "OK" >&2; echo "OK" >&3 pardose_object='$(EGS_LIBDIR)read_write_pardose.o' else echo "Failed" >&2; echo "Failed" >&3 fi echo $ECHO_N "Compiling load_vculib ... $ECHO_C" >&2 echo $ECHO_N "Compiling load_vculib ... $ECHO_C" >&3 echo "********** Compiling load_vculib **********" >&4 testc_compile='$CC $C_FLAGS -c -I. ${COUT}load_vculib.o ../../cutils/load_vculib.c >&4' if { (eval $testc_compile) 2>&4; test_status=$?; (exit $test_status); }; then echo "OK" >&2; echo "OK" >&3 vculib_object='$(EGS_LIBDIR)load_vculib.o' else echo "Failed" >&2; echo "Failed" >&3 fi fi fi # Now create dosxyznrc.spec # echo $ECHO_N "Creating dosxyznrc_${my_machine}.spec ... $ECHO_C" >&2 echo $ECHO_N "Creating dosxyznrc_${my_machine}.spec ... $ECHO_C" >&3 cat >${HEN_HOUSE}specs/dosxyznrc_${my_machine}.spec <<_ACEOF # This file specifies additional object files needed in the link # step of DOSXYZnrc. # PARDOSE_OBJECTS = $pardose_object VCULIB_OBJECTS = $vculib_object _ACEOF echo "OK" >&2; echo "OK" >&3 #compile the rest of the codes in progs for prog in beamdp ctcreate statdose readphsp dosxyz_show addphsp; do if test $prog = dosxyz_show && test $have_c_compiler = no; then echo "Skipping dosxyz_show compilation (no C compiler)" >&2 echo "Skipping dosxyz_show compilation (no C compiler)" >&3 echo "Skipping dosxyz_show compilation (no C compiler)" >&4 else if cd "$OMEGA_HOME/progs/$prog"; then #echo >&2 echo >&3 #echo "Now in OMEGA_HOME/progs/$prog directory " >&2 echo "Now in OMEGA_HOME/progs/$prog directory " >&3 echo "*** cd $OMEGA_HOME/progs/$prog ***" >&4 echo $ECHO_N "Compiling $prog ... $ECHO_C" >&2 echo $ECHO_N "Compiling $prog ... $ECHO_C" >&3 echo "********** Compiling $prog ***********" >&4 if { $make_prog >&4 2>&4; mystatus=$?; (exit $mystatus); }; then echo "OK" >&2; echo "OK" >&3 else echo "Failed compiling $prog" >&2 echo "Failed compiling $prog" >&3 install_complete=no fi else echo "Failed to change directory to $OMEGA_HOME/progs/$prog" >&2 echo "Failed to change directory to $OMEGA_HOME/progs/$prog" >&3 echo "Failed program was 'cd $OMEGA_HOME/progs/$prog'" >&4 install_complete=no fi fi done if test "x$install_complete" = xno; then cat >&2 <<_ACEOF ****************************************************************************** WARNING: Some parts of the OMEGA/BEAM installation failed. Look in the install.status file to see what these were. Once you have found and fixed the problem, either run the failed commands individually or re-run this installation script. It is recommended that you fix these problems before finalizing the OMEGA/BEAM installation for individual users. ****************************************************************************** _ACEOF cat >&3 <<_ACEOF ****************************************************************************** WARNING: Some parts of the OMEGA/BEAM installation failed. Look in the install.status file to see what these were. Once you have found and fixed the problem, either run the failed commands individually or re-run this installation script. It is recommended that you fix these problems before finalizing the OMEGA/BEAM installation for individual users. ****************************************************************************** _ACEOF fi cat >&2 <<_ACEOF ****************************************************************************** The OMEGA/BEAM basic installation is finished. Every user who wants to use the system must now run the script ${HEN_HOUSE}scripts/finalize_beam_foruser This will copy example .module files into the user's EGS_HOME/beamnrc/spec_modules directory and compile DOSXYZnrc on the user's area. ****************************************************************************** _ACEOF cat >&3 <<_ACEOF ****************************************************************************** The OMEGA/BEAM basic installation is finished. Every user who wants to use the system must now run the script ${HEN_HOUSE}scripts/finalize_beam_foruser This will copy example .module files into the user's EGS_HOME/beamnrc/spec_modules directory and compile DOSXYZnrc on the user's area. ****************************************************************************** _ACEOF if test "x$USER" = xroot; then exit 0 fi cat >&2 <<_ACEOF You are logged in as user $USER. Do you want this script to finalize the OMEGA/BEAM installation for you by running ${HEN_HOUSE}scripts/finalize_beam_foruser _ACEOF echo $ECHO_N "script ? (yes/no): $ECHO_C" >&2 read response if test "x$response" = xhelp; then cat >&2 <<_ACEOF If you are on a single user system, the answer is yes. On a multi-user system, if you are going to run OMEGA/BEAM from this account, answer yes, but if this is to be the repository of the system, answer no. Do you want this script to finalize the OMEGA/BEAM installation for you by running ${HEN_HOUSE}scripts/finalize_beam_foruser _ACEOF echo $ECHO_N "script ? (yes/no): $ECHO_C" >&2 read response fi if test "x$response" = xyes; then if cd "$HEN_HOUSE/scripts"; then echo >&3 echo "Now in HEN_HOUSE/scripts directory " >&3 echo "*** cd ${HEN_HOUSE}scripts ***" >&4 ./finalize_beam_foruser else echo "Failed to change directory to ${HEN_HOUSE}scripts" >&3 echo "Failed program was 'cd ${HEN_HOUSE}scripts'" >&4 fi fi echo "Now back in script install_beam" exit 0