include script to set-owner-name

This commit is contained in:
Eric Dobbs 2017-07-22 21:55:38 -06:00
parent 2b708a73b2
commit 7f64713024
2 changed files with 41 additions and 2 deletions

View File

@ -7,8 +7,8 @@ RUN useradd --create-home app \
WORKDIR /home/app
RUN su app -c "npm install -g --prefix . wiki@0.11.4"
RUN su app -c "mkdir .wiki"
COPY configure-and-launch-wiki configure-and-launch-wiki
RUN chown app configure-and-launch-wiki
COPY configure-and-launch-wiki set-owner-name ./
RUN chown app configure-and-launch-wiki set-owner-name
VOLUME "/home/app/.wiki"
ENV DOMAIN=localhost
ENV OWNER_NAME="The Owner"

39
set-owner-name Executable file
View File

@ -0,0 +1,39 @@
#!/bin/bash -eu
set -o pipefail
usage() {
cat <<EOF
Usage: $(basename $0) NAME
replaces the owner's name in $OWNER_FILE
EOF
}
main() {
initialize-environment-vars $@ || { usage; exit 1; }
backup-and-save-name
report-success
}
initialize-environment-vars() {
readonly OWNER_FILE=/home/app/.wiki/$DOMAIN.owner.json
readonly OWNER_BACKUP_FILE=$OWNER_FILE-saved-$(date --iso-8601=minutes)
readonly NAME=${@:-missing}
[ ! "$NAME" == "missing" ]
}
backup-and-save-name() {
mv $OWNER_FILE $OWNER_BACKUP_FILE
jq ".name = \"$NAME\"" $OWNER_BACKUP_FILE > $OWNER_FILE
}
report-success() {
cat <<EOF
Owner's name changed to "$NAME"
Previous config is saved in ${OWNER_BACKUP_FILE##$PWD/}
EOF
}
main "$@"