package INSTALL::reboot; use INSTALL::common; use INSTALL::global; use INSTALL::os; use INSTALL::substitute; my $pOS = \%INSTALL::os::Details; my $pGlobals = \%INSTALL::global::variables; # These aren't my'd because they need to be resolved symbolically in code # below. my'd symbols cannot be resolved symbolically. $RedHat_RCFile = '#!/bin/sh #------------------------------------------------------------------------------ # Generated for the Sun Chili!Soft ASP Server # # Author: Sun Microsystems, Inc. (2000) # Script: <> #------------------------------------------------------------------------------ # Source function library. . /etc/rc.d/init.d/functions # See how we were called. case "$1" in start) echo -n "Executing start script (<>): " <> > /dev/null 2>&1 && success || failed $1 echo touch /var/lock/subsys/<> > /dev/null 2>&1 ;; stop) echo -n "Executing stop script (<>): " <> > /dev/null 2>&1 && success || failed $1 echo rm -f /var/lock/subsys/<> > /dev/null 2>&1 ;; status) echo "Executing status script(<>): " <> ;; restart) $0 stop $0 start ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1 esac exit 0 '; $TurboLinux_RCFile = '#!/bin/sh #------------------------------------------------------------------------------ # Generated for the Sun Chili!Soft ASP Server # # Author: Sun Microsystems, Inc. (2000) # Script: <> #------------------------------------------------------------------------------ # Source function library. . /etc/rc.d/init.d/functions function success { echo -n "Success." } function failure { echo "Failed to $1." exit 1 } # See how we were called. case "$1" in start) echo -n "Executing start script (<>): " <> > /dev/null 2>&1 && success || failed $1 echo touch /var/lock/subsys/<> > /dev/null 2>&1 ;; stop) echo -n "Executing stop script (<>): " <> > /dev/null 2>&1 && success || failed $1 echo rm -f /var/lock/subsys/<> > /dev/null 2>&1 ;; status) echo "Executing status script(<>): " <> ;; restart) $0 stop $0 start ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1 esac exit 0 '; $SuSE_RCFile = '#! /bin/sh #------------------------------------------------------------------------------ # Generated for the Sun Chili!Soft ASP Server # # Author: Sun Microsystems, Inc. (2000) # Script: <> #------------------------------------------------------------------------------ . /etc/rc.config # Set this to something other than yes to disable automatic restart on system # boot. If it is set to something other than yes, the script will only # execute if run by a user (ie. not during runlevel changes). START_ASP=yes # Determine the base and follow a runlevel link name. base=${0##*/} link=${base#*[SK][0-9][0-9]} # Force execution if not called by a runlevel directory. test $link = $base && START_ASP_=yes test "$START_ASP" = yes || exit 0 # The echo return value for success (defined in /etc/rc.config). return=$rc_done case "$1" in start) echo -n "Executing start script (<>): " <> > /dev/null 2>&1 || return=$rc_failed echo -e "$return" touch /var/lock/subsys/<> > /dev/null 2>&1 ;; stop) echo -n "Executing stop script (<>): " <> > /dev/null 2>&1 || return=$rc_failed echo -e "$return" rm -f /var/lock/subsys/<> > /dev/null 2>&1 ;; restart) $0 stop || return=$rc_failed $0 start || return=$rc_failed ;; status) echo "Executing status script(<>): " <> ;; *) echo "Usage: $0 {start|stop|status|restart}" exit 1 ;; esac # Inform the caller not only verbosely and set an exit status. test "$return" = "$rc_done" || exit 1 exit 0 '; $Slackware_RCFile = '#! /bin/sh #------------------------------------------------------------------------------ # Generated for the Sun Chili!Soft ASP Server # # Author: Sun Microsystems, Inc. (2000) # Script: <> #------------------------------------------------------------------------------ rc_success="Success." rc_failed="Failure." return=$rc_success case "$1" in start) echo -n "Executing start script (<>): " <> > /dev/null 2>&1 || return=$rc_failed echo -e "$return" touch /var/lock/subsys/<> > /dev/null 2>&1 ;; stop) echo -n "Executing stop script (<>): " <> > /dev/null 2>&1 || return=$rc_failed echo -e "$return" rm -f /var/lock/subsys/<> > /dev/null 2>&1 ;; restart) $0 stop || return=$rc_failed $0 start || return=$rc_failed ;; status) echo "Executing status script(<>): " <> ;; *) echo "Usage: $0 {start|stop|status|restart}" exit 1 ;; esac # Inform the caller not only verbosely and set an exit status. test "$return" = "$rc_success" || exit 1 exit 0 '; $Debian_RCFile = $Slackware_RCFile; ######################### # Solaris ######################### $SunOS_RCFile = '#! /bin/sh #------------------------------------------------------------------------------ # Generated for the Sun Chili!Soft ASP Server # # Author: Sun Microsystems, Inc. (2000) # Script: <> #------------------------------------------------------------------------------ rc_success="Success." rc_failed="Failure." return=$rc_success case "$1" in start) echo "Executing start script (<>): \c" <> > /dev/null 2>&1 || return=$rc_failed echo "$return" ;; stop) echo "Executing stop script (<>): \c" <> > /dev/null 2>&1 || return=$rc_failed echo "$return" ;; restart) $0 stop || return=$rc_failed $0 start || return=$rc_failed ;; status) echo "Executing status script(<>): " <> ;; *) echo "Usage: $0 {start|stop|status|restart}" exit 1 ;; esac # Inform the caller not only verbosely and set an exit status. test "$return" = "$rc_success" || exit 1 exit 0 '; ######################### # AIX ######################### $AIX_RCFile = '#!/usr/bin/ksh #------------------------------------------------------------------------------ # Generated for the Sun Chili!Soft ASP Server # # Author: Sun Microsystems, Inc. (2000) # Script: <> # NOTE: To avoid your system from failing on reboot, do not change this # file in any way. # This script is designed to be executed on reboot. # ############################################################################# #------------------------------------------------------------------------------ rc_success="Success." rc_failed="Failure." return=$rc_success # See how we were called. case "$1" in start) echo "Executing start script (<>): \c" <> > /dev/null 2>&1 || return=$rc_failed echo "$return" ;; stop) echo "Executing stop script (<>): \c" <> > /dev/null 2>&1 || return=$rc_failed echo "$return" ;; status) echo "Executing status script(<>): " <> ;; restart) $0 stop $0 start ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1 esac # Inform the caller not only verbosely and set an exit status. test "$return" = "$rc_success" || exit 1 exit 0 '; ######################### # HP-UX ######################### $HPUX_RCFile = '#!/sbin/sh #------------------------------------------------------------------------------ # Generated for the Sun Chili!Soft ASP Server # # Author: Sun Microsystems, Inc. (2000) # Script: <> # NOTE: To avoid your system from failing on reboot, do not change this # file in any way. # This script is designed to be executed on reboot. # #------------------------------------------------------------------------------ PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH export PATH # Set this value to 0, if you want to stop the auto-reboot feature. CHILIASP_START=1 rval=0 case "$1" in start_msg) echo "Starting Chili!Soft ASP Server" ;; stop_msg) echo "Stopping Chili!Soft ASP Server" ;; start) if [ -f /etc/rc.config ] ; then . /etc/rc.config else print "ERROR: /etc/rc.config defaults file MISSING" fi if [ "$CHILIASP_START" -eq 1 ]; then <> rval=$? else rval=2 fi ;; stop) <> rval=$? ;; status) <> rval=$? ;; restart) <> <> rval=$? ;; *) echo "usage: $0 {start|stop|status|restart}" rval=2 ;; esac exit $rval '; #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # External functions #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #------------------------------------------------------------------------------ # This method returns non-undef / true in the case of automatic reboot being # enabled for the running distribution. #------------------------------------------------------------------------------ sub supported { # Invoke the appropriate install_script function for the appropriate OS, # distribution, etc. using the following rules: # If a function exists by the name install__, use that function, else # If a function exists by the name install__, use that function, else # If a function exists by the name install__Default, use that function, else # return(undef) # Note: supported requires both an install and an uninstall function. my $base_install = encode_names("install_$pOS->{os}_"); my $base_uninstall = encode_names("uninstall_$pOS->{os}_"); my @attempts = ($pOS->{distribution},$pOS->{distribution_flavor},"Default"); foreach(@attempts) { my $install = "$base_install$_"; my $uninstall = "$base_uninstall$_"; if ((defined &$install) && (defined &$uninstall)) { return(1); } } #--------------------------------------------------------------------------- # Non-supported platform / distribution. #--------------------------------------------------------------------------- return(undef); } sub retrieve_RCFile { ($#_ < 0) || die "Invalid number of arguments."; my $RCFile_Distribution_Var = encode_names("$pOS->{distribution}_RCFile"); my $RCFile_Flavor_Var = encode_names("$pOS->{distribution_flavor}_RCFile"); my $RCFile_OS_Var = encode_names("$pOS->{os}_RCFile"); my $RCFile; if (defined $$RCFile_Distribution_Var) { # If there is a specific variant of the RedHat RCFile that we want to use # for a given RedHat flavor, it will have an associated RCFile. # Use it if there is one. $RCFile = $$RCFile_Distribution_Var; } elsif (defined $$RCFile_Flavor_Var) { $RCFile = $$RCFile_Flavor_Var; } elsif (defined $$RCFile_OS_Var) { $RCFile = $$RCFile_OS_Var; } else { if ($pOS->{os} =~ /Linux/i) { die "Unable to locate RCFile for distribution / flavor ($pOS->{distribution}/$pOS->{distribution_flavor})."; } else { die "Unable to locate RCFile for $pOS->{os}."; } } return($RCFile); } #------------------------------------------------------------------------------ # RedHat #------------------------------------------------------------------------------ sub install_Linux_RedHat { ($#_ == 5) || die "Invalid number of arguments."; my ($script_name, $start_script, $stop_script, $status_script, $start_priority, $stop_priority) = @_; my %substitute = ( reboot::script_name => $script_name, reboot::start_script => $start_script, reboot::stop_script => $stop_script, reboot::status_script => $status_script, reboot::start_priority => $start_priority, reboot::stop_priority => $stop_priority ); my $script_path = "/etc/rc.d/init.d/$script_name"; my $RCFile = retrieve_RCFile; unlink($script_path); INSTALL::substitute::string_to_file ({ map { ("<<$_>>" => $substitute{$_}) } keys %substitute }, $script_path, $RCFile ); chmod(0755,$script_path); my $source = "../init.d/$script_name"; # Generate start links. foreach (3 .. 5) { my $destination = "/etc/rc.d/rc$_.d/S$start_priority$script_name"; unlink($destination); unless(symlink($source,$destination)) { uninstall_script($script_name,$start_priority,$stop_priority); return(error("Unable to make symlink from $source to $destination.\n")); } } # Generate kill links. foreach (0, 1, 2, 6) { my $destination = "/etc/rc.d/rc$_.d/K$stop_priority$script_name"; unlink($destination); unless(symlink($source,$destination)) { uninstall_script($script_name,$start_priority,$stop_priority); return(error("Unable to make symlink from $source to $destination.\n")); } } return(1); } sub uninstall_Linux_RedHat { ($#_ == 2) || die "Invalid number of arguments."; my ($script_name,$start_priority, $stop_priority) = @_; if ($pOS->{distribution_flavor} eq "RedHat") { unlink("/etc/rc.d/init.d/$script_name"); foreach (0 .. 6) { unlink("/etc/rc.d/rc$_.d/K$stop_priority$script_name"); unlink("/etc/rc.d/rc$_.d/S$start_priority$script_name"); } return(1); } } #------------------------------------------------------------------------------ # SuSE #------------------------------------------------------------------------------ sub install_Linux_SuSE { ($#_ == 5) || die "Invalid number of arguments."; my ($script_name, $start_script, $stop_script, $status_script, $start_priority, $stop_priority) = @_; my %substitute = ( reboot::script_name => $script_name, reboot::start_script => $start_script, reboot::stop_script => $stop_script, reboot::status_script => $status_script, reboot::start_priority => $start_priority, reboot::stop_priority => $stop_priority ); my $script_path; if ($pOS->{distribution} =~ /SuSE/i && $pOS->{distribution_version} >= 7.2) { $script_path = "/etc/init.d/$script_name"; } else { $script_path = "/sbin/init.d/$script_name"; } my $RCFile = retrieve_RCFile; unlink($script_path); unless(INSTALL::substitute::string_to_file ({ map { ("<<$_>>" => $substitute{$_}) } keys %substitute }, $script_path, $RCFile )) { uninstall_script($script_name,$start_priority,$stop_priority); return(error("Unable to make create file $script_path")); } chmod(0755,$script_path); unless(symlink($script_path,"/sbin/rc$script_name")) { uninstall_script($script_name,$start_priority,$stop_priority); return(error("Unable to make symlink from $script_path to /sbin/rc$script_name")); } my $source = "../$script_name"; # Generate start links. foreach (2 .. 5) { my $destination = "/etc/rc.d/rc$_.d/S$start_priority$script_name"; unlink($destination); unless(symlink($source,$destination)) { uninstall_script($script_name,$start_priority,$stop_priority); return(error("Unable to make symlink from $source to $destination.\n")); } } # Generate kill links. foreach (0, 1, 6) { my $destination = "/etc/rc.d/rc$_.d/K$stop_priority$script_name"; unlink($destination); unless(symlink($source,$destination)) { uninstall_script($script_name,$start_priority,$stop_priority); return(error("Unable to make symlink from $source to $destination.\n")); } } return(1); } sub uninstall_Linux_SuSE { ($#_ == 2) || die "Invalid number of arguments."; my ($script_name,$start_priority, $stop_priority) = @_; if ($pOS->{distribution} =~ /SuSE/i && $pOS->{distribution_version} >= 7.2) { unlink("/etc/init.d/$script_name"); } else { unlink("/sbin/init.d/$script_name"); } unlink("/sbin/rc$script_name"); foreach (0 .. 6) { unlink("/etc/rc.d/rc$_.d/K$stop_priority$script_name"); unlink("/etc/rc.d/rc$_.d/S$start_priority$script_name"); } return(1); } #------------------------------------------------------------------------------ # Slackware #------------------------------------------------------------------------------ sub install_Linux_Slackware { ($#_ == 5) || die "Invalid number of arguments."; my ($script_name, $start_script, $stop_script, $status_script, $start_priority, $stop_priority) = @_; my %substitute = ( reboot::script_name => $script_name, reboot::start_script => $start_script, reboot::stop_script => $stop_script, reboot::status_script => $status_script, reboot::start_priority => $start_priority, reboot::stop_priority => $stop_priority ); ### Even though Slackware uses BSD-style init scripts still, they have ### made SysV-style init scripts available through one BSD-style script ### which is responsible for checking the existence of any SysV-style ### scripts and executing them (rc.sysvinit). my $script_dir = "/etc/rc.d/init.d"; if (not -d $script_dir) { unless(mkdir($script_dir,0755)) { return(error("Unable to create $script_dir for SysV-style init scripts.")); } } my $script_path = "$script_dir/$script_name"; my $RCFile = retrieve_RCFile; unlink($script_path); INSTALL::substitute::string_to_file ({ map { ("<<$_>>" => $substitute{$_}) } keys %substitute }, $script_path, $RCFile ); chmod(0755,$script_path); my $source = "../init.d/$script_name"; # Generate start links. foreach (2 .. 5) { my $destination_dir = "/etc/rc.d/rc$_.d"; if (not -d $destination_dir) { unless(mkdir($destination_dir,0755)) { uninstall_script($script_name,$start_priority,$stop_priority); return(error("Unable to create directory $destination_dir for SysV-style init script.")); } } my $destination = "$destination_dir/S$start_priority$script_name"; unlink($destination); unless(symlink($source,$destination)) { uninstall_script($script_name,$start_priority,$stop_priority); return(error("Unable to make symlink from $source to $destination.\n")); } } # Generate kill links. foreach (0, 1, 6) { my $destination_dir = "/etc/rc.d/rc$_.d"; if (not -d $destination_dir) { unless(mkdir($destination_dir,0755)) { uninstall_script($script_name,$start_priority,$stop_priority); return(error("Unable to create directory $destination_dir for SysV-style init script.")); } } my $destination = "$destination_dir/K$stop_priority$script_name"; unlink($destination); unless(symlink($source,$destination)) { uninstall_script($script_name,$start_priority,$stop_priority); return(error("Unable to make symlink from $source to $destination.\n")); } } return(1); } sub uninstall_Linux_Slackware { ($#_ == 2) || die "Invalid number of arguments."; my ($script_name,$start_priority, $stop_priority) = @_; unlink("/etc/rc.d/init.d/$script_name"); foreach (0 .. 6) { unlink("/etc/rc.d/rc$_.d/K$stop_priority$script_name"); unlink("/etc/rc.d/rc$_.d/S$start_priority$script_name"); } return(1); } #------------------------------------------------------------------------------ # Debian #------------------------------------------------------------------------------ sub install_Linux_Debian { ($#_ == 5) || die "Invalid number of arguments."; my ($script_name, $start_script, $stop_script, $status_script, $start_priority, $stop_priority) = @_; my %substitute = ( reboot::script_name => $script_name, reboot::start_script => $start_script, reboot::stop_script => $stop_script, reboot::status_script => $status_script, reboot::start_priority => $start_priority, reboot::stop_priority => $stop_priority ); my $script_path = "/etc/init.d/$script_name"; my $RCFile = retrieve_RCFile; unlink($script_path); INSTALL::substitute::string_to_file ({ map { ("<<$_>>" => $substitute{$_}) } keys %substitute }, $script_path, $RCFile ); chmod(0755,$script_path); my $source = "../init.d/$script_name"; # Generate start links. foreach (2 .. 5) { my $destination = "/etc/rc$_.d/S$start_priority$script_name"; unlink($destination); unless(symlink($source,$destination)) { uninstall_script($script_name,$start_priority,$stop_priority); return(error("Unable to make symlink from $source to $destination.\n")); } } # Generate kill links. foreach (0, 1, 6) { my $destination = "/etc/rc$_.d/K$stop_priority$script_name"; unlink($destination); unless(symlink($source,$destination)) { uninstall_script($script_name,$start_priority,$stop_priority); return(error("Unable to make symlink from $source to $destination.\n")); } } return(1); } sub uninstall_Linux_Debian { ($#_ == 2) || die "Invalid number of arguments."; my ($script_name,$start_priority, $stop_priority) = @_; if ($pOS->{distribution_flavor} eq "Debian") { unlink("/etc/init.d/$script_name"); foreach (0 .. 6) { unlink("/etc/rc$_.d/K$stop_priority$script_name"); unlink("/etc/rc$_.d/S$start_priority$script_name"); } return(1); } } #------------------------------------------------------------------------------ # SunOS #------------------------------------------------------------------------------ sub install_SunOS_Default { ($#_ == 5) || die "Invalid number of arguments."; my ($script_name, $start_script, $stop_script, $status_script, $start_priority, $stop_priority) = @_; my %substitute = ( reboot::script_name => $script_name, reboot::start_script => $start_script, reboot::stop_script => $stop_script, reboot::status_script => $status_script, reboot::start_priority => $start_priority, reboot::stop_priority => $stop_priority ); my $script_dir = "/etc/init.d"; if (not -d $script_dir) { INSTALL::common::mkpath($script_dir) || return(error("Unable to create reboot path $script_dir")); } my $script_path = "$script_dir/$script_name"; my $RCFile = retrieve_RCFile; unlink($script_path); INSTALL::substitute::string_to_file ({ map { ("<<$_>>" => $substitute{$_}) } keys %substitute }, $script_path, $RCFile ); chmod(0755,$script_path); my $source = "../init.d/$script_name"; # Generate start links. foreach (2) { my $rc_dir= "/etc/rc$_.d"; my $destination = "$rc_dir/S$start_priority$script_name"; mkpath($rc_dir,755); unlink($destination); unless(symlink($source,$destination)) { uninstall_script($script_name,$start_priority,$stop_priority); return(error("Unable to make symlink from $source to $destination.\n")); } } # Generate kill links. foreach (0, 1, 6) { my $rc_dir= "/etc/rc$_.d"; my $destination = "$rc_dir/K$stop_priority$script_name"; mkpath($rc_dir,755); unlink($destination); unless(symlink($source,$destination)) { uninstall_script($script_name,$start_priority,$stop_priority); return(error("Unable to make symlink from $source to $destination.\n")); } } return(1); } sub uninstall_SunOS_Default { ($#_ == 2) || die "Invalid number of arguments."; my ($script_name,$start_priority, $stop_priority) = @_; unlink("/etc/init.d/$script_name"); foreach (0 .. 6) { unlink("/etc/rc$_.d/K$stop_priority$script_name"); unlink("/etc/rc$_.d/S$start_priority$script_name"); } return(1); } #------------------------------------------------------------------------------ # AIX #------------------------------------------------------------------------------ sub install_AIX_Default { ($#_ == 5) || die "Invalid number of arguments."; my ($script_name, $start_script, $stop_script, $status_script, $start_priority, $stop_priority) = @_; my %substitute = ( reboot::script_name => $script_name, reboot::start_script => $start_script, reboot::stop_script => $stop_script, reboot::status_script => $status_script, reboot::start_priority => $start_priority, reboot::stop_priority => $stop_priority ); # we need to generate a /etc/rc.XX script . my $script_path = "/etc/rc.$script_name"; my $RCFile = retrieve_RCFile; unlink($script_path); INSTALL::substitute::string_to_file ({ map { ("<<$_>>" => $substitute{$_}) } keys %substitute }, $script_path, $RCFile ); chmod(0755,$script_path); my @reboot_lines; if (-x "/usr/sbin/lsitab") { @reboot_lines = grep { m@^\s*casp-[0-9]+:@ } split(/\n/,`/usr/sbin/lsitab -a`); } else { local *INITTAB; unless(open(INITTAB,"; chomp @reboot_lines; close(INITTAB); } } my %reboot_tags; foreach(@reboot_lines) { if (m@^\s*casp-([0-9]+):@) { $reboot_tags{$1} = undef; } } my $i = 0; my $reboot_tag; for(;;) { my $tag = sprintf("%03d",$i++); if (not exists $reboot_tags{$tag}) { $reboot_tag = "casp-$tag"; last; } } my $success; if (-x "/usr/sbin/mkitab") { if (system(qq'/usr/sbin/mkitab "$reboot_tag:$pOS->{default_runlevel}:once:$script_path start > /dev/console 2>&1"')) { error("mkitab failed to update the inittab file with the start script.", "Attempting to update manually."); } else { $success = 1; } } # Manual update. unless ($success) { my $dupname = "/etc/inittab.chiliasp-install"; unlink($dupname); if (copy("/etc/inittab",$dupname)) { return(error("Unable to make copy of the system inittab file, bailing ...", "Sun Chili!Soft ASP could not successfully enable auto start on", "system boot.")); } local *SRC; local *INITTAB; unless(open(SRC,"<$dupname") && open(INITTAB,">/etc/inittab")) { # Back out any changes. close(SRC); close(INITTAB); unlink($script_path); if (unlink("/etc/inittab")) { unless(rename($dupname,"/etc/inittab")) { if (copy($dupname,"/etc/inittab")) { # Egads ... return(error("Aiyeee, unable to restore system inittab. $dupname contains a duplicate of the original information.")); } } } else { unlink($dupname); } return(error("Unable to update the system inittab file.", "Sun Chili!Soft ASP could not successfully enable auto start on", "system boot.")); } my $source = join("",); unless ($source =~ /\n$/) { $source .= "\n"; } close(SRC); print INITTAB ($source, "$reboot_tag:$pOS->{default_runlevel}:once:$script_path start > /dev/console 2>&1\n"); close(INITTAB); report("Note: Manual modification of the system inittab was successful."); } return(1); } sub uninstall_AIX_Default { ($#_ == 2) || die "Invalid number of arguments."; my ($script_name,$start_priority, $stop_priority) = @_; my $script_path = "/etc/rc.$script_name"; my @reboot_lines; if (-x "/usr/sbin/lsitab") { @reboot_lines = grep { m@^\s*casp-[0-9]+:@ } split(/\n/,`/usr/sbin/lsitab -a`); } else { local *INITTAB; unless(open(INITTAB,"; chomp @reboot_lines; close(INITTAB); } } my $reboot_tag; foreach(@reboot_lines) { if (m@(casp-[0-9]+):[0-9]*:once:$script_path\s@) { $reboot_tag = $1; } } unless($reboot_tag) { return(error("Unable to locate a matching entry in the system inittab file.")); } my $success; if (-x "/usr/sbin/rmitab") { if (system(qq'/usr/sbin/rmitab "$reboot_tag"')) { error("rmitab failed to remove $reboot_tag from the system inittab.", "Attempting manual removal."); } else { $success = 1; } } # Manual removal. unless ($success) { my $dupname = "/etc/inittab.chiliasp-uninstall"; unlink($dupname); if (copy("/etc/inittab",$dupname)) { return(error("Unable to make copy of the system inittab file, bailing ...", "Sun Chili!Soft ASP could not successfully disable auto start on", "system boot.")); } local *SRC; local *INITTAB; unless(open(SRC,"<$dupname") && open(INITTAB,">/etc/inittab")) { # Back out any changes. close(SRC); close(INITTAB); unlink($script_path); if (unlink("/etc/inittab")) { unless(rename($dupname,"/etc/inittab")) { if (copy($dupname,"/etc/inittab")) { # Egads ... return(error("Aiyeee, unable to restore system inittab. $dupname contains a duplicate of the original information.")); } } } else { unlink($dupname); } return(error("Unable to remove $script_name from the system inittab file.", "Sun Chili!Soft ASP could not successfully disable auto start on", "system boot.", "")); } foreach my $line () { unless ($line =~ m@^\s*$reboot_tag:@) { print INITTAB ($line); } } close(INITTAB); report("Note: Manual modification of the system inittab was successful."); } return(1); } #------------------------------------------------------------------------------ # HP-UX #------------------------------------------------------------------------------ sub install_HPUX_Default { ($#_ == 5) || die "Invalid number of arguments."; my ($script_name, $start_script, $stop_script, $status_script, $start_priority, $stop_priority) = @_; my %substitute = ( reboot::script_name => $script_name, reboot::start_script => $start_script, reboot::stop_script => $stop_script, reboot::status_script => $status_script, reboot::start_priority => $start_priority, reboot::stop_priority => $stop_priority ); my $script_dir = "/sbin/init.d"; if (not -d $script_dir) { INSTALL::common::mkpath($script_dir) || return(error("Unable to create reboot path $script_dir")); } my $script_path = "$script_dir/$script_name"; my $RCFile = retrieve_RCFile; unlink($script_path); INSTALL::substitute::string_to_file ({ map { ("<<$_>>" => $substitute{$_}) } keys %substitute }, $script_path, $RCFile ); chmod(0755,$script_path); my $source = "../init.d/$script_name"; # Generate start links. - Initiate auto-start at level 2 foreach (2) { my $rc_dir= "/sbin/rc$_.d"; my $destination = "$rc_dir/S$start_priority$script_name"; mkpath($rc_dir,755); unlink($destination); unless(symlink($source,$destination)) { uninstall_script($script_name,$start_priority,$stop_priority); return(error("Unable to make symlink from $source to $destination.\n")); } } # Generate kill links. foreach (0 .. 4) { my $rc_dir= "/sbin/rc$_.d"; my $destination = "$rc_dir/K$stop_priority$script_name"; mkpath($rc_dir,755); unlink($destination); unless(symlink($source,$destination)) { uninstall_script($script_name,$start_priority,$stop_priority); return(error("Unable to make symlink from $source to $destination.\n")); } } return(1); } sub uninstall_HPUX_Default { ($#_ == 2) || die "Invalid number of arguments."; my ($script_name,$start_priority, $stop_priority) = @_; unlink("/sbin/init.d/$script_name"); foreach (0 .. 4) { unlink("/sbin/rc$_.d/K$stop_priority$script_name"); unlink("/sbin/rc$_.d/S$start_priority$script_name"); } return(1); } #============================================================================== #------------------------------------------------------------------------------ ####################################################### Helper methods. #------------------------------------------------------------------------------ #============================================================================== sub encode_names { my @names = @_; # Remove any non-supported symbols from the name. if (wantarray) { return(map { s/[^A-Za-z0-9_]//g; $_; } @names); } else { ($#names == 0) || die "Cannot return list to scalar."; $names[0] =~ s/[^A-Za-z0-9_]//g; return($names[0]); } } #============================================================================== #------------------------------------------------------------------------------ ####################################################### User-accessible scripts #------------------------------------------------------------------------------ #============================================================================== sub install_script { # Invoke the appropriate install_script function for the appropriate OS, # distribution, etc. using the following rules: # If a function exists by the name install__, use that function, else # If a function exists by the name install__, use that function, else # If a function exists by the name install__Default, use that function, else # return(undef) my $base_function = encode_names("install_$pOS->{os}_"); my @attempts = encode_names($pOS->{distribution},$pOS->{distribution_flavor},"Default"); foreach(@attempts) { my $function = "$base_function$_"; if (defined &$function) { return(&$function(@_)); } } #--------------------------------------------------------------------------- # Non-supported platform / distribution. #--------------------------------------------------------------------------- return(undef); } sub uninstall_script { # Invoke the appropriate install_script function for the appropriate OS, # distribution, etc. using the following rules: # If a function exists by the name install__, use that function, else # If a function exists by the name install__, use that function, else # If a function exists by the name install__Default, use that function, else # return(undef) my $base_function = encode_names("uninstall_$pOS->{os}_"); my @attempts = encode_names($pOS->{distribution},$pOS->{distribution_flavor},"Default"); foreach(@attempts) { my $function = "$base_function$_"; if (defined &$function) { return(&$function(@_)); } } #--------------------------------------------------------------------------- # Non-supported platform / distribution. #--------------------------------------------------------------------------- return(undef); } 1;