Annotation of foxridge-archiver/changemany.sh, revision 1.3

1.1       casties     1: #!/bin/bash
                      2: 
1.2       casties     3: VERSION="changemany V0.2 (11.12.2006 ROC)"
1.1       casties     4: 
                      5: #set -x
                      6: 
                      7: if [ -z "$1$2" ]
                      8: then
                      9:     echo $VERSION
1.2       casties    10:     echo "use: $0 dirlist [-debug] [-dry-run] [-long] [params...]"
1.1       casties    11:     echo "  Changes the document directories given in the file dirlist."
                     12:     echo "  The list has the full pathname first and then one column per parameter, separated with spaces."
1.2       casties    13:     echo "    -debug: is passed to changemeta script"
                     14:     echo "    -dry-run: only print out script calls"
                     15:     echo "    -long: pass only one parameter but its value can contain spaces"
1.1       casties    16:     exit 1
                     17: fi
                     18: 
                     19: DIRLIST="$1"
1.2       casties    20: if [ "$2" == "-debug" ]
                     21: then
                     22:     shift
                     23:     DEBUG="-debug"
                     24: fi
                     25: if [ "$2" == "-dry-run" ]
                     26: then
                     27:     shift
                     28:     DRY_RUN=1
                     29: fi
                     30: if [ "$2" == "-long" ]
                     31: then
                     32:     shift
                     33:     LONG=1
                     34: fi
1.1       casties    35: PARAM1="$2"
                     36: PARAM2="$3"
                     37: PARAM3="$4"
                     38: 
                     39: if [ ! -f $DIRLIST ]
                     40: then
                     41:     echo "ERROR: directory list file $DIRLIST not found!"
                     42:     exit 1
                     43: fi
                     44: 
                     45: CNT=0
                     46: 
1.2       casties    47: if [ -z $LONG ]
                     48: then
                     49: # short options
                     50:     # read directories and options from DIRLIST
                     51:     while read DIR OPT1 OPT2 OPT3
                     52:     do
                     53:         CNT=$(( $CNT + 1 ))
                     54:         if [ -d "$DIR" ]
                     55:         then
                     56:        echo "changing document $CNT: $DIR..."
                     57:             if [ -n "$DRY_RUN" ]
                     58:             then
                     59:                 echo "/usr/local/mpiwg/archive/changemeta ${PARAM1:+$PARAM1=$OPT1} ${PARAM2:+$PARAM2=$OPT2} ${PARAM3:+$PARAM3=$OPT3} $DEBUG $DIR"
                     60:                 echo "  FAKED"
                     61:             else
                     62:            if /usr/local/mpiwg/archive/changemeta "${PARAM1:+$PARAM1=$OPT1}" "${PARAM2:+$PARAM2=$OPT2}" "${PARAM3:+$PARAM3=$OPT3}" "$DEBUG" "$DIR"
                     63:            then
                     64:                echo "  OK"
                     65:            else
                     66:                echo "FAILED!"
                     67:                # abort?
                     68:            fi
                     69:             fi
                     70:         else
                     71:        echo "$CNT ERROR: document directory $DIR not found!"
                     72:         fi
                     73:     done < $DIRLIST
                     74: else
                     75: # long option
                     76:     # read directories and options from DIRLIST
                     77:     while read DIR OPT
                     78:     do
                     79:         CNT=$(( $CNT + 1 ))
                     80:         if [ -d "$DIR" ]
                     81:         then
                     82:        echo "changing document $CNT: $DIR..."
                     83:             if [ -n "$DRY_RUN" ]
                     84:             then
                     85:                 echo "/usr/local/mpiwg/archive/changemeta ${PARAM1:+$PARAM1=$OPT} $DEBUG $DIR"
                     86:                 echo "  FAKED"
                     87:             else
1.3     ! casties    88:            if /usr/local/mpiwg/archive/changemeta "${PARAM1:+$PARAM1=$OPT}" "$DEBUG" "$DIR"
1.2       casties    89:            then 
                     90:                echo "  OK"
                     91:            else
                     92:                echo "FAILED!"
                     93:                # abort?
                     94:            fi
                     95:             fi
                     96:         else
                     97:        echo "$CNT ERROR: document directory $DIR not found!"
                     98:         fi
                     99:     done < $DIRLIST
                    100: fi
1.1       casties   101: 
                    102: if [ $CNT = 0 ]
                    103: then
                    104:     echo "ERROR: the list file $DIRLIST seems to be empty!"
                    105: else
                    106:     echo "Processed $CNT documents!"
                    107: fi

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>