]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/install+setup/install/mountdest.sh
Merge remote-tracking branch 'origin/next' into thirteen
[people/teissler/ipfire-2.x.git] / src / install+setup / install / mountdest.sh
1 ###############################################################################
2 # #
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2007-2012 IPFire Team <info@ipfire.org> #
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 ###############################################################################
20
21 # Set histchars to an empty string so we are able to replace an
22 # exclamation mark.
23 histchars=
24
25 echo "Scanning for possible destination drives"
26
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
49 if [ -n "$(ls /harddisk/ipfire-*.tlz 2>/dev/null)" ]; then
50 ret=0
51 fi
52
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*)
69 continue
70 ;;
71 # Floppy.
72 fd*)
73 continue
74 ;;
75 # Cd/Tape.
76 sr*)
77 continue
78 ;;
79 esac
80
81 # Replace any exclamation marks (e.g. cciss!c0d0).
82 device_=${device//!/\/}
83
84 # Guess if this could be a raid device.
85 for dev in ${device_} ${device_}p1; do
86 if [ -e "/dev/${dev}" ]; then
87 device=${dev}
88 break
89 fi
90 done
91
92 echo "Checking ${device_}"
93 if check_source_drive ${device_}; then
94 echo " is source drive - skipping"
95 continue
96 fi
97
98 if [ $(cat /sys/block/${device}/size) == 0 ]; then
99 echo " is empty - skipping"
100 continue
101 fi
102
103 # Found it.
104 echo " OK, this is it..."
105 echo -n "${device_}" > /tmp/dest_device
106
107 # Build string with drive details
108 echo -n "/dev/${device_} (" > /tmp/dest_device_info
109 # size is in sectors (512 Bytes)
110 let DISK_SIZE=$(cat /sys/block/${device}/size)/2097152
111 echo -n "$DISK_SIZE GB - " >> /tmp/dest_device_info
112 echo -n "$(cat /sys/block/${device}/device/vendor) " >> /tmp/dest_device_info
113 echo -n "$(cat /sys/block/${device}/device/model) " >> /tmp/dest_device_info
114 echo -n "$(cat /sys/block/${device}/device/rev))" >> /tmp/dest_device_info
115
116 # Exit code table:
117 # 1: sda
118 # 2: RAID
119 # 10: nothing found
120 case "${device_}" in
121 *p1|*c0d0)
122 exit 2
123 ;;
124 *)
125 exit 1
126 ;;
127 esac
128 done
129
130 # Nothing found.
131 exit 10