Package: service-wrapper
Version: 3.5.3-2
Severity: important
Tags: patch

Hi, the upstream source comes with sh.script.in, which is a template for an
init.d script to be customised by the end-application-developer.

I've written some build scripts to refactor it into an application-customisable
component (which, once customised, may be installed into /etc/init.d as part of
that application), and a large static daemon.sh, for inclusion in this package.

I've also included the example wrapper.conf, which is useful both as
documentation, and as an include for setting defaults.


-- System Information:
Debian Release: wheezy/sid
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable'), (500, 'stable'), (1, 
'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.32-5-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_GB.utf8, LC_CTYPE=en_GB.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages service-wrapper depends on:
ii  libc6                         2.11.2-11  Embedded GNU C Library: Shared lib
ii  libservice-wrapper-java       3.5.3-2    Jar daemon wrapper java libraries
ii  libservice-wrapper-jni        3.5.3-2    Jar daemon wrapper JNI libraries

service-wrapper recommends no packages.

service-wrapper suggests no packages.

-- no debconf information
>From 9a2c80239bc955186d541196aa88b8caf0c9f697 Mon Sep 17 00:00:00 2001
From: Ximin Luo <infini...@gmx.com>
Date: Sat, 9 Apr 2011 13:38:50 +0100
Subject: [PATCH] add wrapper shell scripts to package, also no need to export 
DEB_* vars

---
 debian/build-wrapper-scripts   |  145 ++++++++++++++++++++++++++++++++++++++++
 debian/rules                   |   18 +++--
 debian/service-wrapper.install |    3 +
 3 files changed, 159 insertions(+), 7 deletions(-)
 create mode 100755 debian/build-wrapper-scripts

diff --git a/debian/build-wrapper-scripts b/debian/build-wrapper-scripts
new file mode 100755
index 0000000..9669f2c
--- /dev/null
+++ b/debian/build-wrapper-scripts
@@ -0,0 +1,145 @@
+#!/bin/sh
+# Split up service-wrapper-java sh.script.in into a user-editable config
+# component that calls the static code, which needs not be modified.
+
+SRCSH="src/bin/sh.script.in"
+
+if [ ! -f "$SRCSH" ]; then echo >&2 "cwd has no $SRCSH"; exit 1; fi
+if [ ! -d "$BUILD_DIR" ]; then echo >&2 "BUILD_DIR not a directory, or unset: 
$BUILD_DIR"; exit 1; fi
+
+WRAPPER_SERVICE="$1"
+WRAPPER_CMD="$2"
+
+if [ -z "$WRAPPER_SERVICE" ]; then
+       WRAPPER_SERVICE="./daemon.sh"
+fi
+
+mk_init_d_template() {
+       {
+       sed -n -e "1,${2}p" "$SRCSH"
+       cat <<EOF
+
+if [ -f "/etc/default/\$APP_NAME" ]; then
+       . "/etc/default/\$APP_NAME"
+fi
+
+# WRAPPER_PREINIT START
+# WRAPPER_PREINIT END
+
+. "$WRAPPER_SERVICE"
+
+EOF
+       } | sed -e 's|^\(WRAPPER_CMD=\).*|\1"'"$WRAPPER_CMD"'"|g'
+}
+
+mk_daemon_sh() {
+       sed -n -e "1,${1}p" "$SRCSH"
+       cat <<'EOF'
+
+if [ -z "$WRAPPER_CONF" ]; then
+       echo >&2 "WRAPPER_CONF not set; abort"
+       exit 1
+fi
+
+EOF
+       sed -n -e "${2},\$p" "$SRCSH"
+}
+
+mk_make_wrapper_init_d_sh() {
+       cat <<'EOF2'
+#!/bin/sh
+# Create an application-specific init.d that uses service-wrapper to launch.
+
+QUIET=false
+PREINIT_SH=/dev/null
+
+# parse command line arguments
+case "$1" in
+-q|--quiet)
+       QUIET=true
+       ;;
+-h|--help)
+       echo >&2 "Usage: cat <PARAMS> | $0 [-q|--quiet]"
+       exit 1
+esac
+
+if ! $QUIET; then
+       cat >&2 <<EOF
+This script will generate an init.d that uses service-wrapper. I will now read
+from STDIN; please input your parameters in the following format:
+
+==== start of input stream ====
+APP_NAME
+APP_LONG_NAME
+APP_DESCRIPTION
+NAME1 VALUE1
+NAME2 VALUE2
+...
+NAMEn VALUEn
+
+PREINIT_SHELL_SCRIPT_LINE1
+PREINIT_SHELL_SCRIPT_LINE2
+...
+PREINIT_SHELL_SCRIPT_LINEn
+==== end of input stream ====
+
+where:
+
+APP_NAME: short system name of application, e.g. avahi-daemon, apache2
+       This is used to refer to scripts like /etc/default/APP_NAME
+APP_LONG_NAME: long name of application, e.g. Apache Web Server
+       This is used to refer to the application in messages for the end user.
+APP_DESCRIPTION: longer description for your application
+       This serves as documentation for the end user.
+NAMEn VALUEn: optional name-value pairs that set application-specific defaults
+       for service-wrapper variables. At run-time, these may be overridden by 
user
+       settings in /etc/default/APP_NAME. Note: a space separates NAME VALUE, 
not
+       an equals sign (=). Also, currently VALUE cannot contain "|".
+PREINIT_SHELL_SCRIPTn: at run-time, these commands will be run after init.d
+sources /etc/default/APP_NAME, to do further processing on any variables set.
+
+Please enter your input; press Ctrl-D when you are done:
+EOF
+fi
+
+# splice params
+
+SED_ARGS=""
+push_sed_expr() { SED_ARGS="$SED_ARGS -e '$1'"; }
+
+read APP_NAME
+push_sed_expr "s/@app.name@/$APP_NAME/g"
+
+read APP_LONG_NAME
+push_sed_expr "s/@app.long.name@/$APP_LONG_NAME/g"
+
+read APP_DESCRIPTION
+push_sed_expr "s/@app.description@/$APP_DESCRIPTION/g"
+
+while read ARG VAL; do
+       if [ -z "$ARG" ]; then break; fi
+       push_sed_expr 's|^\s*#\?\s*\('"$ARG"'=\).*|\1"'"$VAL"'"|g'
+done
+
+PREINIT_SH="$(tempfile)"
+cat - > "$PREINIT_SH"
+
+if ! $QUIET; then set -x; fi
+eval sed $SED_ARGS <<EOF | sed -e "/WRAPPER_PREINIT START/r$PREINIT_SH"
+EOF2
+       mk_init_d_template "$1" "$2"
+       echo EOF
+}
+
+
+sed -n -e '/^#--/=' "$SRCSH" | {
+
+read L1
+read L2
+
+mk_daemon_sh $L1 $L2 > "$BUILD_DIR/daemon.sh"
+chmod +x "$BUILD_DIR/daemon.sh"
+mk_make_wrapper_init_d_sh $L1 $L2 > "$BUILD_DIR/make-wrapper-init.d.sh"
+chmod +x "$BUILD_DIR/make-wrapper-init.d.sh"
+
+}
diff --git a/debian/rules b/debian/rules
index 470a219..1131b57 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,10 +1,12 @@
-#!/usr/bin/make -f 
+#!/usr/bin/make -f
 
 DH_VERBOSE=1
-CLASSPATH="/usr/share/java/junit4.jar:/usr/share/java/junit.jar:/usr/share/java/commons-collections.jar"
+DEB_HOST_ARCH     := $(shell dpkg-architecture -qDEB_HOST_ARCH)
+DEB_HOST_ARCH_CPU := $(shell dpkg-architecture -qDEB_HOST_ARCH_CPU)
+CLASSPATH         := 
/usr/share/java/junit4.jar:/usr/share/java/junit.jar:/usr/share/java/commons-collections.jar
+JAVA_HOME         := /usr/lib/jvm/default-java
 export CLASSPATH
-export DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)
-export DEB_HOST_ARCH_CPU := $(shell dpkg-architecture -qDEB_HOST_ARCH_CPU)
+export JAVA_HOME
 
 #DEB_DESTDIR=debian/acgvision-agent
 
@@ -38,6 +40,8 @@ build-indep-stamp:
        dh_testdir
        # Build the package
        jh_build
+       cd $(CURDIR) && BUILD_DIR=lib $(CURDIR)/debian/build-wrapper-scripts \
+         /usr/share/wrapper/daemon.sh /usr/sbin/wrapper
        touch $@
 
 clean:
@@ -63,7 +67,7 @@ binary-arch: build-arch
        dh_clean -k
        dh_install -a
        #jh_installlibs wrapper.jar -plibservice-wrapper-java
-       dh_installdocs -a 
+       dh_installdocs -a
        dh_installchangelogs -a
        dh_installman debian/wrapper.1
        #jh_depends
@@ -82,7 +86,7 @@ binary-arch: build-arch
 
 binary-indep: build-indep install-indep
        # Create the package here
-       dh_testdir 
+       dh_testdir
        dh_testroot -i
        dh_clean -k
        dh_install -i
@@ -112,5 +116,5 @@ post-clean:
        rm -f src/c/*.o
        rm -f bin/wrapper
 
-binary: binary-indep binary-arch 
+binary: binary-indep binary-arch
 .PHONY: build build-arch build-indep clean binary-indep binary-arch binary 
install-indep  post-clean
diff --git a/debian/service-wrapper.install b/debian/service-wrapper.install
index 46a0e53..328aaeb 100644
--- a/debian/service-wrapper.install
+++ b/debian/service-wrapper.install
@@ -1 +1,4 @@
 bin/wrapper usr/sbin/
+lib/daemon.sh usr/share/wrapper/
+lib/make-wrapper-init.d.sh usr/share/wrapper/
+conf/wrapper.conf usr/share/wrapper/
-- 
1.7.4.1

Reply via email to