Separate in-development source files

Stored experimental in-development source files within the dev
    subdirectory of the project, to make it easier for end-users to
    know which shell scripts are ready for use.
This commit is contained in:
Lee Ockert
2023-10-18 17:49:01 -04:00
parent 1ae26c20b8
commit c4b6bd13e1
2 changed files with 102 additions and 0 deletions

102
dev/dirtimefix.sh Executable file
View File

@ -0,0 +1,102 @@
#!/usr/bin/env bash
# DIRECTORY TIME FIX
#
# Copyright (c) 2023 Joshua Lee Ockert <torstenvl@gmail.com>
#
# THIS WORK IS PROVIDED "AS IS" WITH NO WARRANTY OF ANY KIND. THE IMPLIED
# WARRANTIES OF MERCHANTABILITY, FITNESS, NON-INFRINGEMENT, AND TITLE ARE
# EXPRESSLY DISCLAIMED. NO AUTHOR SHALL BE LIABLE UNDER ANY THEORY OF LAW
# FOR ANY DAMAGES OF ANY KIND RESULTING FROM THE USE OF THIS WORK.
#
# Permission to use, copy, modify, and/or distribute this work for any
# purpose is hereby granted, provided this notice appears in all copies.
############################################################################
## FUNCTION TO PRINT USAGE INSTRUCTIONS ##
############################################################################
printusage() {
echo "
DIRECTORY TIME FIX
USAGE
dirtimefix.sh [--execute] <topdir> <minutes>
DESCRIPTION
For each directory in <topdir> with a modification time within the past
<minutes> minutes, reset its modification time (via touch -r) to match
the newest file it contains.
OPTIONS
--execute Actually reset modification times. By default, this program
runs in test mode.
"
}
############################################################################
## PARSE & MAKE SENSE OF COMMAND LINE ##
############################################################################
# CHECK FOR THE EXECUTE FLAG (DEFAULT IS TESTING-ONLY MODE)
REALLYRUN=0
if [ "${1}" == "--execute" ]; then
REALLYRUN=1
shift
fi
EMTPYDIRS=""
# MAKE SURE WE HAVE THE RIGHT NUMBER OF ARGUMENTS AND THEY'RE VALID
if [ ! $# -eq 2 ]; then
echo && echo "Wrong number of arguments!" && printusage && exit
else
topdir=$1
minutes=$2
if [ ! -d "${topdir}" ]; then
echo && echo "${topdir} is not a directory!" && printusage && exit
elif [[ ! "${minutes}" =~ ^[0-9]+$ ]]; then
echo && echo "${minutes} is not a whole number of minutes!" && printusage && exit
fi
fi
############################################################################
## ADJUST MODIFICATION TIMES (OR NOT) ##
############################################################################
echo find "${topdir}" -type d -mtime -"${minutes}"m -d
find "${topdir}" -type d -mtime -"${minutes}"m -d -print0 | while read -d $'\0' moddir
do
srchdir="${moddir}"
newest=$(find "${srchdir}" \( -type d -or -type f \) -mtime +"${minutes}"m -mindepth 1 -maxdepth 1 -exec ls -td {} + | head -1)
if [ "${newest}" == "" ]; then
newest=$(find "${srchdir}/.." \( -type d -or -type f \) -mtime +"${minutes}"m -mindepth 1 -maxdepth 1 -exec ls -td {} + | head -1)
if [ "${newest}" == "" ]; then
newest=$(find "${srchdir}/../.." \( -type d -or -type f \) -mtime +"${minutes}"m -mindepth 1 -maxdepth 1 -exec ls -td {} + | head -1)
if [ "${newest}" == "" ]; then
newest=$(find "${srchdir}/../../.." \( -type d -or -type f \) -mtime +"${minutes}"m -mindepth 1 -maxdepth 1 -exec ls -td {} + | head -1)
if [ "${newest}" == "" ]; then
newest=$(find "${srchdir}/../../../.." \( -type d -or -type f \) -mtime +"${minutes}"m -mindepth 1 -maxdepth 1 -exec ls -td {} + | head -1)
if [ "${newest}" == "" ]; then
echo "EMPTY DIR AT ${moddir}! Could not find a file to borrow mtime from!"
fi
fi
fi
fi
fi
if [ ! "${newest}" == "" ]; then
if [ $REALLYRUN -gt 0 ]; then
echo "Setting mtime of \"${moddir}\" to mtime of \"${newest}\""
touch -r "${newest}" "${moddir}"
else
echo "NOT setting mtime of \"${moddir}\" to mtime of \"${newest}\""
fi
fi
done
exit

40
dev/tmdiskenum.sh Executable file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env bash
function storebackupdrivelist() {
# Search for external drives
local ext_drv_srch=`diskutil list | grep external`
local ext_drv_list=`diskutil list | grep external | sed 's/.*\(disk[0-9][0-9]*\).*/\1/g'`
# Then, for each one...
for drivename in $ext_drv_list; do
# Get the HFS partitions
local ext_hfs_ptns=`diskutil list ${drivename} | grep "Apple_HFS" | grep "${drivename}" | cut -w -f7`
# And get their volume names, mount points, and mount status
for partitionname in $ext_hfs_ptns; do
local volumename=`diskutil info /dev/${partitionname} | grep "Volume Name:" | cut -w -f4`
local mountpoint=`diskutil info /dev/${partitionname} | grep "Mount Point:" | cut -w -f4`
if [ mountpoint == "" ]; then
mountpoint="(none)"
local mountstatus="NO"
else
local mountstatus="YES"
fi
if [ ${#drives[@]} -eq 0 ]; then
drives=("${partitionname}")
else
drives=("${drives[@]}","${partitionname}")
fi
drives=("${drives[@]}","${volumename}")
drives=("${drives[@]}","${mountstatus}")
drives=("${drives[@]}","${mountpoint}")
drives=("${drives[@]}","EOL")
done
done
}
declare -a drives
storebackupdrivelist drives
echo "drives = ${drives}"