new install/uninstall scripts

* new uninstall script
* system install no longer supported
* local install using local virtualenv and symbolic links in
  ~/.local/bin
* --dev switch to allow developper mode with symlinks to git
This commit is contained in:
Gilles Grandou 2023-12-04 22:23:28 +01:00
parent 1447b62755
commit 97cf440ce5
4 changed files with 61 additions and 99 deletions

130
install
View File

@ -1,103 +1,41 @@
#!/usr/bin/bash
#!/bin/bash
local_bin_dir=~/local/bin
local_config_dir=~/.config/runon
system_bin_dir=/usr/local/bin
system_config_dir=/etc/runon
srcdir=$(dirname $(readlink -f $0))
venvdir=~/.local/lib/runon
bindir=~/.local/bin
configdir=~/.config/runon
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
if [ "$1" == "--dev" ]; then
editable=--editable
devmode=1
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
if [ ! -d $venvdir/bin/activate ]; then
echo "create virtualenv $venvdir..."
python3 -m venv $venvdir
fi
done
source $venvdir/bin/activate
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
echo "populate $venvdir..."
python3 -m pip install --upgrade pip
python3 -m pip install wheel
python3 -m pip install $editable $srcdir
echo "create links in $bindir..."
mkdir -p $bindir
ln -sf $venvdir/bin/runon $bindir/
echo "install base config in $configdir..."
mkdir -p $configdir
if [ -n "$devmode" ]; then
ln -s $srcdir/runon.default.conf $configdir/
else
cp -p $srcdir/runon.default.conf $configdir/
fi
echo "done."
if [[ ":$PATH:" != *":$(readlink -f $bindir):"* ]]; then
echo ""
echo "WARNING: $bindir is not in your PATH"
fi

View File

@ -23,7 +23,6 @@ def read_ini(user_confname, osname=''):
'.runon.conf',
os.path.join(xdg.BaseDirectory.xdg_config_home, 'runon', 'runon.conf'),
os.path.join(xdg.BaseDirectory.xdg_config_home, 'runon', 'runon.default.conf'),
'/etc/runon/runon.conf',
]
defaults = {
'osname': osname,

25
uninstall Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
srcdir=$(dirname $(readlink -f $0))
venvdir=~/.local/lib/runon
bindir=~/.local/bin
configdir=~/.config/runon
if [ -e $venvdir/bin/runon ]; then
echo "remove links from $bindir"
find -L $bindir -samefile $bindir/runon -exec rm -v {} \;
find -L $bindir -samefile $venvdir/bin/runon -exec rm -v {} \;
fi
if [ -d $venvdir ]; then
echo "remove virtualenv $venvdir"
rm -rf $venvdir
fi
if [ -e $configdir ]; then
echo "remove configs"
rm -vf $configdir/runon.default.conf
rmdir -v $configdir || true
fi
echo "done."