[yast-commit] r51180 - /trunk/printer/tools/modify_cupsd_conf
Author: jsmeix Date: Tue Sep 16 15:48:51 2008 New Revision: 51180 URL: http://svn.opensuse.org/viewcvs/yast?rev=51180&view=rev Log: Added support for the 'Listen/Port' keywords in cupsd.conf. Modified: trunk/printer/tools/modify_cupsd_conf Modified: trunk/printer/tools/modify_cupsd_conf URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/tools/modify_cupsd_conf?rev=51180&r1=51179&r2=51180&view=diff ============================================================================== --- trunk/printer/tools/modify_cupsd_conf (original) +++ trunk/printer/tools/modify_cupsd_conf Tue Sep 16 15:48:51 2008 @@ -17,8 +17,11 @@ echo "Without a new value, the current value is reported." 1>&2 echo "Supported keywords and possible new values are:" 1>&2 echo "Browsing [ On | Off ]" 1>&2 - echo "BrowseAllow [ all | none | @LOCAL | IP-address[/netmask] ]" 1>&2 + echo "BrowseAllow [ all | none | @LOCAL | host-address | network-address/netmask ]" 1>&2 echo "E.g.: BrowseAllow '@LOCAL 192.168.100.1 192.168.200.0/255.255.255.0'" 1>&2 + echo "Listen [ all | localhost | network-address ]" 1>&2 + echo "E.g.: Listen '192.168.100.0 192.168.200.0' (localhost is added automatically)" 1>&2 + echo " Listen 'localhost' (to have only 'Listen 127.0.0.1:631')" 1>&2 echo "There is a strict syntax for keywords and values:" 1>&2 echo "Case matters." 1>&2 echo "Multiple values for a keyword must be separated by space." 1>&2 @@ -73,7 +76,7 @@ fi } -# Function to deal with 'BrowseAllow [ all | none | @LOCAL | IP-address[/netmask] ]' +# Function to deal with 'BrowseAllow [ all | none | @LOCAL | host-address | network-address/netmask ]' BrowseAllow() { if test -n "$VALUE" then # If a value was specified, only 'all' or 'none' or '@LOCAL' (case sensitive) @@ -82,7 +85,7 @@ do if ! test "all" = "$V" -o "none" = "$V" -o "@LOCAL" = "$V" then # Test if value matches to IP-address syntax: if ! echo "$V" | egrep -q '^([0-9]{1,3}\.){3}[0-9]{1,3}(/([0-9]{1,2})|/(([0-9]{1,3}\.){3}[0-9]{1,3}))?$' - then echo "Only '$KEY [ all | none | @LOCAL | IP-address[/netmask] ]' is supported." 1>&2 + then echo "Only '$KEY [ all | none | @LOCAL | host-address | network-address/netmask ]' is supported." 1>&2 exit 4 fi fi @@ -133,9 +136,86 @@ fi } +# Function to deal with 'Listen [ all | localhost | network-address ]' +Listen() +{ if test -n "$VALUE" + then # If a value was specified, only 'all' or 'localhost' or one or more network-addresses are allowed: + if ! test "localhost" = "$VALUE" + then for V in $VALUE + do if ! test "all" = "$V" + then # Test if value matches to IP-address syntax: + if ! echo "$V" | egrep -q '^([0-9]{1,3}\.){3}[0-9]{1,3}$' + then echo "Only '$KEY [ all | network-address ]' or '$KEY localhost' is supported." 1>&2 + exit 4 + fi + fi + done + fi + # Determine if it listens on the domain socket: + LISTEN_DOMAIN_SOCKET_LINE="$( grep -i '^Listen.*/cups.sock' $CUPSDCONF | head -n 1 )" + # All existing active Port lines are deactivated (ignore case). + # Those lines are not removed because YaST does not support Port lines + # so that a remove would silently delete Port information: + sed -i.yast2save -e 's/^\(Port.*\)$/#\1/i' $CUPSDCONF + # Determine the first 'Listen' line (ignore case): + FIRST_LISTEN_LINE="$( sed -n -e '/Listen/I=' $CUPSDCONF | head -n 1 )" + # All existing active Listen lines are removed (ignore case). + # Those lines can be removed because YaST supports Listen lines + # (YaST shows the Listen entries in the "share printers" dialog) + # so that no Listen information is silently deleted: + sed -i -e '/^Listen.*/Id' $CUPSDCONF + # Append the mandatory 'Listen localhost' line (see http://www.cups.org/str.php?L2834 + # "What is *not* supported is a configuration where only a domain socket is enabled") + # below the first 'Listen' line (ignore case) + # to have the new Listen line at the matching place + # but if no 'Listen' line exists, append at the end of the file: + if test -n "$FIRST_LISTEN_LINE" + then sed -i -e "${FIRST_LISTEN_LINE}aListen localhost:631" $CUPSDCONF + else echo -en "\nListen localhost:631\n\n" >>$CUPSDCONF + fi + # Append a Listen line for the domain socket (if such a line was there): + if test -n "$LISTEN_DOMAIN_SOCKET_LINE" + then sed -i -e "/^Listen localhost/a$LISTEN_DOMAIN_SOCKET_LINE" $CUPSDCONF + fi + # Insert Listen lines before the 'Listen localhost' line + # to have the new Listen lines at the matching place + # and in the ordering of the values (needed for the test below): + for V in $VALUE + do if test "all" = "$V" + then V="*" + fi + if ! test "localhost" = "$V" + then sed -i -e "/^Listen localhost/i$KEY $V:631" $CUPSDCONF + fi + done + fi + # Report the resulting setting in any case: + # The 'tr ... [:blank:]' makes sure that all active Listen entries + # are found if there is more than one which is allowed. + # Remove trailing spaces (needed for the test below). + RESULT="$( grep -i "^$KEY " $CUPSDCONF | sed -e 's/:631//' -e 's/\*/all/' | tr -s '[:blank:]' ' ' | cut -s -d' ' -f2 | tr -s '\n' ' ' | sed -e 's/ *$//' )" + echo -n "$RESULT" + # For a nicer output on a terminal where stdout and stderr is mixed up, + # output a '\n' on stderr to get subsequent stuff (e.g. the shell prompt + # or an error message because of a failed test below) on a new line: + echo 1>&2 + # Test if the result is the expected one if a value was specified: + if test -n "$VALUE" + then if test "localhost" = "$VALUE" + then SPECIFIC_RESULT="$( echo "$RESULT" | sed -e 's/[^ ]*\/cups\.sock//' -e 's/ *$//' )" + else SPECIFIC_RESULT="$( echo "$RESULT" | sed -e 's/localhost.*//' -e 's/ *$//' )" + fi + if test "$SPECIFIC_RESULT" != "$VALUE" + then echo "Failed to set '$KEY $VALUE' in $CUPSDCONF." 1>&2 + exit 5 + fi + fi +} + case "$KEY" in Browsing) Browsing;; BrowseAllow) BrowseAllow;; + Listen) Listen;; *) echo "Ignoring keyword '$KEY'" 1>&2 exit 3 ;; esac -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
jsmeix@svn.opensuse.org