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