From c73da120247ac34d76c2ba6a06ebc036798d4d4a Mon Sep 17 00:00:00 2001 From: "uni@bor.mac" Date: Mon, 9 Jun 2025 22:34:35 +0200 Subject: [PATCH] install.sh: add --- README.md | 3 +- install.sh | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 1 deletion(-) create mode 100755 install.sh diff --git a/README.md b/README.md index aa579c3..5201216 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ CLI script to rearrange pdf pages for printing book signatures and foldable zine - [`venv`](https://docs.python.org/3/library/venv.html) (might be installed) - check with `python3 -m venv --help` -``` +```bash +#!/bin/bash PREFIX="$HOME/.local" LIBDIR=$PREFIX/lib BINDIR=$PREFIX/bin diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..8587471 --- /dev/null +++ b/install.sh @@ -0,0 +1,114 @@ +#!/bin/bash +## INSTALL pdf2book in Linux or macOS +### Dependencies: +# - bash: check with `bash --version` +# - python3: check with `python3 --version` +#- venv: check with `python3 -m venv --help` +# +PREFIX="$HOME/.local" +HELP=""" +$0: install pdf2book with its virtual environment +usage: + -h|--help show this help message and exti + -d|--delete remove pdf2book + -f|--force force overwriting of PREFIX/lib/pdf2book.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 + ;; + --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 'pdf2book'? +PREFIX [$PREFIX] : +""" + read userprefix + if [[ -n $userprefix ]] + then + PREFIX=$userprefix + fi +fi + +LIBDIR=$PREFIX/lib +BINDIR=$PREFIX/bin +SRCDIR=$LIBDIR/pdf2book.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] ]] || exit 1 + fi + rm -rf $SRCDIR +fi +mkdir -p $LIBDIR $BINDIR +git clone https://git.wlankabel.at/onipa/pdf2book.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/pdf2book.py $@ +deactivate +'''> $BINDIR/pdf2book +chmod +x $BINDIR/pdf2book +echo "pdf2book 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 + fi +fi +#echo inpath: $INPATH +echo "you might need to restart your shell" +#echo prefix: $PREFIX