From 8349f9268b6f6b832d727856006644f8c6dc8a03 Mon Sep 17 00:00:00 2001 From: Danny Bautista Date: Fri, 7 Jun 2019 14:12:51 -0400 Subject: [PATCH] Add --webroot parameter. --- scripts/README.md | 4 +++- scripts/deploy-ebook-to-www | 27 +++++++++++++++++++-------- scripts/generate-opds.php | 6 +++++- scripts/generate-rss.php | 6 +++++- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index 268fcc37..bf0e68c4 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -4,6 +4,8 @@ To use, call this script with the directory where your ebooks go as its last arg # deploy-ebook-to-www -To use, call this script with the directories of the books you want to deploy as its arguments. For example, to deploy all ebooks after using sync-ebooks, run `deploy-ebook-to-www /standardebooks.org/ebooks/*`. To deploy only The Time Machine by H.G Wells, you would run `deploy-ebook-to-www /standardebooks.org/ebooks/h-g-wells_the-time-machine`. Note that deploy-ebook-to-www assumes that your webroot is in /standardebooks.org/. To output progress information, use -v or --verbose. +To use, call this script with the directories of the books you want to deploy as its arguments. For example, to deploy all ebooks after using sync-ebooks, run `deploy-ebook-to-www /standardebooks.org/ebooks/*`. To deploy only The Time Machine by H.G Wells, you would run `deploy-ebook-to-www /standardebooks.org/ebooks/h-g-wells_the-time-machine`. To output progress information, use -v or --verbose. + +The default web root is /standardebooks.org. If it is located elsewhere, specify it with the --webroot option. For instance, `deploy-ebook-to-www --webroot /var/www/html /path/to/ebook`. Note that there will be php errors if the git repositories are not in the ebook directory immediately in the web root. Either keep them there or create a symlink. The default group is se. to use a different one, specify it with the --group option. For instance, to use this script inside the included Vagrant VM, which uses the www-data group, use `deploy-ebook-to-www --group www-data /path/to/ebook`. diff --git a/scripts/deploy-ebook-to-www b/scripts/deploy-ebook-to-www index 34dc2842..96208c31 100755 --- a/scripts/deploy-ebook-to-www +++ b/scripts/deploy-ebook-to-www @@ -6,9 +6,10 @@ DESCRIPTION Deploy a Standard Ebook source repository to the web. USAGE - deploy-ebook-to-www [-v,--verbose] [-g,--group GROUP] DIRECTORY [DIRECTORY...] + deploy-ebook-to-www [-v,--verbose] [-g,--group GROUP] [--webroot WEBROOT] DIRECTORY [DIRECTORY...] DIRECTORY is a bare source repository. GROUP is a groupname. Defaults to "se". + WEBROOT is the path to your webroot. Defaults to "/standardebooks.org". EOF exit } @@ -18,6 +19,7 @@ require(){ command -v "$1" > /dev/null 2>&1 || { suggestion=""; if [ -n "$2" ]; verbose="false" group="se" +webRoot="/standardebooks.org" if [ $# -eq 0 ]; then usage @@ -36,6 +38,11 @@ while [ $# -gt 0 ]; do group="$2" shift 2 ;; + --webroot) + [ -n "$2" ] || die "Web root can't be empty." + webRoot="$2" + shift 2 + ;; *) break ;; esac done @@ -44,6 +51,10 @@ if ! [ "$(getent group "${group}")" ]; then die "Group ${group} does not exist. Either use --group or create the group." fi +if ! [ -d "${webRoot}" ]; then + die "${webRoot} does not exist or is not a directory." +fi + # Check for dependencies require "convert" "Try: apt-get install imagemagick" require "rsvg-convert" "Try: apt-get install librsvg2-bin" @@ -65,7 +76,7 @@ if ! [ -f "${scriptsDir}"/generate-rss.php ]; then die "\"${scriptsDir}\"/generate-rss.php\" is not a file or could not be found." fi -mkdir -p /standardebooks.org/www/images/covers/ +mkdir -p "${webRoot}"/www/images/covers/ for dir in "$@" do @@ -106,7 +117,7 @@ do workDir=$(mktemp -d) imgWorkDir=$(mktemp -d) - webDir="/standardebooks.org/www/ebooks/${webDir}" + webDir="${webRoot}/www/ebooks/${webDir}" if [ "${verbose}" = "true" ]; then printf "Generating cover image for web ... " @@ -170,7 +181,7 @@ do mv "${workDir}"/* "${webDir}/" # Move the cover images over - mv "${imgWorkDir}/${urlSafeIdentifier}"*.jpg "/standardebooks.org/www/images/covers/" + mv "${imgWorkDir}/${urlSafeIdentifier}"*.jpg "${webRoot}/www/images/covers/" # Delete the now-empty work dir (empty except for .git) rm --preserve-root --recursive --force "${workDir}" "${imgWorkDir}" @@ -178,8 +189,8 @@ do sudo chgrp --preserve-root --recursive "${group}" "${webDir}" sudo chmod --preserve-root --recursive g+ws "${webDir}" - sudo chgrp --preserve-root --recursive "${group}" "/standardebooks.org/www/images/covers/" - sudo chmod --preserve-root --recursive g+ws "/standardebooks.org/www/images/covers/" + sudo chgrp --preserve-root --recursive "${group}" "${webRoot}/www/images/covers/" + sudo chmod --preserve-root --recursive g+ws "${webRoot}/www/images/covers/" if [ "${verbose}" = "true" ]; then printf "Flushing PHP-FPM opcache and apcu cache ... " @@ -199,7 +210,7 @@ if [ "${verbose}" = "true" ]; then printf "Rebuilding OPDS catalog ... " fi -bash -c "php \"${scriptsDir}\"/generate-opds.php > /standardebooks.org/www/opds/all.xml; export XMLLINT_INDENT=\$(printf \"\\t\") && xmllint --c14n /standardebooks.org/www/opds/all.xml | (printf \"%s\\n\" \"\" && cat) | xmllint --output /standardebooks.org/www/opds/all.xml --format -" +bash -c "php \"${scriptsDir}\"/generate-opds.php --webroot \"${webRoot}\" > \"${webRoot}\"/www/opds/all.xml; export XMLLINT_INDENT=\$(printf \"\\t\") && xmllint --c14n \"${webRoot}\"/www/opds/all.xml | (printf \"%s\\n\" \"\" && cat) | xmllint --output \"${webRoot}\"/www/opds/all.xml --format -" if [ "${verbose}" = "true" ]; then printf "Done.\n" @@ -210,7 +221,7 @@ if [ "${verbose}" = "true" ]; then printf "Rebuilding new releases RSS feed ... " fi -bash -c "php \"${scriptsDir}\"/generate-rss.php > /standardebooks.org/www/rss/new-releases.xml" +bash -c "php \"${scriptsDir}\"/generate-rss.php --webroot \"${webRoot}\" > \"${webRoot}\"/www/rss/new-releases.xml" if [ "${verbose}" = "true" ]; then printf "Done.\n" diff --git a/scripts/generate-opds.php b/scripts/generate-opds.php index 6a23803a..4f77c169 100755 --- a/scripts/generate-opds.php +++ b/scripts/generate-opds.php @@ -1,5 +1,9 @@ \n"); ?> diff --git a/scripts/generate-rss.php b/scripts/generate-rss.php index 0987cc50..ae544b1d 100644 --- a/scripts/generate-rss.php +++ b/scripts/generate-rss.php @@ -1,6 +1,10 @@