runon/install
Gilles Grandou 8b08aab4e7 symlink enhancements
* runon -l now install symlink
* install -u now removes all found symlinks to runon
2021-05-01 16:29:59 +02:00

104 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/bash
local_bin_dir=~/local/bin
local_config_dir=~/.config/runon
system_bin_dir=/etc/runon
system_config_dir=/usr/local/bin
op=install
bin_dir=$local_bin_dir
config_dir=$local_config_dir
function usage
{
echo "$0 [local|system] [-u|--uninstall] [<dest>]"
echo
echo " local install for local user, by default"
echo " system install for all users"
echo " dev install in dev mode (create links to source)"
echo " -u, --uninstall local or system uninstall"
echo " <dest> destination dir for binary"
echo
echo "default local paths:"
echo " binary: $local_bin_dir"
echo " config: $local_config_dir"
echo
echo "default system paths:"
echo " binary: $system_bin_dir"
echo " config: $system_config_dir"
echo
}
function do_exec
{
echo "$@"
"$@"
}
while [ $# -gt 0 ]; do
case $1 in
local)
bin_dir=$local_bin_dir
config_dir=$local_config_dir
;;
system)
bin_dir=$system_bin_dir
config_dir=$system_config_dir
;;
dev)
bin_dir=$local_bin_dir
config_dir=$local_config_dir
op=installdev
;;
-u)
op=uninstall
;;
--uninstall)
op=uninstall
;;
-h*)
usage
exit 0
;;
*) bin_dir=$1
;;
esac
shift
done
bin_dir=$(realpath $bin_dir)
config_dir=$(realpath $config_dir)
if [[ ":$PATH:" != *":$bin_dir:"* ]]; then
echo "WARNING: $bin_dir is not in your PATH, runon will not be automatically found."
echo
fi
set -e
if [ "$op" = "install" ]; then
do_exec install -d $bin_dir
do_exec install -d $config_dir
#rm -f $bin_dir/runon
#rm -f $config_dir/runon
do_exec install runon $bin_dir
do_exec install runon.conf $config_dir
elif [ "$op" = "installdev" ]; then
do_exec install -d $bin_dir
do_exec install -d $config_dir
do_exec ln -s -f $(realpath runon) $bin_dir/
do_exec ln -s -f $(realpath runon.conf) $config_dir/
elif [ "$op" = "uninstall" ]; then
# find all symlinks targetting to runon, and remove them
find $bin_dir -type l | while read l; do
if [ "$(readlink $l)" = "runon" ]; then
do_exec rm $l
fi
done
do_exec rm -f $bin_dir/runon
do_exec rm -f $config_dir/runon.conf
test -d $bin_dir && do_exec rmdir --parents --ignore-fail-on-non-empty $bin_dir 2> /dev/null
test -d $config_dir && do_exec rmdir --parents --ignore-fail-on-non-empty $config_dir 2> /dev/null
fi