Fix minor typo in ChangePassword task
[snf-image] / snf-image-helper / tasks / 50ChangePassword.in
index d6f3771..54b3f76 100644 (file)
@@ -19,7 +19,7 @@
 
 ### BEGIN TASK INFO
 # Provides:            ChangePassword
-# RunBefore:            UmountImage
+# RunBefore:            EnforcePersonality
 # RunAfter:            InstallUnattend
 # Short-Description:   Changes Password for specified users
 ### END TASK INFO
 set -e
 . "@commondir@/common.sh"
 
+trap task_cleanup EXIT
+report_task_start
+
+# Check if the task should be prevented from running.
+check_if_excluded
+
 windows_password() {
     local target="$1"
     local password="$2"
@@ -34,6 +40,9 @@ windows_password() {
     echo "@echo off" > "$target/Windows/SnfScripts/ChangeAdminPassword.cmd"
 
     if [ -z "$SNF_IMAGE_PROPERTY_USERS" ]; then
+        warn "Image property \`USERS' is missing or empty. " \
+            "Changing the password for default user: \`Administrator'."
+
         SNF_IMAGE_PROPERTY_USERS="Administrator"
     fi
 
@@ -61,14 +70,9 @@ linux_password() {
             users+=("$usr")
         done
     else
+        warn "Image property \`USERS' is missing or empty. " \
+            "Changing the password for default user: \`root'."
         users+=("root")
-
-        local distro=$(get_distro $target)
-
-        if [ "x$distro" = "xubuntu" -o \
-             "x$distro" = "xfedora" ] ; then
-            users+=("user")
-        fi
     fi
 
     for i in $(seq 0 1 $((${#users[@]}-1))); do
@@ -76,6 +80,9 @@ linux_password() {
         add_cleanup rm "$tmp_shadow"
 
         echo -n "Setting ${users[$i]} password..."
+        if ! grep "^${users[$i]}:" "$target/etc/shadow" > /dev/null; then
+            log_error "User: \`${users[$i]}' does not exist."
+        fi
     
         echo "${users[$i]}:$hash:15103:0:99999:7:::" > "$tmp_shadow"
         grep -v "${users[$i]}" "$target/etc/shadow" >> "$tmp_shadow"
@@ -101,8 +108,6 @@ elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "linux" ]; then
     linux_password "$SNF_IMAGE_TARGET" "$SNF_IMAGE_PASSWORD"
 fi
 
-echo "done"
-
 exit 0
 
 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :