install.sh: use variable for bin name and reponame

This commit is contained in:
yaw 2025-10-26 22:52:04 +01:00
parent c08442f2ea
commit e678b71778

View File

@ -1,5 +1,5 @@
#!/bin/bash
## INSTALL pdf2zine in Linux or macOS
## INSTALL ${REPONAME} in Linux or macOS
### Dependencies:
# - bash: check with `bash --version`
# - python3: check with `python3 --version`
@ -15,11 +15,11 @@ python3 -m venv --help > /dev/null || echo 'install venv with pip?'
#
PREFIX="$HOME/.local"
HELP="""
$0: install pdf2zine with its virtual environment
$0: install ${REPONAME} with its virtual environment
usage:
-h|--help show this help message and exti
-d|--delete remove pdf2zine installation
-f|--force force overwriting of PREFIX/lib/pdf2zine.git
-d|--delete remove ${REPONAME} installation
-f|--force force overwriting of PREFIX/lib/${REPONAME}.git
can be used for upgrading
-p|--prefix PREFIX install into PREFIX/lib and PREFIX/bin
-v|--verbose print more info (set -x)
@ -33,7 +33,7 @@ while [[ $# -gt 0 ]]; do
DELETE=1
echo 'THIS DOES NOTHING AT THE MOMENT ...'
echo 'todo:'
echo " - [ ] remove $PREFIX/pdf2zine.git"
echo " - [ ] remove $PREFIX/${REPONAME}.git"
echo " - [ ] and clean your ~/.bashrc or ~/.zshrc"
exit 0
;;
@ -67,7 +67,7 @@ done
if [[ $PSET != 1 ]]
then
echo -n """Where to do you want to install 'pdf2zine'?
echo -n """Where to do you want to install '${REPONAME}'?
PREFIX [$PREFIX] :
"""
read userprefix
@ -77,21 +77,27 @@ PREFIX [$PREFIX] :
fi
fi
REPONAME=pdf2book
BINNAME=pdf2zine
LIBDIR=$PREFIX/lib
BINDIR=$PREFIX/bin
SRCDIR=$LIBDIR/pdf2zine.git
SRCDIR=$LIBDIR/${REPONAME}.git
if [[ -d $SRCDIR ]]
then
if [[ -z $FORCE ]]
then
echo -n """Directory '$SRCDIR' already exist.
Do you want to overwrite? [y/N] """
read confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || echo "... exiting ..." && exit 1
read confirm
if ! [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]]
then
echo "... exiting ..." && exit 1
fi
fi
rm -rf $SRCDIR
fi
mkdir -p $LIBDIR $BINDIR
git clone https://git.wlankabel.at/onipa/pdf2zine.git $SRCDIR
git clone https://git.wlankabel.at/onipa/${REPONAME}.git $SRCDIR
python3 -m venv $SRCDIR/.venv
. $SRCDIR/.venv/bin/activate
pip3 install pypdf
@ -99,11 +105,11 @@ echo -n '''#!/bin/bash
SRCDIR='$SRCDIR'
VENVDIR=$SRCDIR/.venv
. $VENVDIR/bin/activate
python3 $SRCDIR/pdf2zine.py $@
python3 $SRCDIR/'''${BINNAME}'''.py $@
deactivate
'''> $BINDIR/pdf2zine
chmod +x $BINDIR/pdf2zine
echo "pdf2zine is installed into '$(realpath $BINDIR)'"
'''> $BINDIR/${BINNAME}
chmod +x $BINDIR/${BINNAME}
echo "$BINNAME} is installed into '$(realpath $BINDIR)'"
#check if $BINDIR is in $PATH
INPATH=$(echo $PATH | tr : '\n' | grep $(realpath $BINDIR) | wc -l )
if [[ $INPATH -lt 1 ]]
@ -120,8 +126,6 @@ then
if [[ $confirm == [yY] || $confirm == [yY][eE][sS] || -z $confirm ]]
then
echo 'export PATH=$PATH:'$(realpath $BINDIR) >> $HOME/$RCFILE
fi
fi
#echo inpath: $INPATH
echo "you might need to restart your shell"
#echo prefix: $PREFIX
fi
fi