summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorGunnar Wrobel <wrobel@gentoo.org>2007-02-21 22:11:48 +0000
committerGunnar Wrobel <wrobel@gentoo.org>2007-02-21 22:11:48 +0000
commitd3ea96e12549b4f75e314418de97a6820a07466f (patch)
treec6443803a46269a49cc0bf92cc6d61b6288f6fe6 /sbin
downloadwebapp-config-d3ea96e12549b4f75e314418de97a6820a07466f.tar.gz
webapp-config-d3ea96e12549b4f75e314418de97a6820a07466f.tar.bz2
webapp-config-d3ea96e12549b4f75e314418de97a6820a07466f.zip
Added current version
svn path=/trunk/webapp-config/; revision=2
Diffstat (limited to 'sbin')
-rwxr-xr-xsbin/webapp-cleaner144
-rwxr-xr-xsbin/webapp-config44
2 files changed, 188 insertions, 0 deletions
diff --git a/sbin/webapp-cleaner b/sbin/webapp-cleaner
new file mode 100755
index 0000000..d7ded2c
--- /dev/null
+++ b/sbin/webapp-cleaner
@@ -0,0 +1,144 @@
+#!/bin/bash
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+PN=
+
+ACTION=
+PRETEND=
+
+CMD="emerge -Cav"
+WEBAPP_DIR="/usr/share/webapps"
+WEBAPP_CONFIG=
+
+[[ -z ${RC_GOT_FUNCTIONS} ]] && source /sbin/functions.sh
+
+function help() {
+ echo "Remove obsolete and unused versions of web applications"
+ echo
+ echo "Usage:"
+ echo " $0 [options] [action] app_name"
+ echo
+ echo "Options:"
+ echo " -p, --pretend"
+ echo " Instead of cleaning, simply show the commands to be executed"
+ echo
+ echo "Actions:"
+ echo " -P, --prune"
+ echo " Removes all but the latest version of a package. Similar to"
+ echo " emerge --prune"
+ echo
+ echo " -C, --clean-unused"
+ echo " Removes all versions of a web application that have not been"
+ echo " installed into a virtual host"
+ echo
+ echo " -h, --help"
+ echo " Displays this help message"
+ echo
+ echo "If multiple actions are given, only the action specified last will"
+ echo "be executed"
+}
+
+function sanity_checks() {
+ WEBAPP_CONFIG=$(which webapp-config)
+ if [ "${WEBAPP_CONFIG}x" == "x" ]; then
+ eerror "webapp-config not found"
+ exit 1
+ fi
+
+ if [[ -z "${ACTION}" ]]; then
+ eerror "Please specify a valid action"
+ exit 1
+ fi
+
+ if [[ -z ${PN} && ${ACTION} != "help" ]]; then
+ eerror "Please specify a web application to be cleaned"
+ exit 1
+ fi
+
+ if [[ ! -d "${WEBAPP_DIR}/${PN}" ]]; then
+ eerror "${PN} not found"
+ exit 1
+ fi
+
+}
+
+
+function prune() {
+
+ if [[ $(ls -1 "${WEBAPP_DIR}/${PN}" | wc -l) == "1" ]]; then
+ einfo "Nothing to clean"
+ return
+ else
+ local BEST_VERSION=$(ls ${WEBAPP_DIR}/${PN} | sort -nr | head -n 1)
+ for x in $(ls ${WEBAPP_DIR}/${PN}); do
+ if [[ ${BEST_VERSION} != ${x} ]]; then
+ CMD="${CMD} =${PN}-${x}"
+ fi
+ done
+
+ einfo "Multiple versions of ${PN} detected."
+ if [[ -z ${PRETEND} ]]; then
+ einfo "Running ${CMD}"
+ ${CMD}
+ else
+ einfo "To prune, run the following command:"
+ einfo "${CMD}"
+ fi
+ fi
+}
+
+function clean_unused() {
+ local output=$(${WEBAPP_CONFIG} --lui ${PN})
+
+ if [[ -z ${output} ]] ; then
+ einfo "Nothing to clean"
+ return
+ else
+ CMD="${CMD} =${output}"
+ einfo "Unused versions of ${PN} detected."
+ if [[ -z ${PRETEND} ]]; then
+ einfo "Running ${CMD}"
+ ${CMD}
+ else
+ einfo "To clean, run the following command:"
+ einfo "${CMD}"
+ fi
+ fi
+}
+
+function process_opts() {
+
+ if [[ -z $1 ]]; then
+ help
+ exit 0
+ fi
+
+ while [ "$1+" != "+" ]; do
+ case "$1" in
+ -p|--pretend)
+ PRETEND="yes"
+ ;;
+ -P|--prune)
+ ACTION="prune"
+ ;;
+ -C|--clean-unused)
+ ACTION="clean_unused"
+ ;;
+ -h|--help)
+ ACTION="help"
+ ;;
+ *)
+ PN="$1"
+ ;;
+ esac
+
+ shift
+ done
+}
+
+process_opts $@
+
+sanity_checks
+
+${ACTION}
diff --git a/sbin/webapp-config b/sbin/webapp-config
new file mode 100755
index 0000000..7d30ba6
--- /dev/null
+++ b/sbin/webapp-config
@@ -0,0 +1,44 @@
+#!python
+#
+# /usr/sbin/webapp-config
+# Python script for managing the deployment of web-based
+# applications
+#
+# Originally written for the Gentoo Linux distribution
+#
+# Copyright (c) 1999-2005 Gentoo Foundation
+# Released under v2 of the GNU GPL
+#
+# Author(s) Stuart Herbert <stuart@gentoo.org>
+# Renat Lumpau <rl03@gentoo.org>
+# Gunnar Wrobel <php@gunnarwrobel.de>
+#
+# ========================================================================
+''' webapp-config is a powerful tool that allows you to install,
+upgrade, and remove web-based applications in a virtual-hosting
+environment. '''
+
+__version__ = "$Id: webapp-config 126 2005-11-05 23:26:48Z wrobel $"
+
+# ========================================================================
+# Dependencies
+# ------------------------------------------------------------------------
+
+from WebappConfig.config import Config
+
+def main():
+ '''
+ Main program call.
+ '''
+ # Get the configuration
+
+ config = Config()
+
+ config.parseparams()
+
+ # Handle the work
+
+ config.run()
+
+if __name__ == "__main__":
+ main()