Revision bad5ca1f snf-image-helper/tasks/50ChangePassword.in

b/snf-image-helper/tasks/50ChangePassword.in
8 8
### END TAST INFO
9 9

  
10 10
set -e
11
. @commondir@/common.sh
11
. "@commondir@/common.sh"
12 12

  
13 13
windows_password() {
14
    local target=$1
15
    local password=$2
14
    local target="$1"
15
    local password="$2"
16 16

  
17
    local tmp_unattend=`mktemp` || exit 1
18
    CLEANUP+=("rm $tmp_unattend")
17
    local tmp_unattend="$(mktemp)"
18
    add_cleanup rm "$tmp_unattend"
19 19

  
20 20
    echo -n "Installing new admin password..."
21 21

  
22 22
    local namespace="urn:schemas-microsoft-com:unattend"
23 23
    
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
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"
25 25

  
26
    cat $tmp_unattend > "$target/Unattend.xml"
26
    cat "$tmp_unattend" > "$target/Unattend.xml"
27 27
    echo done
28 28
}
29 29

  
30 30
linux_password() {
31
    local target=$1
32
    local password=$2
31
    local target="$1"
32
    local password="$2"
33 33

  
34
    local hash=$(@scriptsdir@/snf-passtohash.py $password)
35
    if [ ! -e ${target}/etc/shadow ]; then
34
    local hash=$("@scriptsdir@/snf-passtohash.py" "$password")
35
    if [ ! -e "$target/etc/shadow" ]; then
36 36
       log_error "No /etc/shadow found!" 
37 37
    fi
38 38
    
......
46 46
    fi
47 47

  
48 48
    for i in $(seq 0 1 $((${#users[@]}-1))); do
49
        local tmp_shadow=$(mktemp)
50
        CLEANUP+=("rm $tmp_shadow")
49
        local tmp_shadow="$(mktemp)"
50
        add_cleanup rm "$tmp_shadow"
51 51

  
52 52
        echo -n "Setting ${users[$i]} password..."
53 53
    
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
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"
57 57
        echo "done"
58 58
    done
59 59
}
......
67 67
fi
68 68

  
69 69
if [ "$SNF_IMAGE_TYPE" = "ntfsdump" ]; then
70
    windows_password $SNF_IMAGE_TARGET $SNF_IMAGE_PASSWORD
70
    windows_password "$SNF_IMAGE_TARGET" "$SNF_IMAGE_PASSWORD"
71 71
elif [ "$SNF_IMAGE_TYPE" = "extdump" ]; then
72
    linux_password $SNF_IMAGE_TARGET $SNF_IMAGE_PASSWORD
72
    linux_password "$SNF_IMAGE_TARGET" "$SNF_IMAGE_PASSWORD"
73 73
fi
74 74

  
75 75
echo "done"

Also available in: Unified diff