summaryrefslogtreecommitdiffstats
path: root/rescue/Flash/scripts/clear_systemloop
blob: cd76fc7ebf86d37e0cbf8537d8c12a669c75da04 (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
#!/bin/bash

# import functions library
source rescue_common

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

function prepare() {

    mkdir -p $rootdir

    if ! mount_usbroot $rootdir; then
        return 1
    fi

    return 0
}

function doit() {

    clear
    echo
    echo "WARNING!"
    echo
    echo "Mandriva Flash will be reset to factory defaults!"
    echo -n "All user files, customizations and new packages installed "
    echo "will be removed."
    echo
    echo "This process may take a few minutes."
    echo
    echo -n "Do you want to continue? [N/y] "
    read confirm

    if [ x"$confirm" = x"y" -o x"$confirm" = x"Y" ]; then

        if [ ! -f $loop ] || [ x"$version" != x"1.0" ]; then
            dd if=/dev/zero of=$loop bs=1000 count=1000
        fi

        if [ x"$version" = x"1.0" ]; then
            /sbin/mkfs.ext2 -q -F $loop
        fi

        echo
        if [ $? -ne 0 ]; then
            echo 'Error resetting device to factory defaults'
            return 1
        else
            echo 'Mandriva Flash was restored to factory defaults!'
        fi
    fi

    echo

    return 0
}

function cleanup() {

    umount $rootdir > /dev/null 2>&1
    rmdir $rootdir $tmpdir 2> /dev/null
}

clear
trap cleanup SIGINT

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

if [ x"$version" = x"1.0" ]; then
    loop="$rootdir/loopbacks/system.loop"
else
    loop="$rootdir/.loopbacks/system.loop"
fi

if ! prepare; then
    cleanup
    exit 1
fi

if ! doit; then
    cleanup
    exit 1
fi

cleanup