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

134
install
View File

@ -1,103 +1,41 @@
#!/usr/bin/bash #!/bin/bash
local_bin_dir=~/local/bin srcdir=$(dirname $(readlink -f $0))
local_config_dir=~/.config/runon venvdir=~/.local/lib/runon
system_bin_dir=/usr/local/bin bindir=~/.local/bin
system_config_dir=/etc/runon configdir=~/.config/runon
op=install if [ "$1" == "--dev" ]; then
bin_dir=$local_bin_dir editable=--editable
config_dir=$local_config_dir devmode=1
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 fi
set -e if [ ! -d $venvdir/bin/activate ]; then
echo "create virtualenv $venvdir..."
if [ "$op" = "install" ]; then python3 -m venv $venvdir
do_exec install -d $bin_dir fi
do_exec install -d $config_dir source $venvdir/bin/activate
#rm -f $bin_dir/runon
#rm -f $config_dir/runon echo "populate $venvdir..."
do_exec install runon $bin_dir python3 -m pip install --upgrade pip
do_exec install runon.conf $config_dir python3 -m pip install wheel
elif [ "$op" = "installdev" ]; then python3 -m pip install $editable $srcdir
do_exec install -d $bin_dir
do_exec install -d $config_dir echo "create links in $bindir..."
do_exec ln -s -f $(realpath runon) $bin_dir/ mkdir -p $bindir
do_exec ln -s -f $(realpath runon.conf) $config_dir/ ln -sf $venvdir/bin/runon $bindir/
elif [ "$op" = "uninstall" ]; then
# find all symlinks targetting to runon, and remove them echo "install base config in $configdir..."
find $bin_dir -type l | while read l; do mkdir -p $configdir
if [ "$(readlink $l)" = "runon" ]; then if [ -n "$devmode" ]; then
do_exec rm $l ln -s $srcdir/runon.default.conf $configdir/
fi else
done cp -p $srcdir/runon.default.conf $configdir/
fi
do_exec rm -f $bin_dir/runon
do_exec rm -f $config_dir/runon.conf echo "done."
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 if [[ ":$PATH:" != *":$(readlink -f $bindir):"* ]]; then
echo ""
echo "WARNING: $bindir is not in your PATH"
fi fi

View File

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