Revision cb9587b6

b/example/hooks/linux/root_passwd
7 7
set -e
8 8

  
9 9
. common.sh
10
. common_linux.sh
10 11

  
11 12
debug set -x
12 13

  
......
14 15

  
15 16
trap cleanup EXIT
16 17

  
18
declare -a USERS
19

  
20
USERS+=("root")
21

  
22
get_os ${TARGET}
23
if [ " $OPERATING_SYSTEM" = " ubuntu" ] ; then
24
    USERS+=("user")
25
fi
26

  
17 27
if [ -e ${TARGET}/etc/shadow ]; then
18
    echo "Setting root password... "
19
    SHADOW_TMP=$(mktemp --tmpdir=${TARGET}/etc)
20
    echo "root:$HASH:15103:0:99999:7:::" > $SHADOW_TMP
21
    grep -v "root" ${TARGET}/etc/shadow >> $SHADOW_TMP
22
    cat $SHADOW_TMP > ${TARGET}/etc/shadow
23
    CLEANUP+=("rm $SHADOW_TMP")
24
    echo "Root password changed successfully."
28

  
29
    for i in `seq 0 1 $((${#USERS[@]}-1))`; do
30
    
31
        TMP_SHADOW=$(mktemp)
32
        CLEANUP+=("rm $TMP_SHADOW")
33
    
34
        echo -n "Setting ${USERS[$i]} password..."
35
    
36
        echo "${USERS[$i]}:$HASH:15103:0:99999:7:::" > $TMP_SHADOW
37
        grep -v "${USERS[$i]}" ${TARGET}/etc/shadow >> $TMP_SHADOW
38
        cat $TMP_SHADOW > ${TARGET}/etc/shadow
39
        echo "done"
40
    
41
    done
42

  
25 43
    cleanup
26 44
    trap - EXIT
27 45
    exit 0
28 46
fi
29 47

  
30
echo "Couldn't change root password!"
48
echo "Password changes failed!!!"
49
exit 1
31 50

  
32
trap - EXIT
33
exit 0

Also available in: Unified diff