Page MenuHomec4science

install_bins.sh
No OneTemporary

File Metadata

Created
Sat, May 4, 13:34

install_bins.sh

#!/bin/bash
# Set SNAME, SDIR and SPATH
if [ -h $0 ]; then SNAME=$(readlink $0); else SNAME=$0; fi
SDIR=$(dirname $SNAME)
if [[ "$SDIR" =~ ^/ ]]; then SPATH=$SDIR; else SPATH=$(realpath $(pwd)/$SDIR); fi
# Set DIR_LIB
DIR_LIB=$(realpath $SPATH/../lib/bash)
# Source libs
source $DIR_LIB/colors.sh
source $DIR_LIB/io.sh
# Set DESTINATION
if [ -n "$1" ]; then
DESTINATION="$(realpath $1)"
else
DESTINATION=$(realpath ${HOME}/bin)
fi
if [ ! -d $DESTINATION/ ]; then
error_echo "'$DESTINATION' is not a valid directory."
exit 1
fi
info_echo "Using '$DESTINATION' as binary directory."
function link_to_binaries() {
for bin in $(echo $BINS); do
if [ -r $DESTINATION/$bin ]; then
if [ -h $DESTINATION/$bin ]; then
OLD=$(realpath $DESTINATION/$bin)
if [ "$OLD" == "$DIR_BIN/$bin" ]; then
color_echo_n "Command '$bin' already exists... "
else
color_echo_n "Moving command '$bin' from '$OLD' to '$DIR_BIN/$bin'... "
rm $DESTINATION/$bin
ln -s $DIR_BIN/$bin $DESTINATION/$bin
fi
else
error_echo "A similar command already exists: '$OLD'"
exit 2
fi
else
color_echo_n "Installing command '$bin' to '$DESTINATION/'... "
ln -s $DIR_BIN/$bin $DESTINATION/$bin
fi
[ -h $DESTINATION/$bin ]
check_rc_echo $?
done
}
DIR_BIN=$(realpath $SPATH/../bin)
BINS='bamc'
link_to_binaries
DIR_BIN=$(realpath $SPATH/../local/epfl)
BINS='search-epfl'
link_to_binaries
# Done
warning_echo "Make sure '$DESTINATION' is in your \$PATH variable.";
# RIP
exit 0

Event Timeline