Page MenuHomec4science

install_bins.sh
No OneTemporary

File Metadata

Created
Sat, Apr 20, 02:43

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)
# DEBUG STUFF
#echo "SNAME: $SNAME"
#echo "SDIR: $SDIR"
#echo "SPATH: $SPATH"
#echo "DIR_LIB: $DIR_LIB"
# Source libs
source $DIR_LIB/tools.sh
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."
info_echo "To change binary directory, run \"$(basename $0) /path/to/your/bin_dir\""
confirm "Do you want to continue using \"$DESTINATION\" as binary directory?"
if [ $? -eq 0 ]; then exit; fi;
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 $?
if [ $(command $bin 2> /dev/null | wc -l) -eq 0 ]; then
warning_echo "Make sure '$DESTINATION' is in your \$PATH variable. (Looks like it is not the case.)";
fi
done
}
DIR_BIN=$(realpath $SPATH/../bin)
BINS='bamc'
link_to_binaries
DIR_BIN=$(realpath $SPATH/../local/epfl)
BINS='sel check-scipers'
link_to_binaries
DIR_BIN=$(realpath $SPATH/../local/pdf)
BINS='pdf-add-blanks'
link_to_binaries
DIR_BIN=$(realpath $SPATH/../local/stats)
BINS='amcstats'
link_to_binaries
if [ "$OS" == "darwin" ]; then
if [ "$CLICOLOR" != "1" ]; then
info_echo "To have output colors in your terminal, set CLICOLOR=1 in your environment."
fi
fi
# RIP
exit 0

Event Timeline