Package: backuppc
Version: 3.1.0-9
Severity: wishlist

Based on an idea by Hanspeter Kunz, please find attached a patch
against the init.d script to start an ssh-agent process for the
backuppc server process, with the goal to facilitate use of
encrypted SSH identities.

If there were a /etc/default/backuppc file, a variable therein could
further control this, or another means could be used to give users
the choice.

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

Kernel: Linux 2.6.36-trunk-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_NZ, LC_CTYPE=en_NZ.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash


-- 
 .''`.   martin f. krafft <madd...@d.o>      Related projects:
: :'  :  proud Debian developer               http://debiansystem.info
`. `'`   http://people.debian.org/~madduck    http://vcs-pkg.org
  `-  Debian - when you have better things to do than fixing systems
--- backuppc	2009-11-25 16:11:46.000000000 +0100
+++ /etc/init.d/backuppc	2010-11-03 17:43:36.495370715 +0100
@@ -51,9 +51,41 @@
     fi
 }
 
+check_or_start_ssh_agent()
+{
+    [ -x $(command -v ssh-agent) ] || return 0
+
+    [ -r /var/run/backuppc/ssh-agent.env ] && . /var/run/backuppc/ssh-agent.env >/dev/null
+
+    for i in $(pgrep -u $USER ssh-agent); do
+        # if the agent is still running, return
+        [ $i = $SSH_AGENT_PID ] && return 0
+    done
+
+    log_begin_msg "Starting ssh-agent for $NAME..."
+    su backuppc -c 'ssh-agent -s' 2>/dev/null >/var/run/backuppc/ssh-agent.env
+    log_end_msg $?
+    . /var/run/backuppc/ssh-agent.env >/dev/null
+}
+
+stop_ssh_agent()
+{
+    [ -r /var/run/backuppc/ssh-agent.env ] && . /var/run/backuppc/ssh-agent.env >/dev/null
+
+    for i in $(pgrep -u $USER ssh-agent); do
+        if [ $i = $SSH_AGENT_PID ]; then
+            log_begin_msg "Stopping ssh-agent for $NAME..."
+            kill -TERM $i
+            log_end_msg $?
+            rm -f /var/run/backuppc/ssh-agent.env
+            return 0
+        fi
+    done
+}
 
 case "$1" in
   start)
+    check_or_start_ssh_agent
     log_begin_msg "Starting $NAME..."
     check_old_config
     start-stop-daemon --start --pidfile /var/run/backuppc/BackupPC.pid \
@@ -65,8 +97,10 @@
     start-stop-daemon --stop --pidfile /var/run/backuppc/BackupPC.pid -u $USER \
 			    --oknodo --retry 30
     log_end_msg $?
+    stop_ssh_agent
       ;;
   restart)
+    check_or_start_ssh_agent
     log_begin_msg "Restarting $NAME..."
     start-stop-daemon --stop --pidfile /var/run/backuppc/BackupPC.pid -u $USER \
 			    --oknodo --retry 30

Attachment: digital_signature_gpg.asc
Description: Digital signature (see http://martin-krafft.net/gpg/)

Reply via email to