From c8cb8f788ad30c149fbb6f0eeeba6cc9092a39a3 Mon Sep 17 00:00:00 2001 From: Danny Bautista Date: Fri, 7 Jun 2019 14:10:29 -0400 Subject: [PATCH] Add --group parameter. --- scripts/README.md | 2 ++ scripts/deploy-ebook-to-www | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index 933a409c..268fcc37 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -5,3 +5,5 @@ 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. + +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 593211bc..34dc2842 100755 --- a/scripts/deploy-ebook-to-www +++ b/scripts/deploy-ebook-to-www @@ -6,8 +6,9 @@ DESCRIPTION Deploy a Standard Ebook source repository to the web. USAGE - deploy-ebook-to-www [-v,--verbose] DIRECTORY [DIRECTORY...] + deploy-ebook-to-www [-v,--verbose] [-g,--group GROUP] DIRECTORY [DIRECTORY...] DIRECTORY is a bare source repository. + GROUP is a groupname. Defaults to "se". EOF exit } @@ -16,6 +17,7 @@ require(){ command -v "$1" > /dev/null 2>&1 || { suggestion=""; if [ -n "$2" ]; # End boilerplate verbose="false" +group="se" if [ $# -eq 0 ]; then usage @@ -29,10 +31,19 @@ while [ $# -gt 0 ]; do verbose="true" shift 1 ;; + -g|--group) + [ -n "$2" ] || die "Group cannot be empty." + group="$2" + shift 2 + ;; *) break ;; esac done +if ! [ "$(getent group "${group}")" ]; then + die "Group ${group} does not exist. Either use --group or create the group." +fi + # Check for dependencies require "convert" "Try: apt-get install imagemagick" require "rsvg-convert" "Try: apt-get install librsvg2-bin" @@ -127,7 +138,7 @@ do mv "${imgWorkDir}/${urlSafeIdentifier}@2x.jpg" "${imgWorkDir}/${urlSafeIdentifier}-cover@2x.jpg" mv "${imgWorkDir}/${urlSafeIdentifier}.jpg" "${imgWorkDir}/${urlSafeIdentifier}-cover.jpg" - sudo chgrp --preserve-root --recursive se "${imgWorkDir}/${urlSafeIdentifier}"* + sudo chgrp --preserve-root --recursive "${group}" "${imgWorkDir}/${urlSafeIdentifier}"* sudo chmod --preserve-root --recursive g+w "${imgWorkDir}/${urlSafeIdentifier}"* if [ "${verbose}" = "true" ]; then @@ -164,10 +175,10 @@ do # Delete the now-empty work dir (empty except for .git) rm --preserve-root --recursive --force "${workDir}" "${imgWorkDir}" - sudo chgrp --preserve-root --recursive se "${webDir}" + sudo chgrp --preserve-root --recursive "${group}" "${webDir}" sudo chmod --preserve-root --recursive g+ws "${webDir}" - sudo chgrp --preserve-root --recursive se "/standardebooks.org/www/images/covers/" + sudo chgrp --preserve-root --recursive "${group}" "/standardebooks.org/www/images/covers/" sudo chmod --preserve-root --recursive g+ws "/standardebooks.org/www/images/covers/" if [ "${verbose}" = "true" ]; then