]> granicus.if.org Git - postgis/commitdiff
Additional work to remove DROP FUNCTION statements depending upon prior DROP TYPE...
authorBborie Park <bkpark at ucdavis.edu>
Sat, 24 Dec 2011 02:51:02 +0000 (02:51 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Sat, 24 Dec 2011 02:51:02 +0000 (02:51 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8538 b70326c6-7e19-0410-871a-916f4a2858ee

utils/uninstall_script

index 8a2d5332f4a0fe57867cb6bc76f6ff6b82df1fb8..78b147ba9b0c8b50cf0e3d95749091a704cf1243 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# this script assumes that it is located in utils
+# this script will change it's current working directory to utils
 
 DB=postgis_uninstall
 
@@ -15,12 +15,13 @@ else
        OUTFILE=$PGFILE
 fi
 INFILE=$OUTFILE.in.$RANDOM
-RAND=$RANDOM
+RAND1=$RANDOM
+RAND2=$RANDOM
 
 RTN=0
 
 cleanup () {
-       rm -f $INFILE $OUTFILE.$RAND
+       rm -f $INFILE $OUTFILE.$RAND1 $OUTFILE.$RAND2
 }
 
 # get reference uninstall of postgis.sql only
@@ -62,7 +63,7 @@ for x in $schema; do
 done
 
 # remove SET statements, remove schema names from DROP statements and add IF EXISTS for DROP statements
-grep -v -E "^SET" < $INFILE | eval "sed ${sedarg}" > $OUTFILE.$RAND
+grep -v -E "^SET" < $INFILE | eval "sed ${sedarg}" > $OUTFILE.$RAND1
 RTN=$?
 
 if [ "$RTN" != "0" ]; then
@@ -70,6 +71,33 @@ if [ "$RTN" != "0" ]; then
        exit $RTN
 fi
 
+kw=""
+OIFS=$IFS
+IFS=$'\n'
+echo -n '' > $OUTFILE.$RAND2
+for x in `cat $OUTFILE.$RAND1`; do
+       y=`echo "$x" | grep "CASCADE;\$"`
+       # CASCADE found, get keyword
+       if [ "x$y" != "x" ]; then
+               kw=`echo "$x" | sed -e 's/^DROP TYPE IF EXISTS //' -e 's/ CASCADE;//'`
+               echo "$x" >> $OUTFILE.$RAND2
+               continue
+       fi
+
+       # no keyword, continue
+       if [ "x$kw" == "x" ]; then
+               echo "$x" >> $OUTFILE.$RAND2
+               continue
+       fi
+
+       y=`echo "$x" | grep "($kw)"`
+       if [ "x$y" == "x" ]; then
+               echo "$x" >> $OUTFILE.$RAND2
+               continue
+       fi
+done
+IFS=$OIFS
+
 # if raster, separate raster from postgis items
 if [ "raster" == "$1" ]; then
        OIFS=$IFS
@@ -78,7 +106,7 @@ if [ "raster" == "$1" ]; then
        echo -n '' > ${RTPATH}$OUTFILE
 
        # see if line found in uninstall_postgis.sql
-       for x in `cat $OUTFILE.$RAND`; do
+       for x in `cat $OUTFILE.$RAND2`; do
                y=`echo $x | sed -e 's/\(\[\|\]\)/\\\&/g'`
                y=`grep "^${y}$" < ${PGPATH}$PGFILE`
 
@@ -90,7 +118,7 @@ if [ "raster" == "$1" ]; then
 
        IFS=$OIFS
 else
-       mv $OUTFILE.$RAND ${PGPATH}${OUTFILE}
+       mv $OUTFILE.$RAND2 ${PGPATH}${OUTFILE}
 fi
 
 # cleanup