#!/bin/sh
# This script extracts the admin user's password hash from VPD

shell="$1"
pwhash=$(jq -r '."factory-password-hash"' /run/system.json)

if [ -z "$pwhash" ] || [ "$pwhash" = "null" ]; then
    # Do not fail, lock account instead.  This way developers can enable
    # root account login at build-time to diagnose the system.
    password=""
    rc=1
else
    password="\"password\": \"$pwhash\","
    rc=0
fi

cat <<EOF
{
  "ietf-system:system": {
    "authentication": {
      "user": [
       {
          "name": "admin",
	  ${password}
	  "infix-system:shell": "$shell"
       }
      ]
    }
  }
}
EOF

exit $rc
