diff --git a/.gitignore b/.gitignore index 96374c4..01ac832 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +# .env file +.env # Windows image file caches Thumbs.db ehthumbs.db diff --git a/Dockerfile b/Dockerfile index 7ce4fcb..2912994 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,99 +1,80 @@ -FROM lsiobase/alpine.python.armhf:3.8 +FROM trasba/docker-baseimage-ubuntu-armhf # set version label ARG BUILD_DATE ARG VERSION -LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}" -LABEL maintainer="chbmb" +LABEL build_version="version:- ${VERSION} Build-date:- ${BUILD_DATE}" +LABEL maintainer="trasba" RUN \ - echo "**** install build packages ****" && \ - apk add --no-cache --virtual=build-dependencies \ - file \ - fontconfig-dev \ - freetype-dev \ - g++ \ - gcc \ - ghostscript-dev \ - lcms2-dev \ - libjpeg-turbo-dev \ - libpng-dev \ - libtool \ - libwebp-dev \ - libxml2-dev \ - libxslt-dev \ - make \ - perl-dev \ - python2-dev \ - tiff-dev \ - xz \ - zlib-dev && \ - echo "**** install runtime packages ****" && \ - apk add --no-cache \ - fontconfig \ - freetype \ - ghostscript \ - lcms2 \ - libjpeg-turbo \ - libltdl \ - libpng \ - libwebp \ - libxml2 \ - libxslt \ - tiff \ - zlib && \ - echo "**** compile imagemagic ****" && \ - IMAGEMAGICK_VER=$(curl --silent http://www.imagemagick.org/download/digest.rdf \ - | grep ImageMagick-6.*tar.gz | sed 's/\(.*\).tar.*/\1/' \ - | sed 's/^.*ImageMagick-/ImageMagick-/') && \ - mkdir -p \ - /tmp/imagemagick && \ - curl -o \ - /tmp/imagemagick-src.tar.xz -L \ - "http://www.imagemagick.org/download/${IMAGEMAGICK_VER}.tar.xz" && \ - tar xf \ - /tmp/imagemagick-src.tar.xz -C \ - /tmp/imagemagick --strip-components=1 && \ - cd /tmp/imagemagick && \ - sed -i -e \ - 's:DOCUMENTATION_PATH="${DATA_DIR}/doc/${DOCUMENTATION_RELATIVE_PATH}":DOCUMENTATION_PATH="/usr/share/doc/imagemagick":g' \ - configure && \ - ./configure \ - --infodir=/usr/share/info \ - --mandir=/usr/share/man \ - --prefix=/usr \ - --sysconfdir=/etc \ - --with-gs-font-dir=/usr/share/fonts/Type1 \ - --with-gslib \ - --with-lcms2 \ - --with-modules \ - --without-threads \ - --without-x \ - --with-tiff \ - --with-xml && \ - make && \ - make install && \ - find / -name '.packlist' -o -name 'perllocal.pod' \ - -o -name '*.bs' -delete && \ + echo "**** install runtime packages & dev packages ****" && \ + apt-get update && apt-get install -y \ + python \ + python-pip \ + python-setuptools \ + curl \ + file \ + libfontconfig1-dev \ + libfreetype6-dev \ + g++ \ + gcc \ + libgs-dev \ + liblcms2-dev \ + libturbojpeg0-dev \ + libpng-dev \ + libtool \ + libwebp-dev \ + libxml2-dev \ + libxslt1-dev \ + make \ + libperl-dev \ + python-dev \ + libtiff5-dev \ + zlib1g-dev && \ + echo "**** install calibre ****" && \ + apt-get install calibre --no-install-recommends -y && \ echo "**** install calibre-web ****" && \ - mkdir -p \ - /app/calibre-web && \ - curl -o \ - /tmp/calibre-web.tar.gz -L \ - https://github.com/janeczku/calibre-web/archive/master.tar.gz && \ - tar xf \ - /tmp/calibre-web.tar.gz -C \ - /app/calibre-web --strip-components=1 && \ + mkdir -p /app/calibre-web && \ + curl -L https://github.com/trasba/calibre-web/archive/master.tar.gz \ + | tar xzv --strip-components=1 -C /app/calibre-web && \ cd /app/calibre-web && \ - pip install --no-cache-dir -U -r \ - requirements.txt && \ - pip install --no-cache-dir -U -r \ - optional-requirements.txt && \ + pip install --no-cache-dir -U -r requirements.txt && \ + sed -i 's/lxml==3.7.2/lxml>=3.8.0/g' optional-requirements.txt && \ + pip install --no-cache-dir -U -r optional-requirements.txt && \ echo "**** cleanup ****" && \ - apk del --purge \ - build-dependencies && \ + apt-get purge -y \ + file libfontconfig1-dev libfreetype6-dev g++ gcc libgs-dev \ + liblcms2-dev libturbojpeg0-dev libpng-dev libtool libwebp-dev \ + libxml2-dev libxslt1-dev make libperl-dev python-dev libtiff5-dev \ + zlib1g-dev python-dev autotools-dev binutils binutils-arm-linux-gnueabihf \ + binutils-common cpp cpp-7 dirmngr fakeroot fonts-droid-fallback \ + fonts-noto-mono g++-7 gcc-7 gcc-7-base gir1.2-harfbuzz-0.0 \ + gnupg gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-client \ + gpg-wks-server gpgconf gpgsm icu-devtools libalgorithm-diff-perl \ + libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan4 \ + libassuan0 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 \ + libcilkrts5 libcupsfilters-dev libcupsfilters1 libcupsimage2 \ + libdpkg-perl libelf1 libexpat1-dev libfakeroot \ + libfile-fcntllock-perl libgcc-7-dev libgdbm-compat4 libgdbm5 \ + libglib2.0-bin libglib2.0-dev-bin libgraphite2-dev libgs9 \ + libgs9-common libharfbuzz-gobject0 libharfbuzz-icu0 libicu-le-hb0 \ + libiculx60 libijs-0.35 libijs-dev libijs-doc libisl19 libjbig-dev \ + libjbig2dec0 libjbig2dec0-dev libjpeg-dev libjpeg-turbo8-dev \ + libjpeg8-dev libksba8 liblocale-gettext-perl libltdl-dev \ + liblzma-dev libmagic-mgc libmagic1 libmpc3 libmpdec2 libmpfr6 \ + libnpth0 libpaper-dev libpaper-utils libpaper1 libpcre16-3 \ + libpcre3-dev libpcre32-3 libpcrecpp0v5 libperl5.26 libpng-tools \ + libpython-all-dev libpython-dev libpython2.7-dev libpython3-stdlib \ + libpython3.6-minimal libpython3.6-stdlib libstdc++-7-dev libtiffxx5 \ + libturbojpeg libubsan0 linux-libc-dev manpages manpages-dev netbase \ + patch perl perl-modules-5.26 pinentry-curses python-all \ + python2.7-dev python3 python3-distutils python3-lib2to3 \ + python3-minimal python3.6 && \ + apt-get clean && \ rm -rf \ - /tmp/* + /tmp/* \ + /var/lib/apt/lists/* \ + /var/tmp/* # add local files COPY root/ / diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..244bc8d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3.4' + +services: + calibre-web: + image: trasba/calibre-web-rpi:edge + build: . + environment: + - TZ=${TZ} + - PUID=${PUID} + - PGID=${PGID} + ports: + - "8089:8083" + volumes: + - ${volbooks}:/books + - ${volconfig}:/config + restart: unless-stopped diff --git a/docker-template.service b/docker-template.service new file mode 100644 index 0000000..dc2794b --- /dev/null +++ b/docker-template.service @@ -0,0 +1,19 @@ +[Unit] +Description=docker.docker-calibre-web daemon +After=network.target docker.service + +[Service] +Type=simple +WorkingDirectory=~~WORK-DIR~~ +ExecStart=~~DOCKER-COMPOSE-BIN~~/docker-compose -f ~~DOCKER-COMPOSE~~ up +ExecStop=~~DOCKER-COMPOSE-BIN~~/docker-compose -f ~~DOCKER-COMPOSE~~ down +Restart=always +User=~~USER~~ +# Note RHEL/Fedora uses 'nobody', Debian/Ubuntu uses 'nogroup' +Group=~~USER~~ +#paths also for other applications used by the libs, e.g awk & grep +#Environment=PATH=/bin:/usr/bin:/home/pi/.nvm/versions/node/v8.10.0/bin + +[Install] +WantedBy=multi-user.target + diff --git a/docker.calibre-web-rpi.service b/docker.calibre-web-rpi.service new file mode 120000 index 0000000..d2a14ee --- /dev/null +++ b/docker.calibre-web-rpi.service @@ -0,0 +1 @@ +/home/pi/.trasba/testing/docker.calibre-web-rpi.service \ No newline at end of file diff --git a/init-env.sh b/init-env.sh new file mode 100755 index 0000000..176d5e1 --- /dev/null +++ b/init-env.sh @@ -0,0 +1,113 @@ +#!/bin/bash +configFile="/.env" +configPath="/.trasba/testing" +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +bak=".bak" +### default values +def_PGID="1000" +def_PUID="1000" +def_TZ="TZ=CET-1CEST,M3.5.0/2,M10.5.0/3" +def_volbooks="~/.trasba/calibre-web/books" +def_volconfig="~/.trasba/calibre-web/config" +### define functions +function setconfig { #ask user for settings + echo "leave empty to use default" + read -p "PGID [1000]: " PGID + read -p "PUID [1000]: " PUID + read -p "TZ (timezone) [$def_TZ]: " TZ + read -p "volbooks [$def_volbooks]: " volbooks + read -p "volconfig [$def_volconfig]: " volconfig + if [ -z $PGID ]; then + echo "PGID=$def_PGID" > $hd$configPath$configFile + else + echo "PGID=$PGID" > $hd$configPath$configFile + fi + if [ -z $PUID ]; then + echo "PUID=$def_PUID" >> $hd$configPath$configFile + else + echo "PUID=$PUID" >> $hd$configPath$configFile + fi + if [ -z $TZ ]; then + echo "TZ=$def_TZ" >> $hd$configPath$configFile + else + echo "TZ=$TZ" >> $hd$configPath$configFile + fi + if [ -z $volbooks ]; then + echo "volbooks=$def_volbooks" >> $hd$configPath$configFile + else + echo "volbooks=$volbooks" >> $hd$configPath$configFile + fi + if [ -z $volconfig ]; then + echo "volconfig=$def_volconfig" >> $hd$configPath$configFile + else + echo "volconfig=$volconfig" >> $hd$configPath$configFile + fi +} + +function checklocal { # true if file exists, false if not + if [ -f $DIR$configFile ]; then + existslocal=1 + else + existslocal=0 + fi +} + +function create-symlink { + echo "Creating symlink $hd$configPath$configFile -> $DIR$configFile" + ln -s $hd$configPath$configFile $DIR$configFile +} +### get user home dir +hd=$( getent passwd "$USER" ) #hd => homedir +hdRC=$? #hdRC => homedir Return Code +if [ $hdRC == 0 ]; + then + hd=$(echo $hd|cut -d: -f6) +elif [ $hdRC == 2 ]; + then + echo "getent error: One or more supplied key could not be found in the database." + echo "Does the user exist?" + exit 1 +fi +### echo remote dir and local dir +echo "Remote config path is: $hd$configPath" +echo "Local config path is: $DIR" +### check if file exists remotely, and create it if not +if [ ! -f $hd$configPath$configFile ]; then + echo "Config file does not exist." + echo "Creating config path" + mkdir -p $hd$configPath #make dir if it does not exist + setconfig +else + echo "Remote config file exists." +fi +### check if file exists locally +checklocal +if [ $existslocal == 1 ]; then + echo "Local config file exists." + realpath=$(readlink -f $DIR$configFile) + if [ $realpath == $hd$configPath$configFile ]; then + echo "Symlink already created." + while true; do + read -p "Recreate config file?(y/n) " recreate + case $recreate in + [Yy]* ) echo "Backing up old config file"; cp $DIR$configFile $DIR$configFile$bak; rm $DIR$configFile; setconfig; create-symlink; break;; + [Nn]* ) echo "Nothing to do."; break;; + * ) echo "Please answer yes or no.";; + esac + done + echo "Exiting." + exit 0 + fi + while true; do + read -p "Overwrite local config file?(y/n) " overwrite + case $overwrite in + [Yy]* ) echo "Backing up old config file"; cp $DIR$configFile $DIR$configFile$bak; rm $DIR$configFile; create-symlink; break;; + [Nn]* ) echo "Aborting"; exit;; + * ) echo "Please answer yes or no.";; + esac + done +else + create-symlink + echo "Exiting." +fi +exit 0 diff --git a/init-service.sh b/init-service.sh new file mode 100755 index 0000000..3a09bcb --- /dev/null +++ b/init-service.sh @@ -0,0 +1,111 @@ +#!/bin/bash +tmplFile="/docker-template.service" +configFile="/docker.calibre-web-rpi.service" +configPath="/.trasba/testing" +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +def_username="pi" +def_dockercompose="\/docker-compose.yml" +bak=".bak" +### define functions +function get_dockercompose_path { + dockercompose_bin=$(which docker-compose) + tmp_ext=$? + if [ $tmp_ext == 1 ]; then + echo "docker-compose could not be found with which. Is it installed?" + echo "Exiting" + exit 1 + fi +} +function enable_service { + if [ $EUID != 0 ]; then + sudo "$0" "$@" + exit $? + fi + systemctl enable $DIR$configFile + service docker.docker-calibre-web start +} +function setconfig { #ask user for settings + echo "Creating service file with current directory as working dir" + echo "leave empty to use default" + read -p "username [$def_username]: " username + if [ -z $username ]; then + username=$def_username + else + username=$username + fi + sed 's,~~WORK-DIR~~,'"$DIR"',g' $DIR$tmplFile > $hd$configPath$configFile + sed -i 's,~~USER~~,'"$username"',g' $hd$configPath$configFile + sed -i 's,~~DOCKER-COMPOSE~~,'"$DIR$def_dockercompose"',g' $hd$configPath$configFile + sed -i 's,~~DOCKER-COMPOSE-BIN~~,'"$DIR$dockercompose_bin"',g' $hd$configPath$configFile +} +function checklocal { # true if file exists, false if not + if [ -f $DIR$configFile ]; then + existslocal=1 + else + existslocal=0 + fi +} +function create-symlink { + echo "Creating symlink $hd$configPath$configFile -> $DIR$configFile" + ln -s $hd$configPath$configFile $DIR$configFile +} + +### get user home dir +get_dockercompose_path +hd=$( getent passwd "$USER" ) #hd => homedir +hdRC=$? #hdRC => homedir Return Code +if [ $hdRC == 0 ]; + then + hd=$(echo $hd|cut -d: -f6) +elif [ $hdRC == 2 ]; + then + echo "getent error: One or more supplied key could not be found in the database." + echo "Does the user exist?" + exit 1 +fi + +### echo remote dir and local dir +echo "Remote config path is: $hd$configPath" +echo "Local config path is: $DIR" +### check if file exists remotely, and create it if not +if [ ! -f $hd$configPath$configFile ]; then + echo "Config file does not exist." + echo "Creating config path" + mkdir -p $hd$configPath #make dir if it does not exist + setconfig +else + echo "Remote config file exists." +fi +### check if file exists locally +checklocal +if [ $existslocal == 1 ]; then + echo "Local config file exists." + realpath=$(readlink -f $DIR$configFile) + if [ $realpath == $hd$configPath$configFile ]; then + echo "Symlink already created." + while true; do + read -p "Recreate config file?(y/n) " recreate + case $recreate in + [Yy]* ) echo "Backing up old config file"; mv $DIR$configFile $DIR$configFile$bak; setconfig; create-symlink; break;; + [Nn]* ) echo "Nothing to do."; break;; + * ) echo "Please answer yes or no.";; + esac + done + echo "enabling service" + enable_service + echo "Exiting." + exit 0 + fi + while true; do + read -p "Overwrite local config file?(y/n) " overwrite + case $overwrite in + [Yy]* ) echo "Backing up old config file"; mv $DIR$configFile $DIR$configFile$bak; create-symlink; break;; + [Nn]* ) echo "Aborting"; exit;; + * ) echo "Please answer yes or no.";; + esac + done +else + create-symlink + echo "Exiting." +fi +exit 0