From f3fa1a955fbc5a3e6bc97bbacd4b27e908cd7701 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Tue, 30 Mar 2021 06:50:06 +0200 Subject: more readme in comments, support -cron-suffix for cron --- htmpasswd | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/htmpasswd b/htmpasswd index 9aff7b7..ab5548c 100755 --- a/htmpasswd +++ b/htmpasswd @@ -3,6 +3,19 @@ # made by Dennis Eriksen in 2021 # # This script helps create temporary users for htpasswd-files +# +# README +# +# Alright. So, this script goes in your $PATH, and in one of your cron-folders. +# Personally I prefer /etc/cron.daily, but if you want more than daily +# precicion on retracting temporary access, you should probably use +# /etc/cron.hourly (for hourly precicion) or /etc/cron.d. +# +# This script uses the environmental variable $RUN_BY_CRON to recognize that it +# is being run by cron. I set this variable to true in /etc/crontab. You can +# also symlink this script to your cron-folder, and name the symlink with the +# suffix "-cron". +# # Exit on error. Append "|| true" if you expect an error. set -o errexit @@ -10,7 +23,8 @@ set -o errexit set -o errtrace # Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR set -o nounset -set -x +# set -x if the DEBUG-environmental is true +if ${DEBUG:-false}; then set -x; fi # Directory where htpasswd-files are stored HTDIR=/etc/nginx/htpasswd @@ -21,7 +35,7 @@ SPOOLDIR=/var/spool/htmpasswd # Temporary time, with minute precicion # Must be valid with `date` # Check by doing `date --date "$TIME"` -TIME="+60 minutes" +TIME="+1 day" USER_LENGTH=6 PASS_LENGTH=6 @@ -123,7 +137,7 @@ checkrw "${HTDIR}" checkrw "${SPOOLDIR}" # Run -if ${RUN_BY_CRON:-false}; then +if ${RUN_BY_CRON:-false} || [[ "${0}" =~ .*"-cron" ]]; then cronrun else main "$@" -- cgit v1.2.3