1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
#!/bin/sh
fullpath_dir() {
(
cd $(dirname $0);
echo $(pwd)
)
}
# Locate bin-folder and prefix from current script-location
BIN="$(fullpath_dir)"
PREFIX=$(dirname "${BIN}")
usage() {
echo "usage: $0 [OPTION]... package [VERSION]";
cat <<EOF
Select a specific version of McStas/McXtrace as default.
--list list available versions of package.
--install install a new version of package for later linking.
--help display this help and exit.
Report bugs to jsbn@fysik.dtu.dk
EOF
}
if [ "x$1" = "x--no-update-alternatives" ]; then
HAS_ALTERNATIVES=false;
shift;
else
HAS_ALTERNATIVES=true;
fi
# Parse arguments
LIST=false;
INSTALL=false;
DRYRUN="";
while true; do
case "$1" in
"--list" )
LIST=true
;;
"--install" )
INSTALL=true;
;;
"--dryrun" )
DRYRUN="$1";
;;
* )
# No match, drop out
break;
esac
shift;
done
# Sanity check
if ${LIST} && [ "x${INSTALL}" = "x--install" ] ; then
echo "Error: list and install cannot be combined. Pick one.";
exit 1;
fi
# Check for help or missing package name after parsing arguments
if [ "x$1" = "x" ] || [ "x$1" = "x--help" ] ; then
usage;
exit 0;
fi
NAME="$1"
VERSION="$2"
flavor() {
case "$1" in
"mcstas" )
echo "mc";
;;
"mcxtrace" )
echo "mx";
;;
esac
}
echo `flavor mcxtrace`
case "`flavor $1`" in
"mc" )
TOOLS="config convert daemon display doc formatgui gui plot resplot run stas2vitess"
;;
"mx" )
TOOLS="config convert daemon display doc formatgui gui plot run"
;;
esac
mcselect() {
if ${HAS_ALTERNATIVES}; then
mccode-select --install $*
else
mccode-select --no-update-alternatives --install $*
fi
}
list() {
mccode-select --list ${NAME};
}
switch_version() {
(
DRYRUN="$1"
ret=0;
cd "${PREFIX}";
MC="`flavor ${NAME}`";
# Setup core
echo "Core:"
for name in "${NAME}" "${MC}format"; do
mcselect $DRYRUN "${name}" "${VERSION}" || ret=1;
done
# Setup tools
echo ""
echo "Tools:"
for tool in ${TOOLS}; do
name="${MC}${tool}";
vers="${VERSION}";
# Install Perl tool
mcselect $DRYRUN "${name}" "${vers}" || \
echo "> skipping: ${NAME}-tools-${VERSION} isn't installed?";
if [ -x "bin/${name}-${vers}-py" ]; then
# Install Python tool as well
mcselect $DRYRUN "${name}" "${vers}-py" || \
echo ".. skipping";
fi
done
exit ${ret};
)
}
if ${LIST}; then
# list available versions
list;
else
if ! ${INSTALL} || [ "x${VERSION}" = "x" ]; then
usage;
exit 1;
fi
# test run
switch_version --dryrun > /dev/null;
if [ $? -eq 0 ]; then
# things look good, do real run
switch_version ${DRYRUN};
else
# rerun test run with messages
switch_version --dryrun;
fi
fi
|