Makefile: add pickrand
[cmccabe-bin] / archive_patch.sh
index 082f698..aebe780 100755 (executable)
@@ -20,12 +20,14 @@ usage() {
     echo "-c               copy the file rather than moving it"
     echo "-d <dir>         directory where the file should end up (default: .)"
     echo "-h               This help message"
+    echo "-m               Use the file's modification time, not the current time"
     echo
 }
 
 copy=0
 destdir=.
-while getopts  "cd:h" flag
+use_mtime=0
+while getopts  "cd:hm" flag
 do
     case $flag in
     c)  copy=1;;
@@ -36,6 +38,8 @@ do
         exit 1
         ;;
 
+    m)  use_mtime=1;;
+
     *) usage
         exit 1;;
     esac
@@ -54,6 +58,11 @@ for file in "$@"; do
     [ -e "$file" ] || die "'$file' does not exist"
 done
 for file in "$@"; do
-    new_file_name=$destdir/`date +'%Y-%m-%d'`_`basename $file`
+    if [ $use_mtime -eq 1 ]; then
+        new_date=`stat -c '%y' "${file}" | sed 's/ .*//'`
+        new_file_name="${destdir}/${new_date}_`basename "${file}"`"
+    else
+        new_file_name="$destdir/`date +'%Y-%m-%d'`_`basename "${file}"`"
+    fi
     $cmd "${file}" "${new_file_name}" || die "failed on $file"
 done