summaryrefslogtreecommitdiffstats
path: root/rescue/Flash/scripts/reset_userpass
blob: d392ecd181fe573f8b2fc8ddbf7543b984144b62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash

# import functions library
source rescue_common

tmpdir="/tmp/flash-rescue-root"
rootdir="$tmpdir/pen"

function prepare() {

    modprobe unionfs > /dev/null 2>&1
    modprobe sqlzma > /dev/null 2>&1
    modprobe squashfs-lzma > /dev/null 2>&1
    modprobe squashfs > /dev/null 2>&1
    modprobe loop > /dev/null 2>&1

    mkdir -p $rootdir
    mkdir -p $tmpdir/squash
    mkdir -p $tmpdir/user
    mkdir -p $tmpdir/union

    if ! mount_usbroot $rootdir; then
        return 1
    fi

    mount -t squashfs -o loop $sfs_loop $tmpdir/squash > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        echo "Error mounting distrib.sqfs"
        return 1
    fi

    mount -t ext2 -o loop $sys_loop $tmpdir/user > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        echo "Error mounting system.loop"
        return 1
    fi

    mount -t unionfs -o dirs=$tmpdir/user=rw:$tmpdir/squash=ro \
        none $tmpdir/union > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        echo "Error creating union of distrib.sqfs and system.loop"
        return 1
    fi

    chroot $tmpdir/union /etc/init.d/keytable start &> /dev/null
    chroot $tmpdir/union /usr/bin/unicode_start

    return 0
}

function doit() {

    username=$(tail -1 $tmpdir/union/etc/passwd | cut -d ':' -f1)

    clear
    echo
    echo -n "What is your username? [$username] "
    read name

    if [ -z "$name" ]; then
        name="$username"
    fi

    echo
    echo
    chroot $tmpdir/union passwd $name
    echo
    echo

    return 0
}

function cleanup() {

    chroot $tmpdir/union /usr/bin/unicode_stop

    umount $tmpdir/union > /dev/null 2>&1
    lumount $tmpdir/user > /dev/null 2>&1
    lumount $tmpdir/squash > /dev/null 2>&1
    umount $rootdir > /dev/null 2>&1

    rmdir $tmpdir/union $tmpdir/user $tmpdir/squash 2> /dev/null
    rmdir $rootdir $tmpdir 2> /dev/null
}

clear
trap cleanup SIGINT

version=""
if ! insert_pendrive; then
    exit 1
fi

sys_loop="$rootdir$loopbacks_rel/system.loop"
sfs_loop="$rootdir$loopbacks_rel/distrib.sqfs"

if ! prepare; then
    cleanup
    exit 1
fi

if ! doit; then
    cleanup
    exit 1
fi

cleanup
exit 0