summaryrefslogtreecommitdiff
path: root/atom
diff options
context:
space:
mode:
authorBill <bill@billserver.senders.io>2021-03-21 14:19:26 -0400
committerBill <bill@billserver.senders.io>2021-03-21 14:19:26 -0400
commit904930043b2c60b236cc19becdb2642ce01b3fbb (patch)
treefe71d8819c1be53a450dc6c53dfddbc9a75e943c /atom
parentff902ff165e1087d3d10a45abd10dbc95b2a2211 (diff)
03/20 and 03/21 gemlogs + tstool
Gluon made a tool to amend files "without" changing their temporal info. So that could be useful.
Diffstat (limited to 'atom')
-rwxr-xr-xatom/tstool.sh50
1 files changed, 50 insertions, 0 deletions
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