1
0
mirror of synced 2026-01-26 12:21:52 +00:00

WIP updating loadups scripts

This commit is contained in:
Frank Halasz
2023-08-01 12:08:55 -07:00
parent d2102bfe9b
commit 656bb53ef6
16 changed files with 80 additions and 47 deletions

View File

@@ -4,6 +4,13 @@
# could extend with -r or copying multiple files
# could change from cp to ln
ln_or_cp () {
f=$(df $(dirname $1) | tail -1 | awk '{ print $1 }')
d=$(df $(dirname $2) | tail -1 | awk '{ print $1 }')
if [ "$f" != "$d" ]; then cmd="cp -p"; else cmd="ln"; fi
echo $cmd
}
file="$1"
dest="$2"
@@ -18,9 +25,15 @@ if [ -d "$dest" ]; then
dest=$dest/`basename $file`
fi
# if (the new) $dest is a directory, then just bail
if [ -d "$dest" ]; then
echo "Error: destination file ($dest) is a directory. Exiting."
exit 1
fi
# if no such file $dest then just copy
if [ ! -f "$dest" ]; then
ln $file $dest #WAS cp -p $file $dest
$(ln_or_cp $file $dest) $file $dest
exit 0
fi
@@ -41,7 +54,7 @@ if [ $max -eq 0 ]; then # no current versions
new=2
else
if cmp -q $dest $dest.~$max~ >/dev/null 2>&1
then # they're different
then # they're different
max=`expr $max + 1` # make newer version
mv $dest $dest.~$max~
new=`expr $max + 1`
@@ -51,11 +64,8 @@ else
fi
fi
# make new version
# make new version and link it
ln $file $dest.~$new~ # cp -p $file $dest.~$new~
ln $dest.~$new~ $dest # and link it
$(ln_or_cp $file $dest.~new~) $file $dest.~$new~
rm -f $dest
ln $dest.~$new~ $dest