From d89b40e09c5753fabd5e642477c311b82ba82790 Mon Sep 17 00:00:00 2001
From: Bob Gilligan <gilligan@vyatta.com>
Date: Thu, 30 Jul 2009 13:53:48 -0700
Subject: Bugfix 4700:  Move processing to "end" field so that param
 modifications are handled.

In order to correctly handle cases where parameters are changed after a repository
configuration has been set up, we need to do the work in an "end" field instead
of a "create" field.  The "create" field is only executed when the node itself
is created, not when nodes below it are modified.
(cherry picked from commit e500a9e4494649e0ecb523d36b28452f2e9dd326)
---
 templates/system/package/repository/node.def | 31 ++++++++++++++++++----------
 1 file changed, 20 insertions(+), 11 deletions(-)

(limited to 'templates/system/package/repository/node.def')

diff --git a/templates/system/package/repository/node.def b/templates/system/package/repository/node.def
index 17d5d162..40504bf1 100644
--- a/templates/system/package/repository/node.def
+++ b/templates/system/package/repository/node.def
@@ -8,16 +8,25 @@ commit:expression: $VAR(./url/) != ""; "Must configure the repository URL"
 commit:expression: $VAR(./distribution/) != ""; "Must configure the repository distribution"
 commit:expression: $VAR(./components/) != ""; "Must configure the repository components"
 
-create: sudo bash -c "touch /etc/apt/sources.list && \
-	sed -i '\\!# $VAR(@) #!d' /etc/apt/sources.list && \
-	echo \"deb $VAR(url/@) $VAR(distribution/@) $VAR(components/@) # $VAR(@) #\" >> /tmp/$$-sources.list && \
-	if [ $VAR(password/@) ] || [ $VAR(username/@) ]; \
-	then \
+end:
+    if [ ${COMMIT_ACTION} = 'SET' -o ${COMMIT_ACTION} = 'ACTIVE' ]; then
+        if [ ${COMMIT_ACTION} = 'SET' ]; then
+	    echo "Adding new entry to /etc/apt/sources.list..."
+	else 
+	    echo "Updating /etc/apt/sources.list..."
+	fi   
+	sudo bash -c "touch /etc/apt/sources.list && \
+	    sed -i '\\!# $VAR(@) #!d' /etc/apt/sources.list && \
+	    echo \"deb $VAR(url/@) $VAR(distribution/@) $VAR(components/@) # $VAR(@) #\" >> /tmp/$$-sources.list && \
+	    if [ $VAR(password/@) ] || [ $VAR(username/@) ]; \
+		then \
 		sed -i "s!://.*@!://!" /tmp/$$-sources.list; \
 		sed -i "s!://!://$VAR(username/@):$VAR(password/@)@!" /tmp/$$-sources.list; \
-	fi && \
-	cat /tmp/$$-sources.list>>/etc/apt/sources.list ; \
-	rm -f /tmp/$$-sources.list"
-
-delete: sudo sh -c "touch /etc/apt/sources.list && \
-sed -i '\\!# $VAR(@) #!d' /etc/apt/sources.list"
+	     fi && \
+	     cat /tmp/$$-sources.list>>/etc/apt/sources.list ; \
+	     rm -f /tmp/$$-sources.list"
+    elif [ ${COMMIT_ACTION} = 'DELETE' ]; then
+	echo "Removing entry from /etc/apt/sources.list..."
+	sudo sh -c "touch /etc/apt/sources.list && \
+	    sed -i '\\!# $VAR(@) #!d' /etc/apt/sources.list"
+    fi
-- 
cgit v1.2.3

