Bugzilla – Attachment 12606 Details for
Bug 459
No uninstall script
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Revised untested non-patch file - Prevent package uninstalls now
file_459.txt (text/plain), 20.05 KB, created by
Mark Tompsett
on 2012-09-29 12:58:18 UTC
(
hide
)
Description:
Revised untested non-patch file - Prevent package uninstalls now
Filename:
MIME Type:
Creator:
Mark Tompsett
Created:
2012-09-29 12:58:18 UTC
Size:
20.05 KB
patch
obsolete
>#!/bin/bash > ># There are three ways to install: ># - tarball ># - git ># - packages ># So we need to figure out what type, where it was installed, and what to uninstall. > ># This script purposefully avoids attempts to uninstall packages. There are better ># ways to do that! > ># Provide a simple help, which all scripts which attempt to have! >function usage() { > echo "Usage: $0" > echo > echo "This script is intended to uninstall git and tarball installations." > echo "This script does not uninstall packages." > echo "There are no parameters. Any kind of parameters triggers this help." >} > ># This script doesn't take parameters, so if they put one, they need help. >if [ "$#" -ne "0" ]; then > usage > exit 1 >fi > ># Some people may attempt to run this with no parameters in an attempt to ># get the help. This is for those people. It also serves as a good prevention ># for the 'oops, I didn't mean to run that script!' case. >echo -n "Would you like to read the help first? (y/n) " >FLAG=1 >while [ "$FLAG" -eq "1" ]; do > read ANSWER > if [[ "${ANSWER:0:1}" =~ [YyNn] ]]; then > FLAG=0 > else > echo "You must purposefully type 'y' or 'n' (case insensitive)." > echo -n "Would you like to read the help first? (y/n) " > fi >done > >if [[ "${ANSWER:0:1}" =~ [Yy] ]]; then > usage > exit 0 >fi > ># Don't run this as a koha user! >if [[ "$USER" =~ "koha" ]]; then > echo "Do not run this script as a koha user." > exit 1 >fi > ># Check if they have access to dpkg -l >CHKGPKG=`dpkg -l` >if [ "$?" -ne "0" ]; then > echo "Unable to run 'dpkg -l'. Aborting!" > exit 1 >fi > >CHKPERL=`dpkg-query -W perl | wc -l` >RESULT=$? >if [[ "$RESULT" -ne "0" || "$CHKPERL" -eq "0" ]]; then > echo "There is an unexplainable lack of perl or wc. Aborting!" > exit 1 >fi > ># using mktemp to generate a temporary file for our XML_READ helper script. >CHKMKTEMP=`which mktemp` >if [[ "${#CHKMKTEMP}" -eq "0" || ! -e $CHKMKTEMP ]]; then > echo "Unable to find mktemp. Aborting!" > exit 1 >fi > ># The script uses perl, so it better exist. >PERL=`which perl` >if [[ "${#PERL}" -eq "0" || ! -e $PERL ]]; then > echo "Unable to find perl. Aborting!" > exit 1 >fi > ># Okay, let's go looking for /etc/koha ># packages and tarball installations have it. >PKG=0 >GIT=0 >TARBALL=0 >echo "/etc/koha is used by package or tarball installations, but not git." >echo -n "Looking for /etc/koha ... " >if [ -d /etc/koha ]; then > echo "FOUND" > > # Are we running packages? > PKG=`dpkg -l | grep koha-common | wc -l` > if [ "$?" -ne "0" ]; then > echo "Unable to determine if koha-common is installed or not." > fi > > echo "The packages use /etc/koha/sites/{instance}/ for each instance." > echo -n "Checking for a /etc/koha/sites directory... " > if [ -d /etc/koha/sites ]; then > echo "FOUND" > CHKPKG=`ls /etc/koha/sites 2> /dev/null | wc -l` > > if [[ "$PKG" -eq "1" && "$CHKPKG" -gt "0" ]]; then > echo > echo "This script does not remove package installations." > echo "Please consult the documentation about how to use" > echo "koha-list, koha-remove, and apt-get remove." > exit 1 > elif [ "$PKG" -eq "1" ]; then > echo > echo "This script does not remove package installations." > echo "Please consult the documentation about how to use" > echo "apt-get remove." > exit 1 > elif [ "$CHKPKG" -gt "0" ]; then > echo > echo "This script does not remove package installations." > echo "Please consult the documentation about how to uninstall." > echo "koha-common may have already been removed out of order." > exit 1 > else > TARBALL=1 > echo "Checking if \$KOHA_CONF is defined ... " > if [ "X$KOHA_CONF" == "X" ]; then > echo "UNDEFINED" > KOHA_CONF=`find /etc/koha -name "koha-conf.xml"` > echo "\$KOHA_CONF set to $KOHA_CONF" > else > echo "DEFINED" > echo "\$KOHA_CONF is already set to $KOHA_CONF" > fi > fi > elif [ "$PKG" -eq "1" ]; then > echo "NOT FOUND" > echo "Partially installed package installation detected." > echo > echo "This script does not remove package installations." > echo "Please consult the documentation about how to use" > echo "apt-get remove." > exit 1 > else > echo "NOT FOUND" > echo "No package installation detected. Assuming tarball installation." > echo -n "Checking if \$KOHA_CONF is defined ... " > if [ "X$KOHA_CONF" == "X" ]; then > echo "UNDEFINED" > echo -n "Looking for koha-conf.xml in /etc/koha ... " > KOHA_CONF=`find /etc/koha -name "koha-conf.xml"` > if [[ "$?" -eq "0" && "${#KOHA_CONF}" -gt "0" ]]; then > echo "FOUND" > echo "\$KOHA_CONF set to $KOHA_CONF" > else > echo "NOT FOUND" > echo "Unable to set \$KOHA_CONF. Aborting!" > exit 1 > fi > else > echo "DEFINED" > echo "\$KOHA_CONF is already set to $KOHA_CONF" > fi > TARBALL=1 > fi >else > echo "NOT FOUND" > echo "No /etc/koha detected. Assuming git or tarball installation." > > # No choice but to hunt home directory. > echo "Counting git and non-git directories in the home directory which have" > echo "a koha-conf.xml file in them or their subdirectories." > CHKCOUNT=0 > CHKGITCOUNT=0 > while read CHKDIR; do > echo -n "Checking $CHKDIR ... " > if [ -d $CHKDIR/.git ]; then > echo "GIT" > CHKGITCOUNT=$(($CHKGITCOUNT + 1)) > else > echo "NON-GIT" > CHKCOUNT=$(($CHKCOUNT + 1)) > fi > done < <(find ~ -name "koha-conf.xml" | cut -f1-4 -d"/" | sort -u) > > # chkgitcount=0 means it is more likely a tarball. > if [ "$CHKGITCOUNT" -eq "0" ]; then > echo "As there is no /etc/koha and no git directories, you likely have" > echo "a tarball installation. It may not even be installed yet." > echo -n "Checking for \$KOHA_CONF ... " > if [ "X$KOHA_CONF" == "X" ]; then > echo "UNDEFINED" > if [ "$CHKCOUNT" -eq "1" ]; then > echo "An unbuilt tarball needs no uninstall. Aborting!" > exit 1 > else > echo "ERROR: found $CHKCOUNT possible koha-conf.xml directories." > echo "Two copies are typical for a built, but not installed" > echo "tarball. Aborting!" > exit 1 > fi > else > echo "DEFINED" > echo -n "Checking if \$KOHA_CONF file exists... " > if [ ! -e $KOHA_CONF ]; then > echo "NON-EXISTANT" > echo "The tarball installation in not likely installed. Aborting!" > exit 1 > fi > echo "EXISTS" > echo "\$KOHA_CONF is already set to $KOHA_CONF. Continuing." > fi > TARBALL=1 > > # If chkgitcount>0 but chkcount=0, then likely an uninstalled git. > elif [ "$CHKCOUNT" -eq "0" ]; then > echo "As there is not /etc/koha, but there are git directories, and" > echo "there are no non-git home directories that contain koha-conf.xml," > echo "this is likely a git which has not been installed. Aborting!" > exit 1 > > # so chkgitcount>0 and chkcount>0 > else > if [ "$CHKGITCOUNT" -gt "1" ]; then > echo "WARNING: " > fi > echo "Found $CHKGITCOUNT possible git directories." > if [ "$CHKCOUNT" -gt "1" ]; then > echo "WARNING: " > fi > echo "Found $CHKCOUNT possible non-git directories." > > echo -n "Checking if \$KOHA_CONF is defined ... " > if [ "X$KOHA_CONF" == "X" ]; then > echo "UNDEFINED" > if [ "$CHKCOUNT" -eq "1" ]; then > while read CHKDIR; do > if [ ! -d $CHKDIR/.git ]; then > KOHA_CONF=`find $CHKDIR -name "koha-conf.xml"` > echo "\$KOHA_CONF set to $KOHA_CONF" > fi > done < <(find ~ -name "koha-conf.xml" | cut -f1-4 -d"/" | sort -u) > else > echo "There are $CHKCOUNT directories with koha-conf.xml files." > echo "Unble to determine how to uninstall this git installation." > echo "Aborting!" > exit 1 > fi > else > echo "DEFINED" > echo -n "Looking for \$KOHA_CONF file ... " > if [ ! -e $KOHA_CONF ]; then > echo "NOT FOUND" > echo "The git installation may be broken or complex. Aborting!" > exit 1 > fi > echo "FOUND" > echo "\$KOHA_CONF is already set to $KOHA_CONF. Continuing." > fi > GIT=1 > > # End of checking chkgitcount and chkcount > fi > ># End of checking for /etc/koha >fi > ># MUST HAVE $KOHA_CONF DEFINED! >if [ "X$KOHA_CONF" == "X" ]; then > echo "\$KOHA_CONF is not defined. Unable to uninstall." > exit 1 >fi > ># The general installation is based on MySQL, if they don't have MySQL, ># we'll abort. >MYSQL=`which mysql 2> /dev/null` >MYSQLDUMP=`which mysqldump 2> /dev/null` > >if [[ "${#MYSQL}" -eq "0" || ! -e $MYSQL ]]; then > echo "MySQL is not in an expected location. Aborting!" > exit 1 >fi > >if [[ "${#MYSQLDUMP}" -eq "0" || ! -e $MYSQLDUMP ]]; then > echo "MySQL dump is not in an expected location. Aborting!" > exit 1 >fi > ># Create a nice temporary script to read our XML configuration file. >XML_READ=`mktemp` >echo -n '#!' >> $XML_READ >echo $PERL >> $XML_READ >echo >> $XML_READ >echo "use XML::LibXML;" >> $XML_READ >echo >> $XML_READ >echo "my (\$parse," >> $XML_READ >echo " \$xmldoc," >> $XML_READ >echo " \$sample," >> $XML_READ >echo " );" >> $XML_READ >echo >> $XML_READ >echo "\$parse = XML::LibXML->new();" >> $XML_READ >echo "\$xmldoc = \$parse->parse_file(\"$KOHA_CONF\");" >> $XML_READ >echo "for \$sample (\$xmldoc->findnodes(\"\$ARGV[0]\")) {" >> $XML_READ >echo " print \$sample->textContent(),\"\\n\";" >> $XML_READ >echo "}" >> $XML_READ >chmod 755 $XML_READ > ># Where is the install log? >INSTALL_LOG=`$XML_READ yazgfs/config/install_log` >RESULT=$? >if [ "$RESULT" -ne "0" ]; then > echo "Unable to read $KOHA_CONF and determine yazgfs/config/install_log." > echo "Aborting!" > rm $XML_READ > exit 1 >fi >if [ ! -e $INSTALL_LOG ]; then > echo "The install log file ($INSTALL_LOG) does not exist. Aborting!" > rm $XML_READ > exit 1 >fi > >KOHA_USER=`grep KOHA_USER $INSTALL_LOG | cut -f2 -d'='` >CHKUSER=`grep $KOHA_USER /etc/passwd` >if [ "$CHKUSER" -ne "0" ]; then > echo "Koha user ($KOHA_USER) not found. Aborting!" > rm $XML_READ > exit 1 >fi > ># Grab the database user name >DB_USER=`$XML_READ yazgfs/config/user` >RESULT=$? >if [ "$RESULT" -ne "0" ]; then > echo "Unable to read $KOHA_CONF and determine yazgfs/config/user. Aborting!" > rm $XML_READ > exit 1 >fi > ># Grab the database password >DB_PASS=`$XML_READ yazgfs/config/pass` >RESULT=$? >if [ "$RESULT" -ne "0" ]; then > echo "Unable to read $KOHA_CONF and determine yazgfs/config/pass. Aborting!" > rm $XML_READ > exit 1 >fi > ># Grab the database name >DB_NAME=`$XML_READ yazgfs/config/database` >RESULT=$? >if [ "$RESULT" -ne "0" ]; then > echo "Unable to read $KOHA_CONF and determine yazgfs/config/database." > echo "Aborting!" > rm $XML_READ > exit 1 >fi > ># So where are the biblio config files for Zebra? >BIBZEBIDX=`$XML_READ yazgfs/server/config | sort -u | grep bib` >RESULT=$? >if [ "$RESULT" -ne "0" ]; then > echo "Unable to read $KOHA_CONF and determine yazgfs/server/config for" > echo "biblios or permission denied. Aborting!" > rm $XML_READ > exit 1 >fi >if [ ! -e $BIBZEBIDX ]; then > echo "The biblios zebra index file ($BIBZEBIDX) does not exist. Aborting!" > rm $XML_READ > exit 1 >fi > ># So where are the authorities config files for Zebra? >AUTHZEBIDX=`$XML_READ yazgfs/server/config | sort -u | grep auth` >RESULT=$? >if [ "$RESULT" -ne "0" ]; then > echo "Unable to read $KOHA_CONF and determine yazgfs/server/config for" > echo "authorities or permission denied. Aborting!" > rm $XML_READ > exit 1 >fi >if [ ! -e $AUTHZEBIDX ]; then > echo "The authorities zebra index file ($AUTHZEBIDX) does not exist or" > echo "permission denied. Aborting!" > rm $XML_READ > exit 1 >fi > ># Are we running git/dev? the INTRANETDIR will have a .git subdirectory. ># Determine the INTRANETDIR. >INTRANETDIR=`$XML_READ yazgfs/config/intranetdir` >RESULT=$? >if [ "$RESULT" -ne "0" ]; then > echo "Unable to read $KOHA_CONF and determine yazgfs/config/intranetdir or" > echo "permission denied. Aborting!" > rm $XML_READ > exit 1 >fi > ># No sense keeping it if we aren't using it now. >rm $XML_READ > >if [ ! -d $INTRANETDIR ]; then > echo "Missing directory ($INTRANETDIR) or permission denied. Aborting!" > exit 1 >fi > ># Is there a .git subdirectory? >if [[ -d $INTRANETDIR/.git && "$GIT" -ne "1" ]]; then > echo "\$INTRANETDIR ($INTRANETDIR) has .git directory, but determined this" > echo "isn't a git installation. Confused! Aborting!" > exit 1 >fi > >if [[ ! -d $INTRANETDIR/.git && "$GIT" -eq "1" ]]; then > echo "\$INTRANETDIR ($INTRANETDIR) has no .git directory, but determined" > echo "this is a git installation. Confused! Aborting!" > exit 1 >fi > ># We should only try uninstalling if we know there is one kind of installation. ># so let's do some sanity checks. >SANITY=$(($PKG + $GIT + $TARBALL)) >if [ "$SANITY" -ne "1" ]; then > echo "Unable to determine what kind of installation you have. Aborting." > exit 1 >fi > ># Tell the user what kind of installation they have. >if [ "$PKG" -eq "1" ]; then > echo "You likely have a packages installation." >elif [ "$GIT" -eq "1" ]; then > echo "You likely have a git installation." >else > echo "You likely have a tarball installation." >fi > ># Check if there are koha databases. >LOGIN="--user=$DB_USER --password=$DB_PASS" >CHKDBS=`$MYSQL -B -N -e "show databases;" $LOGIN | grep $DB_NAME | wc -l` >if [ "$CHKDBS" -eq "0" ]; then > echo "Unable to find koha database ($DB_NAME). Aborting!" > exit 1 >fi > ># Dump backups of the instances/database. >echo "We will dump copies of the database(s), in case you make a mistake." >while read DB2dump; do > echo -n "Dumping backup of $DB2dump to ~/${DB2dump}.sql ... " > $MYSQLDUMP $LOGIN --databases $DB2dump > ~/${DB2dump}.sql > RESULT=$? > if [ "$RESULT" -eq "0" ]; then > echo "OK" > else > rm ~/${DB2dump}.sql &> /dev/null > echo "FAILED" > fi >done < <($MYSQL -B -N -e "show databases;" $LOGIN | grep $DB_NAME) > ># Prompt for confirmation TWICE. >echo >echo -n "Directories and files will be irrecoverably deleted. " >echo -n "Are you sure (y/n)? " >FLAG=0 >while [ "$FLAG" -eq "0" ]; do > read ANSWER > if [[ "${ANSWER:0:1}" =~ [yYnN] ]]; then > FLAG=1 > else > echo "Please type 'y' or 'n' followed by enter/return" > fi >done > >if [[ "${ANSWER:0:1}" =~ [nN] ]]; then > echo "Aborting!" > exit 1 >else > echo -n "There is no turning back. Are you sure (y/n)? " >fi > >FLAG=0 >while [ "$FLAG" -eq "0" ]; do > read ANSWER > if [[ "${ANSWER:0:1}" =~ [yYnN] ]]; then > FLAG=1 > else > echo "Please type 'y' or 'n' followed by enter/return" > fi >done > >if [[ "${ANSWER:0:1}" =~ [nN] ]]; then > echo "Aborting!" > exit 1 >else > echo "Processing will continue." >fi > >if [ ! -d /etc/apache2/sites-enabled ]; then > echo "Apache2 sites-enabled is not configured as expected. Aborting!" > exit 1 >fi > >if [ ! -d /etc/apache2/sites-available ]; then > echo "Apache2 sites-available is not configured as expected. Aborting!" > exit 1 >fi > >DAEMONCOUNT=`ls /etc/init.d/*koha* 2> /dev/null | wc -l` >if [ "$DAEMONCOUNT" -eq "0" ]; then > echo "Missing expected Zebra daemon files. Aborting!" > exit 1 >fi > >if [ "${#BIBZEBIDX}" -eq "0" ]; then > echo "Unable to find zebra biblio indexing configuration files. Aborting!" > exit 1 >fi > >if [ "${#AUTHZEBIDX}" -eq "0" ]; then > echo "Unable to find zebra authorities indexing configuration files." > echo "Aborting!" > exit 1 >fi > >CHKCROND=`find /etc/cron* -name "*koha*" 2> /dev/null | wc -l` >if [ "$CHKCROND" -eq "0" ]; then > echo "Unable to find koha crontab files. Aborting!" > exit 1 >fi > >CHKDIRS=`grep koha $INSTALL_LOG | cut -f2 -d'=' | cut -f1-4 -d'/' | grep ^\/ | sort -u | wc -l` >if [ "$CHKDIRS" -eq "0" ]; then > echo "Unable to determine typical directories to delete. Aborting!" > exit 1 >fi > ># This is never called now that we purposefully tell them to do it manually. ># But is this so wrong to leave in for reference? :) >if [ "$PKG" -eq "1" ]; then > echo "Koha instances being removed..." > while read INSTANCE; do > echo -n "Removing $INSTANCE... " > sudo koha-remove $INSTANCE &> /dev/null > if [ "$?" -eq "0" ]; then > echo "OK" > else > echo "FAILED" > fi > done < <(koha-list) > echo -n "Removing koha-common package... " > sudo apt-get -y remove koha-common &> /dev/null > if [ "$?" -eq "0" ]; then > echo "OK" > else > echo "FAILED" > fi >fi > ># First we'll handle apache. >echo "Disabling and removing koha apache site(s)." >while read SITE2DIS; do > SITE2RM=`basename $SITE2DIS` > echo -n "Disabling $SITE2RM... " > sudo a2dissite $SITE2RM &> /dev/null > if [ "$?" -eq "0" ]; then > echo "[OK]" > else > echo "[FAILED]" > fi > echo -n "Removing /etc/apache2/sites-available/$SITE2RM... " > sudo rm /etc/apache2/sites-available/$SITE2RM &> /dev/null > if [ "$?" -eq "0" ]; then > echo "[OK]" > else > echo "[FAILED]" > fi >done < <(grep -l koha /etc/apache2/sites-enabled/*) > >echo -n "Restarting apache2... " >sudo service apache2 restart &> /dev/null >if [ "$?" -eq "0" ]; then > echo "[OK]" >else > echo "[FAILED]" >fi > ># Next we'll work on the koha-zebra-daemon. >echo "Removing koha-zebra-daemon." >while read DAEMON; do > # Trim excess spaces and tabs > DAEMON=`echo $DAEMON | tr -d ' ' | tr -d ' '` > if [ "${#DAEMON}" -gt "0" ]; then > echo -n "Stopping $DAEMON... " > sudo $DAEMON stop > if [ "$?" -eq "0" ]; then > echo "OK" > else > echo "FAILED" > fi > > echo -n "Removing rc scripts for $DAEMON... " > sudo update-rc.d `basename $DAEMON` remove > if [ "$?" -eq "0" ]; then > echo "OK" > else > echo "FAILED" > fi > > echo -n "Removing init.d script for $DAEMON... " > sudo rm $DAEMON > if [ "$?" -eq "0" ]; then > echo "OK" > else > echo "FAILED" > fi > fi >done < <(ls /etc/init.d/*koha* 2> /dev/null) > ># Next we'll drop the database >echo "koha databases being removed..." >while read DB2dump; do > echo -n "Dropping $DB2dump... " > mysql $LOGIN -e "drop database $DB2dump;" &> /dev/null > if [ "$?" -eq "0" ]; then > echo "OK" > else > echo "FAILED" > fi >done < <($MYSQL -B -N -e "show databases;" $LOGIN 2> /dev/null | grep $DB_NAME) > ># Cleaning up the Zebra Indexes >echo "Cleaning up the Zebra Indexes" >echo -n "Biblios... " >sudo zebraidx -c $BIBZEBIDX -g iso2709 -d biblios init &> /dev/null >if [ "$?" -eq "0" ]; then > echo "[OK]" >else > echo "[FAILED]" >fi >echo -n "Authorities... " >sudo zebraidx -c $AUTHZEBIDX -g iso2709 -d authorities init &> /dev/null >if [ "$?" -eq "0" ]; then > echo "[OK]" >else > echo "[FAILED]" >fi > ># remove the crontab job >echo "Removing koha crontab jobs..." >while read CRONJOB; do > echo -n "Removing $CRONJOB... " > sudo rm $CRONJOB &> /dev/null > if [ "$?" -eq "0" ]; then > echo "[OK]" > else > echo "[FAILED]" > fi >done < <(find /etc/cron* -name "*koha*") > ># a whole bunch of installation directories. >echo "Directories being deleted." >while read DIR2DEL; do > echo -n "$DIR2DEL being deleted... " > sudo rm -rf $DIR2DEL &> /dev/null > if [ "$?" -eq "0" ]; then > echo "[OK]" > else > echo "[FAILED]" > fi >done < <(grep koha $INSTALL_LOG 2> /dev/null | cut -f2 -d'=' | cut -f1-4 -d'/' | grep ^\/ | sort -u) > ># attempting to delete koha users >echo -n "Removing koha user... " >sudo deluser $KOHA_USER &> /dev/null >if [ "$?" -eq "0" ]; then > echo "[OK]" >else > echo "[FAILED]" >fi > >echo "Uninstall finished." >echo "Please read the output to confirm it completed properly."
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 459
:
12435
|
12451
| 12606