From 904930043b2c60b236cc19becdb2642ce01b3fbb Mon Sep 17 00:00:00 2001 From: Bill Date: Sun, 21 Mar 2021 14:19:26 -0400 Subject: 03/20 and 03/21 gemlogs + tstool Gluon made a tool to amend files "without" changing their temporal info. So that could be useful. --- atom/tstool.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 atom/tstool.sh (limited to 'atom') diff --git a/atom/tstool.sh b/atom/tstool.sh new file mode 100755 index 0000000..44ff515 --- /dev/null +++ b/atom/tstool.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +#FILES=$(ls *.gmi) +SAVE_EXTENSION='original_time' + +show_usage() { + echo "Usage: $0 OPTION FILE..." + echo "Save or restore the original timestamps of a collection of files." + echo + echo " save - save the original timestamps of files" + echo " restore - restore the original timestamps of files" + echo +} + +save_timestamps() { + for file in "$@" + do + touch -amr $file $file.$SAVE_EXTENSION + echo "$file timestamps saved to $file.$SAVE_EXTENSION" + done +} + +restore_timestamps() { + ls *.$SAVE_EXTENSION > /dev/null 2>&1 + if [[ $? -gt 0 ]]; then + echo "error: could not find stored timestamps" + exit 1 + fi + for file in $(ls *.$SAVE_EXTENSION) + do + if [[ ${file::-$((${#SAVE_EXTENSION} + 1))} -nt $file ]]; then + touch -amr $file ${file::-$((${#SAVE_EXTENSION} + 1))} + echo "${file::-$((${#SAVE_EXTENSION} + 1))} timestamps restored from $file" + fi + rm $file + done +} + +if [[ -z $1 || -z $2 ]]; then + show_usage +else + if [[ $1 == "save" ]]; then + shift + save_timestamps "$@" + elif [[ $1 == "restore" ]]; then + restore_timestamps + else + show_usage + fi +fi -- cgit v1.2.3-54-g00ecf