stage/uninstall.sh
changeset 3 859eeb3579b2
child 4 c6c431cf0a89
equal deleted inserted replaced
2:7dddb5fb1595 3:859eeb3579b2
       
     1 #!/bin/bash
       
     2 
       
     3 read -p "Really uninstall Enano including database and config? (type uppercase yes): " confirm
       
     4 if test "$confirm" != "YES"; then
       
     5 	echo "Uninstallation aborted."
       
     6 	exit 1
       
     7 fi
       
     8 
       
     9 bitnami=`dirname $0`/../..
       
    10 
       
    11 while true; do
       
    12 	read -s -p "MySQL root password: " mysqlpass
       
    13 	echo ""
       
    14 	out=`$bitnami/mysql/bin/mysqladmin -u root --password="$mysqlpass" ping 2>&1`
       
    15 	test "$out" = "mysqld is alive" && break
       
    16 	echo $out
       
    17 done
       
    18 
       
    19 echo "Removing Enano from Apache configuration."
       
    20 cat $bitnami/apache2/conf/httpd.conf | grep -F -v apps/enanocms/conf/ > $bitnami/apache2/conf/httpd.conf.new || exit 1
       
    21 mv $bitnami/apache2/conf/httpd.conf $bitnami/apache2/conf/httpd.conf.bak.enanocms-uninstall || exit 1
       
    22 mv $bitnami/apache2/conf/httpd.conf.new $bitnami/apache2/conf/httpd.conf || exit 1
       
    23 
       
    24 $bitnami/ctlscript.sh restart apache
       
    25 
       
    26 echo "Uninstalling database."
       
    27 echo 'DROP DATABASE bn_enanocms; DROP USER bn_enanocms@localhost;' | $bitnami/mysql/bin/mysql -u root --password="${mysqlpass}" || exit 1
       
    28 
       
    29 echo "Removing Enano from applications.html."
       
    30 marker='BitNami Enano CMS Module enanocms'
       
    31 startline=`cat $bitnami/apache2/htdocs/applications.html | grep -n "START $marker" | cut -d: -f1`
       
    32 endline=`cat $bitnami/apache2/htdocs/applications.html | grep -n "END $marker" | cut -d: -f1`
       
    33 nlines=`cat $bitnami/apache2/htdocs/applications.html | wc -l`
       
    34 # sanity check...
       
    35 if test $startline -gt 0 -a $endline -gt 0 -a $endline -gt $startline -a $nlines -gt $endline ; then
       
    36 	cat $bitnami/apache2/htdocs/applications.html | head -n$(($startline - 1)) > $bitnami/apache2/htdocs/applications.html.new
       
    37 	cat $bitnami/apache2/htdocs/applications.html | tail -n$(($nlines - $endline)) >> $bitnami/apache2/htdocs/applications.html.new
       
    38 	mv $bitnami/apache2/htdocs/applications.html $bitnami/apache2/htdocs/applications.html.bak.enanocms-uninstall || exit 1
       
    39 	mv $bitnami/apache2/htdocs/applications.html.new $bitnami/apache2/htdocs/applications.html
       
    40 fi
       
    41 
       
    42 echo "Removing app directory."
       
    43 cd $bitnami || exit 1
       
    44 cp apps/enanocms/uninstall.sh ./ || exit 1
       
    45 rm -rf apps/enanocms/ || exit 1
       
    46