Martin v. Löwis | 73e6187 | 2002-03-18 08:56:23 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Christian Reis <kiko@async.com.br> |
| 4 | # |
| 5 | # Moves |
| 6 | # |
| 7 | # Example: |
| 8 | # |
| 9 | # blackjesus:~> ./move-faqwiz.sh 2\.1 3\.2 |
| 10 | # Moving FAQ question 02.001 to 03.002 |
| 11 | |
| 12 | if [ x$2 == x ]; then |
| 13 | echo "Need 2 args: original_version final_version." |
| 14 | exit 2 |
| 15 | fi |
| 16 | |
| 17 | if [ ! -d data -o ! -d data/RCS ]; then |
| 18 | echo "Run this inside the faqwiz data/ directory's parent dir." |
| 19 | exit 2 |
| 20 | fi |
| 21 | |
| 22 | function cut_n_pad() { |
| 23 | t=`echo $1 | cut -d. -f $2` |
| 24 | export $3=`echo $t | awk "{ tmp = \\$0; l = length(tmp); for (i = 0; i < $2-l+1; i++) { tmp = "0".tmp } print tmp }"` |
| 25 | } |
| 26 | |
| 27 | cut_n_pad $1 1 prefix1 |
| 28 | cut_n_pad $1 2 suffix1 |
| 29 | cut_n_pad $2 1 prefix2 |
| 30 | cut_n_pad $2 2 suffix2 |
| 31 | tmpfile=tmp$RANDOM.tmp |
| 32 | file1=faq$prefix1.$suffix1.htp |
| 33 | file2=faq$prefix2.$suffix2.htp |
| 34 | |
| 35 | echo "Moving FAQ question $prefix1.$suffix1 to $prefix2.$suffix2" |
| 36 | |
| 37 | sed -e "s/$1\./$2\./g" data/$file1 > ${tmpfile}1 |
| 38 | sed -e "s/$1\./$2\./g" data/RCS/$file1,v > ${tmpfile}2 |
| 39 | |
| 40 | if [ -f data/$file2 ]; then |
| 41 | echo "Target FAQ exists. Won't clobber." |
| 42 | exit 2 |
| 43 | fi |
| 44 | |
| 45 | mv ${tmpfile}1 data/$file2 |
| 46 | mv ${tmpfile}2 data/RCS/$file2,v |
| 47 | mv data/$file1 data/$file1.orig |
| 48 | mv data/RCS/$file1,v data/RCS/$file1,v.orig |
| 49 | |