4 # Provides: ChangePassword
5 # RunBefore: UmountImage
6 # RunAfter: InstallUnattend
7 # Short-Description: Changes Password for specified users
11 . "@commondir@/common.sh"
17 local tmp_unattend="$(mktemp)"
18 add_cleanup rm "$tmp_unattend"
20 echo -n "Installing new admin password..."
22 local namespace="urn:schemas-microsoft-com:unattend"
24 "$XMLSTARLET" ed -N x=$namespace -u "/x:unattend/x:settings/x:component/x:UserAccounts/x:AdministratorPassword/x:Value" -v "$password" "$target/Unattend.xml" > "$tmp_unattend"
26 cat "$tmp_unattend" > "$target/Unattend.xml"
34 local hash=$("@scriptsdir@/snf-passtohash.py" "$password")
35 if [ ! -e "$target/etc/shadow" ]; then
36 log_error "No /etc/shadow found!"
39 declare -a users=("root")
41 local distro=$(get_distro $target)
43 if [ "x$distro" = "xubuntu" -o \
44 "x$distro" = "xfedora" ] ; then
48 for i in $(seq 0 1 $((${#users[@]}-1))); do
49 local tmp_shadow="$(mktemp)"
50 add_cleanup rm "$tmp_shadow"
52 echo -n "Setting ${users[$i]} password..."
54 echo "${users[$i]}:$hash:15103:0:99999:7:::" > "$tmp_shadow"
55 grep -v "${users[$i]}" "$target/etc/shadow" >> "$tmp_shadow"
56 cat "$tmp_shadow" > "$target/etc/shadow"
61 if [ ! -d "$SNF_IMAGE_TARGET" ]; then
62 log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing"
65 if [ -z "$SNF_IMAGE_PASSWORD" ]; then
66 log_error "Password is missing"
69 if [ "$SNF_IMAGE_TYPE" = "ntfsdump" ]; then
70 windows_password "$SNF_IMAGE_TARGET" "$SNF_IMAGE_PASSWORD"
71 elif [ "$SNF_IMAGE_TYPE" = "extdump" ]; then
72 linux_password "$SNF_IMAGE_TARGET" "$SNF_IMAGE_PASSWORD"
82 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :