]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/install+setup/install/mountdest.sh
Merge branch 'thirteen' of git.ipfire.org:/pub/git/ipfire-2.x 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 echo "Scanning for possible destination drives"
22
23 function _mount() {
24 local what=${1}
25
26 # Don't mount if the device does not exist.
27 [ -e "${what}" ] || return 1
28
29 mount ${what} /harddisk 2>/dev/null
30 }
31
32 function _umount() {
33 umount -l /harddisk 2>/dev/null
34 }
35
36 function check_source_drive() {
37 local device="/dev/${1}"
38
39 local ret=1
40 local dev
41 for dev in ${device} ${device}1; do
42 # Mount the device (if possible).
43 _mount ${dev} || continue
44
45 if [ -n "$(ls /harddisk/ipfire-*.tlz 2>/dev/null)" ]; then
46 ret=0
47 fi
48
49 _umount
50
51 # Stop if the device has been detected as a source drive.
52 [ "${ret}" = "0" ] && break
53 done
54
55 return ${ret}
56 }
57
58 for path in /sys/block/*; do
59 device=$(basename ${path})
60
61 # Skip devices which cannot be used.
62 case "${device}" in
63 # Virtual devices.
64 loop*|ram*)
65 continue
66 ;;
67 # Floppy.
68 fd*)
69 continue
70 ;;
71 esac
72
73 # Guess if this could be a raid device.
74 for dev in ${device} ${device}p1; do
75 if [ -e "/dev/${dev}" ]; then
76 device=${dev}
77 break
78 fi
79 done
80
81 echo "Checking ${device}"
82 if check_source_drive ${device}; then
83 echo " is source drive - skipping"
84 continue
85 fi
86
87 # Found it.
88 echo " OK, this is it..."
89 echo -n "${device}" > /tmp/dest_device
90
91 # Exit code table:
92 # 1: sda
93 # 2: RAID
94 # 10: nothing found
95 case "${device}" in
96 *p1)
97 exit 2
98 ;;
99 *)
100 exit 1
101 ;;
102 esac
103 done
104
105 # Nothing found.
106 exit 10