~ubuntu-branches/ubuntu/maverick/checkbox/maverick

« back to all changes in this revision

Viewing changes to scripts/device_list

  • Committer: Bazaar Package Importer
  • Author(s): Marc Tardif
  • Date: 2010-04-06 14:17:46 UTC
  • Revision ID: james.westby@ubuntu.com-20100406141746-3dxqefo5j56dmbcg
Tags: 0.10
New upstream release (LP: #585132):
* Added media tests (LP: #397944)
* Added support for comments in templates.
* Added referer when sending submissions to Launchpad (LP: #550973)
* Added suggests to checkbox package in debian/control file (LP: #352740)
* Fixed udev_resource script to be more resilient (LP: #556824)
* Fixed cdimage_resource script to read casper.log (LP: #558728)
* Fixed reporting all resources found for a job (LP: #560948)
* Fixed stalling when using kdesudo to start backend (LP: #557443)
* Fixed starting the appropriate default browser on UNR (LP: #563050)
* Fixed ansi_parser script when outputting to stdout (LP: #560952)
* Fixed opening the report with the gconf preferred browser (LP: #562580)
* Fixed suspend_test to use relative time for wakealarm (LP: #349768)
* Fixed backend not getting terminated upon closing (LP: #553328)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/sh -e
2
 
TYPE="$1"
3
 
 
4
 
case $TYPE in
5
 
    maybe-floppy)
6
 
        logger -t list-devices "deprecated parameter maybe-floppy"
7
 
        TYPE=floppy
8
 
        ;;
9
 
    cd|disk|partition|floppy|maybe-usb-floppy|usb-partition) ;;
10
 
    *)
11
 
        echo "Usage: $0 cd|disk|partition|floppy|maybe-usb-floppy|usb-partition" >&2
12
 
        exit 2
13
 
        ;;
14
 
esac
15
 
 
16
 
if [ ! -d /sys/block ]; then
17
 
        exit 0
18
 
fi
19
 
if type udevadm >/dev/null 2>&1; then
20
 
        device_info () {
21
 
                udevadm info -q "$1" -p "$2" 2>/dev/null
22
 
        }
23
 
elif type udevinfo >/dev/null 2>&1; then
24
 
        device_info () {
25
 
                udevinfo -q "$1" -p "$2" 2>/dev/null
26
 
        }
27
 
else
28
 
        exit 0
29
 
fi
30
 
 
31
 
device_name () {
32
 
        local name
33
 
        if ! name="$(device_info name "$1")"; then
34
 
                name="$(printf %s "${1##*/}" | \
35
 
                        sed 's,!,/,g')"
36
 
        fi
37
 
        echo "/dev/$name"
38
 
}
39
 
 
40
 
is_sataraid () {
41
 
        grep -qs ^DMRAID- "$1/dm/uuid"
42
 
}
43
 
 
44
 
is_sataraid_partition () {
45
 
        # dmraid partitions are always slaved to another dm device
46
 
        for slave in "$1"/slaves/dm-*; do
47
 
                if [ -e "$slave" ]; then
48
 
                        return 0
49
 
                fi
50
 
        done
51
 
        return 1
52
 
}
53
 
 
54
 
if type dmraid >/dev/null 2>&1; then
55
 
        raiddevs="$(dmraid -r -c || true)"
56
 
else
57
 
        raiddevs=
58
 
fi
59
 
 
60
 
# cloned-and-hacked from partman-base/init.d/parted
61
 
part_of_sataraid () {
62
 
        local raiddev
63
 
        for raiddev in $raiddevs; do
64
 
                if [ "$(readlink -f "$raiddev")" = "$1" ]; then
65
 
                        return 0
66
 
                fi
67
 
        done
68
 
        return 1
69
 
}
70
 
 
71
 
syspaths=
72
 
scan_partition=false
73
 
case $TYPE in
74
 
    partition)
75
 
        for x in /sys/block/*/*[0-9]; do
76
 
                [ -d "$x" ] || continue
77
 
                syspaths="${syspaths:+$syspaths }$x"
78
 
        done
79
 
        for x in /sys/block/dm-*; do
80
 
                [ -d "$x" ] || continue
81
 
                (is_sataraid "$x" && is_sataraid_partition "$x") || continue
82
 
                syspaths="${syspaths:+$syspaths }$x"
83
 
        done
84
 
        TYPE=disk
85
 
        # Also allow misdetected USB devices
86
 
        scan_partition=:
87
 
        ;;
88
 
    usb-partition)
89
 
        for x in /sys/block/*/*; do
90
 
                [ -d "$x" ] || continue
91
 
                syspaths="${syspaths:+$syspaths }$x"
92
 
        done
93
 
        ;;
94
 
    *)
95
 
        for x in /sys/block/*; do
96
 
                [ -d "$x" ] || continue
97
 
                case $x in
98
 
                    /sys/block/dm-*)
99
 
                        if is_sataraid "$x" && is_sataraid_partition "$x"; then
100
 
                                continue
101
 
                        fi
102
 
                        ;;
103
 
                    *)
104
 
                        name="$(device_name "$x")"
105
 
                        if part_of_sataraid "$name"; then
106
 
                                continue
107
 
                        fi
108
 
                        ;;
109
 
                esac
110
 
                syspaths="${syspaths:+$syspaths }$x"
111
 
        done
112
 
        ;;
113
 
esac
114
 
for x in $syspaths; do
115
 
        devpath="${x#/sys}"
116
 
        match=false
117
 
        case $TYPE in
118
 
            floppy)
119
 
                # TODO ugly special case for non-IDE floppies
120
 
                case $devpath in
121
 
                    /block/fd[0-9]*)
122
 
                        match=:
123
 
                        ;;
124
 
                esac
125
 
                ;;
126
 
        esac
127
 
        if ! $match && [ "$TYPE" = cd ]; then
128
 
                if device_info env "$devpath" | grep -q '^ID_CDROM='; then
129
 
                        match=:
130
 
                fi
131
 
        fi
132
 
        if ! $match; then
133
 
                if device_info env "$devpath" | grep -q "^ID_TYPE=$TYPE"; then
134
 
                        match=:
135
 
                fi
136
 
        fi
137
 
        if ! $match && [ "$TYPE" = disk ]; then
138
 
                case $devpath in
139
 
                    /block/cciss\!*|/block/ida\!*|/block/rd\!*|/block/mmcblk*)
140
 
                        match=:
141
 
                        ;;
142
 
                    /block/dm-*)
143
 
                        # for now, we only understand dmraid
144
 
                        if is_sataraid "/sys$devpath"; then
145
 
                                match=:
146
 
                        fi
147
 
                        ;;
148
 
                esac
149
 
        fi
150
 
        # Some USB sticks and CD drives are misdetected as floppy
151
 
        # This allows to scan for those
152
 
        if ! $match && ( $scan_partition || [ "$TYPE" = maybe-usb-floppy ] ); then
153
 
                if device_info env "$devpath" | grep -q '^ID_BUS=usb' && \
154
 
                   device_info env "$devpath" | grep -q '^ID_TYPE=floppy'; then
155
 
                        match=:
156
 
                fi
157
 
        fi
158
 
        # Disk partitions, but only on USB drives
159
 
        if ! $match && [ "$TYPE" = usb-partition ]; then
160
 
                if device_info env "$devpath" | grep -q '^ID_BUS=usb' && \
161
 
                   device_info env "$devpath" | grep -q '^ID_TYPE=disk'; then
162
 
                        match=:
163
 
                fi
164
 
        fi
165
 
        if $match; then
166
 
                device_name "/sys$devpath"
167
 
        fi
168
 
done