]>
Commit | Line | Data |
---|---|---|
70df8302 MT |
1 | ############################################################################### |
2 | # # | |
3 | # IPFire.org - A linux based firewall # | |
1d109fd2 | 4 | # Copyright (C) 2007-2013 IPFire Team <info@ipfire.org> # |
70df8302 MT |
5 | # # |
6 | # This program is free software: you can redistribute it and/or modify # | |
7 | # it under the terms of the GNU General Public License as published by # | |
8 | # the Free Software Foundation, either version 3 of the License, or # | |
9 | # (at your option) any later version. # | |
10 | # # | |
11 | # This program is distributed in the hope that it will be useful, # | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
14 | # GNU General Public License for more details. # | |
15 | # # | |
16 | # You should have received a copy of the GNU General Public License # | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
18 | # # | |
19 | ############################################################################### | |
ee78a5ef | 20 | |
9a3d3d95 MT |
21 | # Set histchars to an empty string so we are able to replace an |
22 | # exclamation mark. | |
23 | histchars= | |
24 | ||
ee78a5ef MT |
25 | echo "Scanning for possible destination drives" |
26 | ||
7837dadb MT |
27 | function _mount() { |
28 | local what=${1} | |
29 | ||
30 | # Don't mount if the device does not exist. | |
31 | [ -e "${what}" ] || return 1 | |
32 | ||
33 | mount ${what} /harddisk 2>/dev/null | |
34 | } | |
35 | ||
36 | function _umount() { | |
37 | umount -l /harddisk 2>/dev/null | |
38 | } | |
39 | ||
40 | function check_source_drive() { | |
41 | local device="/dev/${1}" | |
42 | ||
43 | local ret=1 | |
44 | local dev | |
45 | for dev in ${device} ${device}1; do | |
46 | # Mount the device (if possible). | |
47 | _mount ${dev} || continue | |
48 | ||
dbf157bb | 49 | if [ -n "$(ls /harddisk/ipfire-*.tlz 2>/dev/null)" ]; then |
7837dadb | 50 | ret=0 |
ee78a5ef | 51 | fi |
ee78a5ef | 52 | |
7837dadb MT |
53 | _umount |
54 | ||
55 | # Stop if the device has been detected as a source drive. | |
56 | [ "${ret}" = "0" ] && break | |
57 | done | |
58 | ||
59 | return ${ret} | |
60 | } | |
61 | ||
62 | for path in /sys/block/*; do | |
63 | device=$(basename ${path}) | |
64 | ||
65 | # Skip devices which cannot be used. | |
66 | case "${device}" in | |
67 | # Virtual devices. | |
68 | loop*|ram*) | |
56b548f1 | 69 | continue |
7837dadb MT |
70 | ;; |
71 | # Floppy. | |
72 | fd*) | |
73 | continue | |
74 | ;; | |
e8fff1df AF |
75 | # Cd/Tape. |
76 | sr*) | |
77 | continue | |
78 | ;; | |
7837dadb MT |
79 | esac |
80 | ||
9a3d3d95 | 81 | # Replace any exclamation marks (e.g. cciss!c0d0). |
212cab4f | 82 | device_=${device//!/\/} |
9a3d3d95 | 83 | |
7837dadb | 84 | # Guess if this could be a raid device. |
212cab4f | 85 | for dev in ${device_} ${device_}p1; do |
7837dadb MT |
86 | if [ -e "/dev/${dev}" ]; then |
87 | device=${dev} | |
88 | break | |
56b548f1 | 89 | fi |
7837dadb MT |
90 | done |
91 | ||
1d109fd2 AF |
92 | # Check if user want skip by commandline |
93 | if [ "$(grep "skipdst=${device_}" /proc/cmdline)" ]; then | |
94 | echo "${device_} was skipped via cmdline." | |
95 | continue | |
96 | fi | |
97 | ||
212cab4f AF |
98 | echo "Checking ${device_}" |
99 | if check_source_drive ${device_}; then | |
7837dadb MT |
100 | echo " is source drive - skipping" |
101 | continue | |
102 | fi | |
103 | ||
f6057233 AF |
104 | device_size=$(cat /sys/block/${device}/size) |
105 | if [ "${device_size}" = "0" ]; then | |
bbfb087e AF |
106 | echo " is empty - skipping" |
107 | continue | |
108 | fi | |
109 | ||
7837dadb MT |
110 | # Found it. |
111 | echo " OK, this is it..." | |
212cab4f AF |
112 | echo -n "${device_}" > /tmp/dest_device |
113 | ||
2ae5ed5d AF |
114 | if [ ${device_size} -gt 0 ]; then |
115 | # Disk size to GiB. | |
116 | device_size=$(( ${device_size} / 2097152 )) | |
117 | ||
118 | # Build string with drive details | |
119 | device_str="/dev/${device_} - ${device_size} GiB -" | |
120 | else | |
121 | device_str="/dev/${device_} -" | |
122 | fi | |
f6057233 AF |
123 | device_str="${device_str} $(cat /sys/block/${device}/device/vendor)" |
124 | device_str="${device_str} $(cat /sys/block/${device}/device/model)" | |
125 | ||
126 | # Remove all whitespace. | |
127 | device_str=$(echo ${device_str}) | |
128 | ||
129 | echo -n "${device_str}" > /tmp/dest_device_info | |
7837dadb MT |
130 | |
131 | # Exit code table: | |
132 | # 1: sda | |
133 | # 2: RAID | |
134 | # 10: nothing found | |
212cab4f | 135 | case "${device_}" in |
9a3d3d95 | 136 | *p1|*c0d0) |
7837dadb MT |
137 | exit 2 |
138 | ;; | |
139 | *) | |
140 | exit 1 | |
141 | ;; | |
142 | esac | |
56b548f1 MT |
143 | done |
144 | ||
7837dadb MT |
145 | # Nothing found. |
146 | exit 10 |