Bug 107675 - security/vpnc suggest rc.d script
Summary: security/vpnc suggest rc.d script
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Gabor Kovesdan
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-08 11:50 UTC by Dominic Fandrey
Modified: 2007-02-26 19:07 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dominic Fandrey 2007-01-08 11:50:12 UTC
Vpnc doesn't come with a proper rc.d script. I have one and I suggest it's merged into the port.

Fix: 

#!/bin/sh
#
# Author:	kamikaze
# Contact:	LoN_Kamikaze@gmx.de
#
# If vpnc_conf is defined, it will be treated as a list of configuration files
# in vpnc_conf_dir. This managed mode is useful where vpnc tunnels have
# to be established through other vpnc tunnels.
#

# PROVIDE: vpnc
# REQUIRE: NETWORKING
# KEYWORD: FreeBSD shutdown

# Default settings - don't change this.
: ${vpnc_enable="NO"}
: ${vpnc_flags=""}
: ${vpnc_conf=""}
# These values are only used when vpnc_conf is set.
: ${vpnc_pid_dir="/var/run"}
: ${vpnc_conf_dir="/usr/local/etc"}
: ${vpnc_record="$vpnc_pid_dir/vpnc.record"}

. /etc/rc.subr

name="vpnc"
rcvar=`set_rcvar`

command="/usr/local/sbin/$name"

vpnc_start() {
	if [ "$vpnc_conf" ]; then
		# Wait for the system to catch up. It's necessary to wait
		# a bit, if for example the device to tunnel through has
		# just been brought up.
		/bin/sleep 1

		# Make vpnc use random ports to allow multiple instances.
		vpnc_flags="$vpnc_flags --local-port 0"

		# A list of configurations is present. Connect managing
		# what is required for a clean shutdown later.
		for config in $vpnc_conf; {
			# The current configuration file.
			current="$vpnc_conf_dir/$config"
			# Start vpnc.
			$command $vpnc_flags $current

			# Give up on errors.
			status=$?
			if [ $status -ne 0 ]; then
				echo
				echo "Running 'vpnc $vpnc_flags $current' returned $status."
				return $status
			fi

			# Move files to allow a clean shutdown
			# of multiple connections.
			/bin/mv "$vpnc_pid_dir/vpnc.pid" "$vpnc_pid_dir/vpnc.$config.pid"
			/bin/mv "$vpnc_pid_dir/vpnc.defaultroute" "$vpnc_pid_dir/vpnc.$config.defaultroute" 2> /dev/null
			/bin/mv "$vpnc_pid_dir/vpnc.resolv.conf-backup" "$vpnc_pid_dir/vpnc.$config.resolv.conf-backup" 2> /dev/null
			echo "$config" >> "$vpnc_record"

			# Wait for the system to catch up.
			/bin/sleep 1
		}
	else
		# No configuration files given, run unmanaged.
		$command $vpnc_flags
		return $?
	fi
}

vpnc_stop() {
	if [ -e "$vpnc_record" ]; then
		# A record of vpnc connections is present. Attempt a
		# managed shutdown.
		for config in `/usr/bin/tail -r "$vpnc_record"`; {
			# Wait to give the system a chance to catch up with
			# recent changes.
			/bin/sleep 1

			# Move the vpnc files back into position.
			/bin/mv "$vpnc_pid_dir/vpnc.$config.pid" "$vpnc_pid_dir/vpnc.pid"
			/bin/mv "$vpnc_pid_dir/vpnc.$config.defaultroute" "$vpnc_pid_dir/vpnc.defaultroute" 2> /dev/null
			/bin/mv "$vpnc_pid_dir/vpnc.$config.resolv.conf-backup" "$vpnc_pid_dir/vpnc.resolv.conf-backup" 2> /dev/null

			# Run the disconnect command.
			$command-disconnect
		}
		# Remove the connection record.
		/bin/rm "$vpnc_record"
	else
		/bin/sleep 1
		# There's no record of connections, asume unmanaged shutdown.
		$command-disconnect
		return $?
	fi
}

start_cmd=vpnc_start
stop_cmd=vpnc_stop

load_rc_config $name
run_rc_command "$1"
Comment 1 Edwin Groothuis freebsd_committer 2007-01-08 11:50:23 UTC
State Changed
From-To: open->feedback

Awaiting maintainers feedback
Comment 2 Christian Lackas 2007-01-23 17:36:55 UTC
Hi Everyone,

thanks for the submission, the new start script looks good and works
fine. Please find attached a patch with a PREFIX-aware version of the
script as well as the required changes to the Makefile.
Please remove the old file in files/vpnc.sh.


Best regards,
 Christian (Maintainer)




diff -Nur /usr/ports/security/vpnc/Makefile vpnc/Makefile
--- /usr/ports/security/vpnc/Makefile	Sat Jul 29 22:41:30 2006
+++ vpnc/Makefile	Tue Jan 23 18:34:22 2007
@@ -7,7 +7,7 @@
 
 PORTNAME=	vpnc
 PORTVERSION=	0.3.3
-PORTREVISION=	3
+PORTREVISION=	4
 CATEGORIES=	security
 MASTER_SITES=	http://www.unix-ag.uni-kl.de/~massar/vpnc/
 
@@ -23,7 +23,7 @@
 		sbin/vpnc-script \
 		sbin/vpnc-disconnect \
 		etc/vpnc.conf.sample \
-		etc/rc.d/vpnc.sh.sample
+		etc/rc.d/vpnc
 
 PORTDOCS=	README ChangeLog TODO
 MAN8=		vpnc.8
@@ -41,9 +41,9 @@
 	@${INSTALL_PROGRAM} -m 751 ${WRKSRC}/vpnc ${PREFIX}/sbin/vpnc
 	@${INSTALL_SCRIPT} -m 751 ${WRKSRC}/vpnc-script ${PREFIX}/sbin/vpnc-script
 	@${INSTALL_SCRIPT} -m 751 ${WRKSRC}/vpnc-disconnect ${PREFIX}/sbin/vpnc-disconnect
-	@${INSTALL_SCRIPT} ${FILESDIR}/vpnc.sh ${WRKDIR}
-	@${REINPLACE_CMD} -e 's|%%PREFIX%%|${PREFIX}|' ${WRKDIR}/vpnc.sh
-	@${INSTALL_SCRIPT} -m 755 ${WRKDIR}/vpnc.sh ${PREFIX}/etc/rc.d/vpnc.sh.sample
+	@${INSTALL_SCRIPT} ${FILESDIR}/vpnc ${WRKDIR}
+	@${REINPLACE_CMD} -e 's|%%PREFIX%%|${PREFIX}|' ${WRKDIR}/vpnc
+	@${INSTALL_SCRIPT} -m 755 ${WRKDIR}/vpnc ${PREFIX}/etc/rc.d/vpnc
 	@${INSTALL_DATA} -m 600 ${WRKSRC}/vpnc.conf ${PREFIX}/etc/vpnc.conf.sample
 .if !defined(NO_INSTALL_MANPAGES)
 	@${REINPLACE_CMD} -e 's|%%PREFIX%%|${PREFIX}|' ${WRKSRC}/vpnc.8
diff -Nur /usr/ports/security/vpnc/files/vpnc vpnc/files/vpnc
--- /usr/ports/security/vpnc/files/vpnc	Thu Jan  1 01:00:00 1970
+++ vpnc/files/vpnc	Tue Jan 23 18:28:48 2007
@@ -0,0 +1,95 @@
+#!/bin/sh
+#
+# Author:	kamikaze
+# Contact:	LoN_Kamikaze@gmx.de
+#
+# If vpnc_conf is defined, it will be treated as a list of configuration files
+# in vpnc_conf_dir. This managed mode is useful where where vpnc tunnels have
+# to be established through other vpnc tunnels.
+#
+
+# PROVIDE: vpnc
+# REQUIRE: NETWORKING
+# KEYWORD: FreeBSD shutdown
+
+# Default settings - don't change this.
+: ${vpnc_enable="NO"}
+: ${vpnc_conf=""}
+: ${vpnc_pid_dir="/var/run"}
+: ${vpnc_conf_dir="%%PREFIX%%/etc"}
+: ${vpnc_flags=""}
+: ${vpnc_record="$vpnc_pid_dir/vpnc.record"}
+
+. /etc/rc.subr
+
+name="vpnc"
+rcvar=`set_rcvar`
+
+command="%%PREFIX%%/sbin/$name"
+
+vpnc_start() {
+	if [ "$vpnc_conf" ]; then
+		# A list of configurations is present. Connect managing
+		# what is required for a clean shutdown later.
+		for config in $vpnc_conf; {
+			# The current configuration file.
+			current="$vpnc_conf_dir/$config"
+			# Start vpnc.
+			$command $current $vpnc_flags
+
+			# Give up on errors.
+			status=$?
+			if [ $status -ne 0 ]; then
+				echo "Running 'vpnc $current $vpnc_flags' failed."
+				return $status
+			fi
+
+			# Move files to allow a clean shutdown
+			# of multiple connections.
+			/bin/mv "$vpnc_pid_dir/vpnc.pid" "$vpnc_pid_dir/vpnc.$config.pid"
+			/bin/mv "$vpnc_pid_dir/vpnc.defaultroute" "$vpnc_pid_dir/vpnc.$config.defaultroute" 2> /dev/null
+			/bin/mv "$vpnc_pid_dir/vpnc.resolv.conf-backup" "$vpnc_pid_dir/vpnc.$config.resolv.conf-backup" 2> /dev/null
+			echo "$config" >> "$vpnc_record"
+
+			# Wait for the system to catch up.
+			/bin/sleep 1
+		}
+	else
+		# No configuration files given, run unmanaged.
+		$command $vpnc_flags
+		return $?
+	fi
+}
+
+vpnc_stop() {
+	if [ -e "$vpnc_record" ]; then
+		# A record of vpnc connections is present. Attempt a
+		# managed shutdown.
+		for config in `/usr/bin/tail -r "$vpnc_record"`; {
+			# Wait to give the system a chance to catch up with
+			# recent changes.
+			/bin/sleep 1
+
+			# Move the vpnc files back into position.
+			/bin/mv "$vpnc_pid_dir/vpnc.$config.pid" "$vpnc_pid_dir/vpnc.pid"
+			/bin/mv "$vpnc_pid_dir/vpnc.$config.defaultroute" "$vpnc_pid_dir/vpnc.defaultroute" 2> /dev/null
+			/bin/mv "$vpnc_pid_dir/vpnc.$config.resolv.conf-backup" "$vpnc_pid_dir/vpnc.resolv.conf-backup" 2> /dev/null
+
+			# Run the disconnect command.
+			$command-disconnect
+		}
+		# Remove the connection record.
+		/bin/rm "$vpnc_record"
+	else
+		/bin/sleep 1
+		# There's no record of connections, asume unmanaged shutdown.
+		$command-disconnect
+		return $?
+	fi
+}
+
+start_cmd=vpnc_start
+stop_cmd=vpnc_stop
+
+load_rc_config $name
+run_rc_command "$1"







-- 
http://www.lackas.net/ Perl Delphi Linux MP3 Searchengines Domainchecker
http://www.spect-ct.com/
Comment 3 Gabor Kovesdan freebsd_committer 2007-02-19 12:04:59 UTC
State Changed
From-To: feedback->open

Maintainer approved. 


Comment 4 Gabor Kovesdan freebsd_committer 2007-02-19 12:04:59 UTC
Responsible Changed
From-To: freebsd-ports-bugs->gabor

Take.
Comment 5 dfilter service freebsd_committer 2007-02-26 18:57:47 UTC
gabor       2007-02-26 18:57:31 UTC

  FreeBSD ports repository

  Modified files:
    security/vpnc        Makefile 
  Added files:
    security/vpnc/files  vpnc.in 
  Removed files:
    security/vpnc/files  vpnc.sh 
  Log:
  - Update rc.d script
  - Use USE_RC_SUBR instead of direct patching
  - Bump PORTREVISION
  
  PR:             ports/107675
  Submitted by:   Dominic Fandrey <lon_kamikaze@gmx.de> (with fixes from maintainer)
  Approved by:    Christian Lackas <delta@lackas.net> (maintainer),
                  erwin (mentor, implicit)
  
  Revision  Changes    Path
  1.21      +4 -6      ports/security/vpnc/Makefile
  1.1       +95 -0     ports/security/vpnc/files/vpnc.in (new)
  1.4       +0 -29     ports/security/vpnc/files/vpnc.sh (dead)
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 6 Gabor Kovesdan freebsd_committer 2007-02-26 19:06:04 UTC
State Changed
From-To: open->closed

Committed with minor modification, thanks! For reinplace-editing 
the rc.d file the USE_RC_SUBR macro should be used.