meta-ibm: update admin user home directory

currently admin user created with home directory '/' and there is an
error while deleting admin user.

this commit updates admin user home directory to /home/admin.

Tested by: Notice admin home directory and Delete admin user

Change-Id: I32210435ac0a94555d2f369e226df7e04f49d88c
Signed-off-by: Ravi Teja <raviteja28031990@gmail.com>
diff --git a/meta-ibm/recipes-phosphor/images/obmc-phosphor-image.bbappend b/meta-ibm/recipes-phosphor/images/obmc-phosphor-image.bbappend
index 92fa44a..a82f62c 100644
--- a/meta-ibm/recipes-phosphor/images/obmc-phosphor-image.bbappend
+++ b/meta-ibm/recipes-phosphor/images/obmc-phosphor-image.bbappend
@@ -52,7 +52,7 @@
 
 # Add the "admin" account.
 IBM_EXTRA_USERS_PARAMS += " \
-  useradd -M -d / --groups priv-admin,redfish,web -s /sbin/nologin admin; \
+  useradd --groups priv-admin,redfish,web -s /sbin/nologin admin; \
   usermod -p ${DEFAULT_OPENBMC_PASSWORD} admin; \
   "
 
diff --git a/meta-ibm/recipes-phosphor/user/phosphor-user-manager_%.bbappend b/meta-ibm/recipes-phosphor/user/phosphor-user-manager_%.bbappend
new file mode 100644
index 0000000..8667e28
--- /dev/null
+++ b/meta-ibm/recipes-phosphor/user/phosphor-user-manager_%.bbappend
@@ -0,0 +1,15 @@
+FILESEXTRAPATHS:prepend := "${THISDIR}/user:"
+
+inherit obmc-phosphor-systemd
+
+RDEPENDS:${PN} += "bash"
+
+
+SRC_URI += " file://update_admin_account.sh"
+SYSTEMD_SERVICE:${PN}:append = " update_admin_account.service"
+
+do_install:append() {
+  install -m 0755 ${WORKDIR}/update_admin_account.sh ${D}${bindir}/update_admin_account.sh
+}
+
+
diff --git a/meta-ibm/recipes-phosphor/user/user/update_admin_account.service b/meta-ibm/recipes-phosphor/user/user/update_admin_account.service
new file mode 100644
index 0000000..a43ff34
--- /dev/null
+++ b/meta-ibm/recipes-phosphor/user/user/update_admin_account.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Update admin user home directory
+Before=xyz.openbmc_project.User.Manager.service
+
+[Service]
+ExecStart={bindir}/update_admin_account.sh
+Type=oneshot
+RemainAfterExit=yes
+
+[Install]
+RequiredBy=xyz.openbmc_project.User.Manager.service
diff --git a/meta-ibm/recipes-phosphor/user/user/update_admin_account.sh b/meta-ibm/recipes-phosphor/user/user/update_admin_account.sh
new file mode 100644
index 0000000..91b1f61
--- /dev/null
+++ b/meta-ibm/recipes-phosphor/user/user/update_admin_account.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+# Purpose: creates /home/admin directory and updates admin user
+#          home directory to /home/admin
+
+# Update admin user home directory
+if id -u "admin" >/dev/null 2>&1; then
+    # admin user exists
+    homedir=$(grep '^admin:' /etc/passwd | cut -d: -f6)
+    if test "${homedir}" = "/"; then
+        echo "Changing admin user home directory"
+        mkdir -p /home/admin
+        chmod 0755 /home/admin
+        chown --recursive admin:admin /home/admin
+        usermod --home /home/admin admin
+    else
+        echo "admin user home directory is okay"
+    fi
+else
+    echo "admin user account is not present"
+fi