[debian-edu-commits] [Git][debian-edu/debian-edu-config][master] sbin/update-hostname-from-ip: Simply if-then-else-clauses, reduce number of...

Mike Gabriel (@sunweaver) gitlab at salsa.debian.org
Mon Mar 21 06:57:16 GMT 2022



Mike Gabriel pushed to branch master at Debian Edu / debian-edu-config


Commits:
18fbe40e by Mike Gabriel at 2022-03-21T07:56:04+01:00
sbin/update-hostname-from-ip: Simply if-then-else-clauses, reduce number of exit calls, don't exit with non-zero exit code. Improve syslog messages if things fail. (Closes: #1006604).

- - - - -


2 changed files:

- debian/changelog
- sbin/update-hostname-from-ip


Changes:

=====================================
debian/changelog
=====================================
@@ -11,6 +11,10 @@ debian-edu-config (2.12.18) UNRELEASED; urgency=medium
       #1006362).
     - Silence stderr output if the artwork theme lacks a plymouth subfolder.
       This can be silently ignored and should not trouble Debian Edu admins.
+  * sbin/update-hostname-from-ip:
+    - Simply if-then-else-clauses, reduce number of exit calls, don't exit with
+      non-zero exitcode. Improve syslog messages if things fail. (Closes:
+      #1006604).
 
  -- Mike Gabriel <sunweaver at debian.org>  Sun, 20 Feb 2022 19:35:36 +0100
 


=====================================
sbin/update-hostname-from-ip
=====================================
@@ -14,6 +14,10 @@ onlyprint=false
 
 DNSDOMAIN=intern
 
+### IMPORTANT: We don't want this script to fail with a non-zero exitcode.
+###            All problems should be reported as warnings, not errors.
+###            See https://bugs.debian.org/1006604 for details.
+
 log() {
     $QUIET "$2"
     logger -t update-hostname-from-ip "$1"
@@ -56,8 +60,8 @@ sethostname() {
 	echo $hostname > /etc/hostname
 	log "info: changing hostname to $hostname based on $namesource"
     else
-	log "error: unable to set hostname to $hostname."
-	exit 1
+	log "warning: unable to set hostname to $hostname."
+	return -1
     fi
 }
 
@@ -108,11 +112,6 @@ fi
 if [ "$IP" ] ; then
     HOSTNAME=$(ip2hostname $IP)
     SOURCE="reverse DNS of $IP"
-elif $USEMAC ; then
-    HOSTNAME=$(ether2hostname $MAC)
-    SOURCE="hardware MAC address"
-else
-    exit 1
 fi
 
 if $USEMAC && [ -z "$HOSTNAME" ] ; then
@@ -123,7 +122,6 @@ fi
 if [ "$HOSTNAME" ]; then
     if $onlyprint ; then
 	echo $HOSTNAME
-	exit 0
     else
         # Already got the correct host name?
         if [ "$HOSTNAME" != "$(uname -n)" ] ; then
@@ -131,7 +129,7 @@ if [ "$HOSTNAME" ]; then
         fi
     fi
 else
-    exit 1
+    log "warning: failed to detect (and set) hostname from IP or MAC address"
 fi
 
 exit 0



View it on GitLab: https://salsa.debian.org/debian-edu/debian-edu-config/-/commit/18fbe40e9abae0c94147db10691ec145097505f3

-- 
View it on GitLab: https://salsa.debian.org/debian-edu/debian-edu-config/-/commit/18fbe40e9abae0c94147db10691ec145097505f3
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-edu-commits/attachments/20220321/b1ebc592/attachment-0001.htm>


More information about the debian-edu-commits mailing list