No subject
Wed May 27 13:54:03 CEST 2009
At the moment $KOHAROOT is KOHAROOT
ENVFOUND
}
sub noguarantee{
print $TEE_DUAL_OUTPUT <<NOGUARANTEE;
No guarantee that either /etc/koha-conf.xml or /etc/koha/koha-conf.xml
exists. (They may both exist or not, or niether.) And, even if one, or =
both,=20
does exist, there's no guarantee that either contains what you need (or =
is=20
current.)
NOGUARANTEE
}
sub mode{
if ($MODE =3D~ /SAFE/){
print $TEE_DUAL_OUTPUT <<SAFE;
Program mode is: SAFE. No files will be deleted. And the koha database =
will=20
not be dropped. A logfile was created at
/tmp/koha_uninstall_history.log
SAFE
}else{
print $TEE_DUAL_OUTPUT <<RISK;
It is not advisble to run the program in any mode other than SAFE mode.
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
YOU are responsible for ensuring that it is instructed to delete=20
the correct files.
RISK
}
}
###################################################################
# The Basement: This is where the code is.
###################################################################
sub open_logfile{ #Preserve the old one, (if it exists.)
if ( -f "/tmp/koha_uninstall_history.log"){
copy( "/tmp/koha_uninstall_history.log", =
"/tmp/koha_uninstall_history.log.$$")=20
or warn "Cannot preserve old koha uninstall history log.";
if ( -f "/tmp/koha_uninstall_history.log.$$"){
unlink "/tmp/koha_uninstall_history.log";
}
}
$TEE_DUAL_OUTPUT =3D IO::Tee->new(">> =
/tmp/koha_uninstall_history.log", \*STDOUT);
}
sub is_this_authentic_koha_root{
my $BADUNINSTALLINFO=3D"";
my $manyerrors=3D"0";
my @KOHAFILES=3Dqw( bin doc intranet lib man misc opac );
foreach (@KOHAFILES) {
if ($manyerrors < 3){
if ( !-d "$KOHAROOT/$_"){
++$manyerrors;
$BADUNINSTALLINFO=3D"True";
& warnaboutroot;
}
# Bailout of uninstall. You've been given bad uninstall =
info.
} else {
if ($manyerrors < 3){;
if ( -f "$KOHAROOT/$_"){
print $TEE_DUAL_OUTPUT "Validating $KOHAROOT =
[Found] $_\n";
}
}
}
}=20
if ( "$BADUNINSTALLINFO" !~ /True/){
& okibelieve;
& prep_genuine_root_del;
}
}
sub locate_env_variables{
# The first thing we need to do is test for ENV variables
if ($ENV{KOHA_CONF}){
print $TEE_DUAL_OUTPUT "\n [Found] ENV Variable =
$ENV{KOHA_CONF} \n";
& try_etc_koha_conf_xml;
}
if (!$ENV{PERL5LIB}){
if (!$ENV{KOHA_CONF}){
print $TEE_DUAL_OUTPUT "\nWARNING PERL5LIB & KOHA_CONF =
ENV VARS missing!\n";
& try_etc_koha_conf_xml;
& user_input;
}
}else{
if (!$ENV{KOHA_CONF}){
print $TEE_DUAL_OUTPUT "\nWARNING KOHA_CONF ENV VAR =
missing!\n";
}else{
print $TEE_DUAL_OUTPUT "\n [Found] ENV Variable =
$ENV{KOHA_CONF} \n";
& try_etc_koha_conf_xml;
}
# Env variables are present.
$KOHAROOT=3D$ENV{PERL5LIB};
if ( $ENV{PERL5LIB} =3D~ /lib\// ){ =20
$KOHAROOT =3D~ s/lib\///;=20
}else{
$KOHAROOT =3D~ s/lib//;
} =20
$KOHAROOT =3D~ s/koha\//koha/; =20
& printenvfound;=20
& is_this_authentic_koha_root;
}
}
sub try_etc_koha_conf_xml{
if ( -f "/etc/koha-conf.xml" ){
$CONFIGFILE=3D"/etc/koha-conf.xml";
& read_config_file;
& del_conf;
}else{
if ( -f "/etc/koha/koha-conf.xml" ){
$CONFIGFILE=3D"/etc/koha/koha-conf.xml";
& read_config_file;
& del_conf;
}else{
if ( -f "$ENV{KOHA_CONF}" ){
$CONFIGFILE=3D"$ENV{KOHA_CONF}";
& read_config_file;
& del_conf;
}
}
sub read_config_file{
my $etc_conf_log;
print $TEE_DUAL_OUTPUT "\n\n [Found] Config at loc =
$CONFIGFILE \n";
open(CONFIG_FILE, "<$CONFIGFILE");
while (<CONFIG_FILE>){
if ($_ =3D~ /install_log/){
s/\<install_log\>//; # config is XML trim =
this off =20
s/\<\/install_log\>//;
s/\s+//g;
chomp; =20
$etc_conf_log =3D $_;=20
if ( -f "$etc_conf_log" ){
$KOHAROOT=3D$etc_conf_log;
$KOHAROOT =3D~ s/koha-install-log//;
$KOHAROOT =3D~ s/misc\///;
print $TEE_DUAL_OUTPUT <<EOF2;
I have located a koha installation log file history at $etc_conf_log
However, there is no guarantee that the logfile is either current or =
accurate.
From the location of the koha logfile at: $etc_conf_log
I make an educated guess that there is a koha installation at: =
$KOHAROOT
EOF2
& is_this_authentic_koha_root;
}
}
}
}
}
}
sub user_input{
if ($DELCOMPLETE !~ /True/){
print $TEE_DUAL_OUTPUT "Enter location of your koha =
installation\n";
my $kohainstallation=3D(<STDIN>);
chop $kohainstallation;
if ( -d $kohainstallation ){
$KOHAROOT =3D "$kohainstallation";
print " [Found] $KOHAROOT Do you want to delete it? Yes =
or No?\n";
my $continue2=3D(<STDIN>);
chop $continue2;
if ($continue2 =3D~ /^Y\b|^yes|^y\b|^Yes/i) { # =
Uninstall user-specified koharoot
& is_this_authentic_koha_root;
}
}else{
print <<EOF1;
The user-specified directory $kohainstallation does not =
exist. Please locate
your koha installation and rerun the script.
EOF1
exit 0;=20
}
}
}
sub prep_genuine_root_del{
& mode;
if ( $MODE =3D~ /SAFE/){
}else{
if ( $MODE =3D~ /INSECURE/){
& deletelogs;
if (-d "$ETCDIR"){
rmtree($ETCDIR) or warn $!;
my @ETCKOHACONTENTS=3Dqw( koha-httpd.conf =
pazpar2 README.txt zebradb );
foreach (@ETCKOHACONTENTS) {
if ( -e "$ETCDIR/$_"){
print $TEE_DUAL_OUTPUT "[DELETING] =
$ETCDIR/$_\n";
rmtree("$ETCDIR/$_") or warn $!;
}
}
rmdir ("$ETCDIR/$_") || warn (" [ERROR IN =
DELETING] $ETCDIR/$_ $?");
}
my @KOHAFILES=3Dqw( bin doc intranet lib man =
misc opac ); =20
foreach (@KOHAFILES) {
if ( -d "$KOHAROOT/$_"){
rmtree("$KOHAROOT/$_") or warn $!;
print $TEE_DUAL_OUTPUT "[DELETING] =
$KOHAROOT/$_\n";
if ( -d "$KOHAROOT/etc"){
print $TEE_DUAL_OUTPUT =
"[DELETING] $KOHAROOT/etc\n";
rmtree("$KOHAROOT/etc") or warn =
$!;
}
if ( -d "$KOHAROOT/var"){
print $TEE_DUAL_OUTPUT =
"[DELETING] $KOHAROOT/var\n";
rmtree("$KOHAROOT/var") or warn =
$!;
}
}
}
if ( -e "$KOHAROOT"){
print $TEE_DUAL_OUTPUT "[DELETING] =
$KOHAROOT\n";
rmdir ("$KOHAROOT") || warn (" [ERROR IN =
DELETING] $KOHAROOT $?");
}
print $TEE_DUAL_OUTPUT "[DELETION COMPLETE]\n";
$DELCOMPLETE=3D"True";
print $TEE_DUAL_OUTPUT "[DROPPING] the koha database\n";
& drop_the_koha_db;
}
}
}
sub del_conf{
if ( $MODE =3D~ /SAFE/){
print $TEE_DUAL_OUTPUT " Program mode is: SAFE. No files =
will be deleted. \n";
}else{
if ( $MODE =3D~ /INSECURE/){
if ( -e $CONFIGFILE){
print $TEE_DUAL_OUTPUT "\n\n =
[DELETING] Config at loc $CONFIGFILE \n";
unlink $CONFIGFILE;
}
}
}
}
sub drop_the_koha_db{
# You really want to make sure that you really want to do this!
print "Do you want to drop the koha database? Yes or No?\n";
my $dropit=3D(<STDIN>);
chop $dropit;
if ($dropit =3D~ /^Y\b|^yes|^y\b|^Yes/i) { # You have =
permission to drop the database
print "Are you sure that you want to drop the koha =
database? Yes or No?\n";
my $sure=3D(<STDIN>);
chop $sure;
if ($sure =3D~ /^Y\b|^yes|^y\b|^Yes/i) { #How sure does =
he need to be? (Remove it.)
& run_drop_db_code;
}
}
print "Do you want to delete koha's users and groups? Yes or =
No?\n";
my $people=3D(<STDIN>);
chop $people;
if ($people =3D~ /^Y\b|^yes|^y\b|^Yes/i) { # del users & groups=20
& del_users_and_groups;
}
sub run_drop_db_code{
my $DBPASSWD=3D"katikoan";
my $DBUSER=3D"root";
if ( $DROPMODE !~ /SILENT/){
print "Please enter [mysql]database username of mysql =
admin user. \n";
$DBUSER=3D(<STDIN>);
chop $DBUSER;
print "Please enter [mysql]database password for the =
mysql admin user. \n";
$DBPASSWD=3D(<STDIN>);
chop $DBPASSWD;
}
my =
$dbh=3DDBI->connect('DBI:mysql:mysql:localhost:port=3D3306:socket=3D/tmp/=
mysqld-new.sock',=20
$DBUSER, $DBPASSWD) or warn "Cannot connect to database =
: $DBI::errstr\n";
my $sth =3D $dbh->prepare('drop database koha')
or warn "Couldn't prepare statement: " . $dbh->errstr;
$sth->execute() # Execute the query
or warn "Couldn't execute statement: " . $sth->errstr;
$sth->finish;
$dbh->disconnect;
}
sub del_users_and_groups{
foreach (@kohausers){
`$deluser $_`;=20
}
foreach (@kohagroups){
`$delgroup $_`;
}
}
}
sub deletelogs{
if (-d "$LOGDIR") {
my @KOHALOGS=3Dqw( koha-access_log koha-intranet-rewrite.log
koha-opac-error_log README koha-error_log
koha-opac-access_log koha-opac-rewrite.log);
foreach (@KOHALOGS) {
print $TEE_DUAL_OUTPUT "[DELETING] =
$LOGDIR/$_\n";
unlink "$LOGDIR/$_";
}
rmdir ("$LOGDIR") || warn (" [ERROR IN =
DELETING] $LOGDIR $?");
}
}
------=_NextPart_000_0031_01C9FEFD.2015CB50--
More information about the Koha-devel
mailing list