Airfest 2013: Bdale's new airframe on Loki M with TMv1 and Tmega
[fw/tmflights] / fixeeprom
1 #!/bin/sh
2 for i in "$@"; do
3     num=`grep '^F' "$i" | awk '{printf ("%03d\n", strtonum("0x" $4))}'`
4     case "$num" in
5         "")
6         echo "$i: no flight number found" 1>&2
7         ;;
8         *)
9         newname=`echo "$i" | sed 's/flight-[0-9][0-9][0-9]/flight-'"$num"'/'`
10         echo $num "$i" "$newname"
11         ;;
12     esac
13 done | sort -rn | sed 's/^[0-9][0-9]*//' | while read old new; do
14     if [ $new = $old ]; then
15         :
16     else
17         if [ -f $new ]; then
18             if cmp $new $old; then
19                 echo "$old is a duplicate of $new"
20                 rm $old
21             else
22                 echo "$old: $new already exists"
23             fi
24         else
25             echo mv $old $new
26         fi
27     fi
28 done