#!/bin/bash # Script for easy testing of different version of CCP4. # Runs as a subshell with sourced ccp4.setup. die() { echo $1 >&2; exit 1; } if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then echo "This script is to be run in subshell, not sourced." return fi this_file="$0" while [ -h "$this_file" ]; do this_dir="$( cd -P "$( dirname "$this_file" )" && pwd )" this_file="$(readlink "$this_file")" [[ $this_file != /* ]] && this_file="$this_dir/$this_file" done cdir=$(cd "$(dirname "$this_file")" 2>/dev/null; pwd) short_name="`basename "$cdir" | sed -e s/ccp4-//`" tmp_file=`mktemp /tmp/ccp4_start.XXXXXX` || tmp_file=/tmp/ccp4_start.$$ trap "rm -f $tmp_file" EXIT [ -e "$cdir/include/ccp4.setup-sh.in" ] || die "Error. Incomplete installation?" if [ ! -e "$cdir/bin/ccp4.setup-sh" ]; then "$cdir/BINARY.setup" --minimal fi [ -n "$CCP4" ] && \ echo "Note: Replacing current CCP4 environment." case "$(basename $SHELL)" in bash) ;; *) echo "Note: This script opens bash (not `basename $SHELL`, at least for now)" ;; esac case "$LC_CTYPE$LANG" in *.[Uu][Tt][Ff]*8*) ps1_prefix="\[\e[0;36m\]♦\[\e[m\]" ;; *) ps1_prefix="\[\e[0;36m\]C\[\e[m\]" ;; esac cat > $tmp_file <> $tmp_file done fi # in here-document "$@" is expanded like "$*"; let's use built-in printf [ -n "$1" ] && { printf "exec "; printf "%q " "$@"; printf "\n"; } >> $tmp_file cat >> $tmp_file <> $tmp_file << EOF echo -e "\033]0;CCP4 $short_name\007" trap 'echo -e "\033]0;\007"' EXIT EOF fi # adding exec here would prevent removing $tmp_file bash --rcfile $tmp_file