Fix AssignHostname task for arch linux
authorNikos Skalkotos <skalkoto@grnet.gr>
Fri, 4 Jan 2013 13:30:52 +0000 (15:30 +0200)
committerNikos Skalkotos <skalkoto@grnet.gr>
Fri, 4 Jan 2013 13:59:43 +0000 (15:59 +0200)
If both /etc/rc.conf and /etc/hostname are missing, create the latter
to host the hostname.

snf-image-helper/tasks/50AssignHostname.in

index 918a256..1b2d1a6 100644 (file)
@@ -62,7 +62,7 @@ linux_hostname() {
     hostname="$2"
 
     if [ -f "$target/etc/hostname" ]; then
-            echo "$hostname" > "$target/etc/hostname"
+        echo "$hostname" > "$target/etc/hostname"
     else
         distro=$(get_base_distro "$target")
         case "$distro" in
@@ -77,7 +77,13 @@ linux_hostname() {
             gentoo)
                 sed -ie "s/\(\(HOSTNAME\)\|\(hostname\)\)=.*$/\1=\"$hostname\"/" "$target/etc/conf.d/hostname";;
             arch)
-                sed -ie "s/^HOSTNAME=.*$/HOSTNAME=\"$hostname\"/" "$target/etc/rc.conf"
+                if [ -f "$target/etc/rc.conf" ]; then
+                    sed -ie "s/^HOSTNAME=.*$/HOSTNAME=\"$hostname\"/" "$target/etc/rc.conf"
+                else
+                    # In new versions of arch, /etc/rc.conf is missing
+                    echo "$hostname" > "$target/etc/hostname"
+                fi
+
                 if grep "^127\.0\.0\.1[ \t]*" "$target/etc/hosts" > /dev/null; then
                    sed -ie "s/127\.0\.0\.1[ \t]*.*$/127.0.0.1\t$hostname/" "$target/etc/hosts"
                 else