Compare commits

..

No commits in common. "8349b685f1133ef3ecbccea69f6c7b5141ea088c" and "ccbfd962427bca3a402a4dd581e62dab30a34738" have entirely different histories.

2 changed files with 27 additions and 43 deletions

View file

@ -26,9 +26,6 @@ notify() {
return 0 return 0
} }
# Logs are only for root.
umask 027
# Only run for the configured mirroring user. # Only run for the configured mirroring user.
[[ "$(whoami)" != "$MIRRORING_USER" ]] && { [[ "$(whoami)" != "$MIRRORING_USER" ]] && {
printf "%s: %s\\n" "${0##*/}" "must be run by the '$MIRRORING_USER' user - use su to run manually" >&2 printf "%s: %s\\n" "${0##*/}" "must be run by the '$MIRRORING_USER' user - use su to run manually" >&2
@ -63,6 +60,9 @@ if [[ "$FLOCK" != "$0" ]]; then
fi fi
fi fi
# Logs are only for root.
umask 027
# Drop the caches as sometimes old user/groups are cached. # Drop the caches as sometimes old user/groups are cached.
sudo /opt/sbin/drop-caches sudo /opt/sbin/drop-caches
@ -76,7 +76,7 @@ if [[ -n "$WRONG_PERMS" ]]; then
else else
# Do the mirroring work. # Do the mirroring work.
export MIRRORING_USER export MIRRORING_USER
sg "$DEPOSITORY_GROUP" -c "$COMMAND $@" >"$LOGSDIR/$LOGFILE" 2>&1 sg "$DEPOSITORY_GROUP" -c "$COMMAND" "$@" >"$LOGSDIR/$LOGFILE" 2>&1
ERR="$?" ERR="$?"
fi fi

View file

@ -3,9 +3,6 @@
# Configuration. # Configuration.
COMMAND="/opt/bin/sbosrcarch" COMMAND="/opt/bin/sbosrcarch"
DEPOSITORY="/data/depository/sbosrcarch"
SBOSRCARCH_USER="sbosrcarch"
DEPOSITORY_GROUP="depository"
LOGSDIR="/var/log/duplication/sbosrcarch/$(printf "%(%Y/%m)T")" LOGSDIR="/var/log/duplication/sbosrcarch/$(printf "%(%Y/%m)T")"
LOGFILE="$(printf "%(%Y%m%d-%H%M%S)T")-$$" LOGFILE="$(printf "%(%Y%m%d-%H%M%S)T")-$$"
# Where from/to to send emails. Comment for no emailing. # Where from/to to send emails. Comment for no emailing.
@ -25,25 +22,9 @@ notify() {
return 0 return 0
} }
# Logs are only for root. # Don't run as root!
umask 027 (( $(id -u) == 0 )) && {
printf "%s: %s\\n" "${0##*/}" "don't run me as root - it messes up permissions!" >&2
# Only run for the configured sbosrcarch user.
[[ "$(whoami)" != "$SBOSRCARCH_USER" ]] && {
printf "%s: %s\\n" "${0##*/}" "must be run by the '$SBOSRCARCH_USER' user - use su to run manually" >&2
exit 1
}
# Make sure the logs directory exists.
# shellcheck disable=SC2174
mkdir -p -m 750 "$LOGSDIR" 2>/dev/null || {
printf "%s: %s\\n" "${0##*/}" "Failed to create logs directory '$LOGSDIR'" >&2
exit 1
}
# Make sure the command to do the work is runnable.
[[ ! -x "$COMMAND" ]] && {
printf "%s: %s\\n" "${0##*/}" "'$COMMAND' is not executable" >&2
exit 1 exit 1
} }
@ -62,24 +43,27 @@ if [[ "$FLOCK" != "$0" ]]; then
fi fi
fi fi
# Drop the caches as sometimes old user/groups are cached. # Logs are only for root.
sudo /opt/sbin/drop-caches umask 027
# Make sure there's no errant ownerships. # Make sure the logs directory exists.
#WRONG_PERMS="$(find "$DEPOSITORY" \( \! -user "$SBOSRCARCH_USER" -o \! -group "$DEPOSITORY_GROUP" \) -a \! -path "$DEPOSITORY" -printf "%u:%g\t%P\n")" # shellcheck disable=SC2174
if [[ -n "$WRONG_PERMS" ]]; then mkdir -p -m 750 "$LOGSDIR" 2>/dev/null || {
printf "%s\\n" "This run has been aborted!" >"$LOGSDIR/$LOGFILE" printf "%s: %s\\n" "${0##*/}" "Failed to create logs directory '$LOGSDIR'" >&2
printf "%s\\n" "The following files in have errant permissions:" >>"$LOGSDIR/$LOGFILE" exit 1
printf "%s\\n" "$WRONG_PERMS" >>"$LOGSDIR/$LOGFILE" }
ERR=-1
else # Make sure the command to do the work is runnable.
# Do the sbosrcarch work. [[ ! -x "$COMMAND" ]] && {
sg "$DEPOSITORY_GROUP" -c "$COMMAND ${1:-update}" >"$LOGSDIR/$LOGFILE" 2>&1 printf "%s: %s\\n" "${0##*/}" "'$COMMAND' is not executable" >&2
ERR="$?" exit 1
printf "\\n" >>"$LOGSDIR/$LOGFILE" }
sg "$DEPOSITORY_GROUP" -c "$COMMAND status" >>"$LOGSDIR/$LOGFILE" 2>&1
(( ERR += $? )) # Do the sbosrcarch work.
fi "$COMMAND" "${@:-update}" >"$LOGSDIR/$LOGFILE" 2>&1
ERR="$?"
printf "\\n" >>"$LOGSDIR/$LOGFILE"
"$COMMAND" "status" >>"$LOGSDIR/$LOGFILE" 2>&1
# Tell the sysadmin what went on. # Tell the sysadmin what went on.
if (( "$ERR" == 0 )); then if (( "$ERR" == 0 )); then