diff --git a/checksum_file.sh b/checksum_file.sh index 93d6d50..bda0e0c 100755 --- a/checksum_file.sh +++ b/checksum_file.sh @@ -13,7 +13,11 @@ # systems, as older shells may not understand command substitution # with parentheses, as required by POSIX. # NetBSD: cksum & {g,s}etextattr, should be included in src. -# OpenBSD: No extended attribute support since July 2005 (commit 9dd8235) +# OpenBSD: No extended attribute support since July 2005: +# > https://github.com/openbsd/src/commit/9dd8235" +# > Extended Attributes was a piece to get to ACLs, however ACLs have +# > not been worked on, so EA is pointless. Also the code is not enabled +# > in GENERIC so it is not being tested or maintained. # # Each operating system has its own routines for setting/getting EAs and also # for calculating checksums. The only hardcoded value is the digest algorithm @@ -26,22 +30,25 @@ # - Or rewrite this whole thing in Python, for portability's sake? (hashlib, os/xattr) # DIGEST="md5" # md5, sha1, sha256, sha512 + PROG=$(basename "$0") # Adjust if needed PATH=/bin:/usr/bin:/sbin:/usr/local/bin:/opt/local/bin:/opt/csw/bin:/usr/sfw/bin print_usage() { - echo "Usage: $(basename "$0") [get] [file]" - echo " $(basename "$0") [set] [file]" - echo " $(basename "$0") [get-set] [file]" - echo " $(basename "$0") [check-set] [file]" - echo " $(basename "$0") [check] [file]" - echo " $(basename "$0") [remove] [file]" - echo " $(basename "$0") [test]" - echo "" - echo " get-set - sets a new checksum if none is found, print checksum otherwise." - echo " check-set - sets a new checksum if none is found, verify checksum otherwise." +cat </dev/null | awk '/user.checksum/ {print $NF}' ;; - NetBSD) - getextattr -q user checksum.${DIGEST} "$1" - ;; - Linux) # NOTE: If the designated EA is not set, getfattr may not return a non-zero # exit code. This has been fixed upstream but may not have been picked up @@ -155,12 +158,16 @@ case ${OS} in getfattr --only-values --name user.checksum.${DIGEST} -- "$1" 2>/dev/null | awk '/[a-z0-9]/ {print $1}' ;; + NetBSD) + getextattr -q user checksum.${DIGEST} "$1" + ;; + SunOS) runat "$1" cat user.checksum.${DIGEST} 2>/dev/null ;; *) - do_log "We don't support ${OS}, yet :-(" 1 + do_log "We don't support ${OS} :-(" 1 ;; esac } @@ -179,20 +186,20 @@ case ${OS} in pxattr -n user.checksum.${DIGEST} -v "${CHECKSUM_C}" "$1" ;; - NetBSD) - setextattr user checksum.${DIGEST} "${CHECKSUM_C}" "$1" - ;; - Linux) setfattr --name user.checksum.${DIGEST} --value "${CHECKSUM_C}" -- "$1" ;; + NetBSD) + setextattr user checksum.${DIGEST} "${CHECKSUM_C}" "$1" + ;; + SunOS) runat "$1" "echo ${CHECKSUM_C} > user.checksum.${DIGEST}" ;; *) - do_log "We don't support ${OS}, yet :-(" 1 + do_log "We don't support ${OS} :-(" 1 ;; esac } @@ -290,7 +297,7 @@ case ${ACTION} in ;; *) - do_log "We don't support ${OS}, yet :-(" 1 + do_log "We don't support ${OS} :-(" 1 ;; esac ;; diff --git a/rsnapshot/rsnapshot-rotate.sh b/rsnapshot/rsnapshot-rotate.sh index 669cc9f..139d555 100755 --- a/rsnapshot/rsnapshot-rotate.sh +++ b/rsnapshot/rsnapshot-rotate.sh @@ -6,32 +6,33 @@ CONF="/etc/rsnapshot" if [ ! $# = 1 ]; then - HOSTS=$(ls "$CONF"/rsnapshot-*.conf | sed 's/.*\/rsnapshot-//;s/\.conf//' | xargs echo | sed 's/ /|/g') - echo "Usage: $(basename "$0") [$HOSTS]" + HOSTS=$(find ${CONF} -maxdepth 1 -name "*.conf" | sed 's/.*\/rsnapshot-//;s/\.conf//' | xargs echo | sed 's/ /|/g') + echo "Usage: $(basename "$0") [${HOSTS}]" exit 1 else - CONF="$CONF"/rsnapshot-"$1".conf - DIR=$(awk '/^snapshot_root/ {print $2}' "$CONF") + CONF="${CONF}/rsnapshot-${1}.conf" + DIR="$(awk '/^snapshot_root/ {print $2}' "${CONF}")" - # Don't let rsnapshot-wrapper remount our backup store - WRAPPER_CONF="/usr/local/etc/rsnapshot-wrapper.conf" - NOMOUNT=$(awk -F= '/^NOMOUNT/ {print $2}' $WRAPPER_CONF) - touch "$NOMOUNT" - - [ -f "$CONF" ] || exit 2 - [ -d "$DIR" ] || exit 3 + # Safety belt + [ -f "${CONF}" ] || exit 2 + [ -d "${DIR}" ] || exit 3 fi -for i in daily weekly monthly; do - C=$(ls -d "$DIR"/"$i".* 2>/dev/null | wc -l) +set -e +# Don't let rsnapshot-wrapper remount our backup store while we are running. +NOMOUNT=$(awk -F= '/^NOMOUNT/ {print $2}' /usr/local/etc/rsnapshot-wrapper.conf) +touch "${NOMOUNT}" + +for interval in daily weekly monthly; do + COUNT=$(find "${DIR}"/${interval}.[0-9] -maxdepth 0 2>/dev/null | wc -l) j=0 - while [ $j -le "$C" ]; do - echo "("$j"/"$C") rsnapshot -c "$CONF" "$i"..." - rsnapshot -c "$CONF" "$i" + while [ "${j}" -le "${COUNT}" ]; do + echo "(${j}/${COUNT}) rsnapshot -c ${CONF} ${interval}..." + rsnapshot -c "${CONF}" "${interval}" j=$((j+1)) done done # Since this is not a normal operation and may take a long time, we will # remove the NOMOUNT flag again, otherwise we may forget to remove it. -rm -f "$NOMOUNT" +rm -f "${NOMOUNT}" diff --git a/ternet/flop.sh b/ternet/flop.sh index b2430ea..4a7b456 100755 --- a/ternet/flop.sh +++ b/ternet/flop.sh @@ -5,15 +5,17 @@ # https://web.archive.org/web/20170702162404/http://www.breakingsystemsforfunandprofit.com/the-lolcats-they-are-everywhere/ # DIR=/var/www/ternet -while read URL; do + +while read -r URL; do SURL=$(echo "${URL}" | cut -d" " -f1) - echo "${SURL}" | egrep -qi "\.(jp(e)?g|gif|png|tiff|bmp|ico)$" && - ( - umask 002 - PIC=$$-${RANDOM} - wget -q -O ${DIR}/${PIC}.tmp "${SURL}" - convert -quiet ${DIR}/${PIC}.tmp -flop ${DIR}/${PIC}.png - rm -f ${DIR}/${PIC}.tmp - echo http://127.0.0.1/ternet/${PIC}.png - ) || echo "$URL" + if echo "${SURL}" | grep -Eqi "\.(jp(e)?g|gif|png|tiff|bmp|ico)$"; then + umask 002 + PIC=$$-${RANDOM} + wget -q -O ${DIR}/${PIC}.tmp "${SURL}" + convert -quiet ${DIR}/${PIC}.tmp -flop ${DIR}/${PIC}.png + rm -f ${DIR}/${PIC}.tmp + echo http://127.0.0.1/ternet/${PIC}.png + else + echo "${URL}" + fi done diff --git a/vbox-sysrq.sh b/vbox-sysrq.sh index f175594..9407e14 100755 --- a/vbox-sysrq.sh +++ b/vbox-sysrq.sh @@ -16,9 +16,6 @@ # Keyboard scancodes: Ordinary scancodes # https://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html#ss1.4 # -# Re: Magic sysrq on Linux guest, under a Linux host -# https://forums.virtualbox.org/viewtopic.php?f=6&t=10400#p207674 -# # Use Magic Sysrq-key in guest # https://www.halfdog.net/Misc/TipsAndTricks/VirtualBox.html#MagicSysrq # @@ -64,8 +61,8 @@ if [ -n "$PRESS" ]; then VBoxManage controlvm "$VM" keyboardputscancode 1d 38 54 "$PRESS" "$RELEASE" d4 b8 9d else echo - echo "Unknown sysrq key! ("${SYSRQ}")" - egrep '^.\|' "$0" + echo "Unknown sysrq key! (${SYSRQ})" + grep -E '^.\|' "$0" echo exit 1 fi