#!/bin/sh -x
# uploading due to a bug in the script
# %I was accidentally used instead of %H
# this means all time is 01-12 not 00-23
# so you can restore/fix the filenames
# manually by correcting for them using
# how this script performs updates

# GOOD LUCK!
file="$1"
if [ ! -f "$file" ]; then
	echo "file does not exist, you should run this like ls *.pcap|xargs -I {} ./fix.sh {}|sh"
	exit 1
fi
mts=$(stat -c %Y $file)
fdate=$(date -d "@$mts" +"wrccdc.%F.%H%M%S%N.pcap")
cnd=$(ls $fdate|wc -l)
if [ $cnd -ge 1 ]; then
	i=$(($cnd+1))
	echo "i have $cdn so I will have $i copies"
	tfdate=$(echo $fdate|sed -e "s/00.pcap/0$i.pcap/g")
	if [ -f "$tfdate" ]; then
		i=$(($i+1))
	fi
	fdate=$(echo $fdate|sed -e "s/00.pcap/0$i.pcap/g")
fi
mv -vn $file $fdate
if [ $? -ne 0 ]; then
	echo "$file $fdate" >> ~/failed-copy.txt
fi
echo "$file $fdate" >> ~/all-copy.txt

