pdf2book/install.sh

132 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
## INSTALL ${REPONAME} in Linux or macOS
### Dependencies:
# - bash: check with `bash --version`
# - python3: check with `python3 --version`
#- venv: check with `python3 -m venv --help`
#
set -e
# check dependencies
# if not available print error msg
git --version > /dev/null
bash --version > /dev/null
python3 --version > /dev/null
python3 -m venv --help > /dev/null || echo 'install venv with pip?'
#
PREFIX="$HOME/.local"
HELP="""
$0: install ${REPONAME} with its virtual environment
usage:
-h|--help show this help message and exti
-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)
-y|--yes don't ask for confimation of prefix
"""
# OPTIONS
# Iterate through each argument
while [[ $# -gt 0 ]]; do
case "$1" in
--delete|-d)
DELETE=1
echo 'THIS DOES NOTHING AT THE MOMENT ...'
echo 'todo:'
echo " - [ ] remove $PREFIX/${REPONAME}.git"
echo " - [ ] and clean your ~/.bashrc or ~/.zshrc"
exit 0
;;
--force|-f)
FORCE=1
;;
--help|-h)
echo "$HELP"
# Add help instructions here
exit 0
;;
--prefix|-p)
PSET=1
PREFIX=$2
shift 1
;;
--verbose|-v)
set -x
;;
--yes|-y)
PSET=1
;;
*)
echo "Unknown option: $1"
echo "HELP"
exit 1
;;
esac
shift 1 # Move to the next argument
done
if [[ $PSET != 1 ]]
then
echo -n """Where to do you want to install '${REPONAME}'?
PREFIX [$PREFIX] :
"""
read userprefix
if [[ -n $userprefix ]]
then
PREFIX=$userprefix
fi
fi
REPONAME=pdf2book
BINNAME=pdf2zine
LIBDIR=$PREFIX/lib
BINDIR=$PREFIX/bin
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
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/${REPONAME}.git $SRCDIR
python3 -m venv $SRCDIR/.venv
. $SRCDIR/.venv/bin/activate
pip3 install pypdf
echo -n '''#!/bin/bash
SRCDIR='$SRCDIR'
VENVDIR=$SRCDIR/.venv
. $VENVDIR/bin/activate
python3 $SRCDIR/'''${BINNAME}'''.py $@
deactivate
'''> $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 ]]
then
if [[ $(uname) == "Darwin" ]]
then
RCFILE='.zshrc'
else
RCFILE=".bashrc"
fi
echo "WARNING! '$BINDIR' is not in \$PATH"
echo -n """Do you want to add '$BINDIR' to \$PATH (via ~/$RCFILE)? [Y/n] """
read confirm
if [[ $confirm == [yY] || $confirm == [yY][eE][sS] || -z $confirm ]]
then
echo 'export PATH=$PATH:'$(realpath $BINDIR) >> $HOME/$RCFILE
echo "you might need to restart your shell"
fi
fi