[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#373976: apache2-common: a2dissite rewritten to allow globbing/multiple site disabling/includes man page



Package: apache2-common
Version: 2.0.54-5
Severity: normal
Tags: patch


I have modified a2dissite to :

1. disable multiple sites at a time, (including file globbing).
  (Both from the command-line, and from the "Site Name?" prompt)
2. modified the sites-enabled listing to be columnar, as opposed to space-delimited. 
  (Helps when you have hundreds of sites enabled).
3. allow for interactive or non-interactive modes, (using -f). 
  (interactive mode prompts for confirmation before disabling a site). 
4. generates a help message (-h).
5. I also wrote a man page "a2dissite(8)", which documents all of the features that
I have included in this revision:

.TH a2dissite "8" "June 2006" "a2dissite"
.SH NAME
a2dissite \- Disables Apache2 sites
.SH SYNOPSIS
.B a2dissite
[\fIOPTION\fR] [\fIFILE\fR] [\fIFILE\fR]...
.SH DESCRIPTION

.B a2dissite
simplifies the relationship between available and 
live, (or enabled), sites, by creating a user interface which controls
the creation of symbolic links between configuration files
in /etc/apache2/sites-available and /etc/apache2/sites-enabled.
.PP
.B a2dissite
allows you to pass the names of configuration files, (which exist
in /etc/apache2/sites-available), from the command line, or will
generate a listing of available sites if no arguments are given.  
(File globbing is available).
.PP
.SH OPTIONS
.TP
\fB\-f\fR
run in non-interactive mode, (do not prompt user for confirmation when enabling a site).
.TP
\fB\-h\fR
display help message and exit
.PP
.SH "EXAMPLES"
.PP
.B a2dissite
.PP
Generate a list of 
.B available 
sites and prompt for user to input a list of sites which they would like to disable.  
This runs a2dissite in default 
.B interactive 
mode, and will prompt the user for confirmation before disabling any site.
.PP
.B a2dissite -f
.PP
Same as previous example, except that it runs a2dissite in
.B non-interactive
mode. (It will not prompt the user for confirmation before
enabling a site).
.PP
.B a2dissite default
.PP
Enables the default site. (interactive mode)
.PP
.B a2dissite \-f default test2? test1
.PP
Enables the default site, plus test1, and all of the sites which 
match the globbing pattern test2?, (ie test20, test21, ... test29). (non-interactive mode)
.PP
.SH AUTHOR
This manual page was written by Shannon Eric Peevey <speeves@unt.edu>.
.PP
.SH "SEE ALSO"
a2ensite(8), a2enmod(8), a2dismod(8)



-- System Information:
Debian Release: 3.1
Architecture: i386 (i686)
Kernel: Linux 2.6.8-2-386
Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1)

Versions of packages apache2-common depends on:
ii  apache2-utils         2.0.54-5           utility programs for webservers
ii  debconf               1.4.30.13          Debian configuration management sy
ii  debianutils           2.8.4              Miscellaneous utilities specific t
ii  libc6                 2.3.2.ds1-22sarge3 GNU C Library: Shared libraries an
ii  libdb4.2              4.2.52-18          Berkeley v4.2 Database Libraries [
ii  libexpat1             1.95.8-3           XML parsing C library - runtime li
ii  libgcc1               1:3.4.3-13         GCC support library
ii  libmagic1             4.12-1             File type determination library us
ii  mime-support          3.28-1             MIME files 'mime.types' & 'mailcap
ii  net-tools             1.60-10            The NET-3 networking toolkit
ii  openssl               0.9.7e-3sarge1     Secure Socket Layer (SSL) binary a
ii  ssl-cert              1.0-11             Simple debconf wrapper for openssl

-- no debconf information
--- /home/speeves/a2dissite.orig	2006-06-16 09:56:06.767190640 -0500
+++ a2dissite	2006-06-16 06:39:43.000000000 -0500
@@ -1,29 +1,106 @@
 #!/bin/sh -e
 
+# Initialize variables
 SYSCONFDIR='/etc/apache2'
+prompt=1
+disabledsites=
+usage="
+Usage: ${0} [OPTION]...
 
+Options:
+ -f		Never prompt
+ -h		This message
+"
+
+while getopts ":ft" OPT
+do
+    case $OPT in
+	f )
+	    prompt=0
+	    ;;
+	h )
+	    echo "$usage"
+	    exit 1
+	    ;;
+	\?) 
+	    echo "$usage"
+            exit 1;;
+	esac
+done
+# remove the flags from $@
+shift $((${OPTIND} - 1))
+
+# If a2dissite is called without an argument, then
+# print a list of sites to choose from.  Multiple sites
+# can be passed to the SITENAME variable.
 if [ -z $1 ]; then
 	echo "Which site would you like to disable?"
-	echo -n "Your choices are: "
-	ls /etc/apache2/sites-enabled/* | \
-	sed -e "s,$SYSCONFDIR/sites-enabled/,,g" | xargs echo
+	echo "Your choices are: "
+	ls $SYSCONFDIR/sites-enabled/
 	echo -n "Site name? "
-	read SITENAME
+	read  SITENAME
 else
-	SITENAME=$1
+	SITENAME="$@"
 fi
 
-if [ $SITENAME = "default" ]; then
-        PRIORITY="000"
-fi
+delsite="n"
+# Loop through the site files in SITENAME
+for siteentry in $SITENAME
+do
+    # Set default site with top priority
+    ## 
+    if [ $siteentry = "default" ]; then
+	siteentry="000-default"
+    fi
 
-if ! [ -e $SYSCONFDIR/sites-enabled/$SITENAME -o \
-       -e $SYSCONFDIR/sites-enabled/"$PRIORITY"-"$SITENAME" ]; then
-	echo "This site is already disabled, or does not exist!"
-	exit 1
-fi
+    # Allow for file globbing
+    for site in $(ls $SYSCONFDIR/sites-enabled/$siteentry | xargs -n1 -r basename)
+    do
+
+        # Check to see if the site has already been disabled
+	if ! [ -e $SYSCONFDIR/sites-enabled/$site ]; then
+	    echo "$site is already disabled, or does not exist!"
+	    disabled=1
+	fi
 
-if ! rm $SYSCONFDIR/sites-enabled/$SITENAME 2>/dev/null; then
-	rm -f $SYSCONFDIR/sites-enabled/"$PRIORITY"-"$SITENAME"
+        # If -f flag is not passed to the script, prompt user for confirmation on each site.
+	if [ ${disabled:-0} -eq 0 ]; then
+	    if [ $prompt -eq 1 ]; then
+		delsitelast=$delsite
+		echo -n "a2dissite: disable $site? [${delsitelast}] "
+		read delsite
+
+		if [ "$delsite" = "" ]; then
+		    delsite=$delsitelast
+		fi
+
+		if [ ${delsite:-n} = "y" ]; then
+		    rm $SYSCONFDIR/sites-enabled/$site 2>/dev/null
+		    disabledsites="$disabledsites $site "
+		fi
+	    else
+		rm $SYSCONFDIR/sites-enabled/$site 2>/dev/null
+		disabledsites="$disabledsites $site "
+	    fi
+	fi
+	unset disabled
+    done
+done
+
+
+# Print list of disabled sites, if any
+# Test to see if any sites were disabled
+if [ ${#disabledsites} -gt 0 ]; then
+    echo "Following site(s) disabled: "
+    echo
+    for vhost in $disabledsites
+    do
+	echo "$vhost"
+    done
+    echo
+    echo "Run /etc/init.d/apache2 reload to fully disable."
+else
+    echo
+    echo "No sites were disabled."
 fi
-echo "Site $SITENAME disabled; run /etc/init.d/apache2 reload to fully disable."
+unset disabledsites
\ No newline at end of file

Reply to: