X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=src%2Finstall%2Bsetup%2Finstall%2Fmountdest.sh;h=749d4fa5e8df8ee10280eae4d7f07dcb1756d031;hb=4a8dc4556aed707286cf3930f57d62362d85a6f8;hp=3e4f4d3a533e21ed3e10207a5701229d7f559c6d;hpb=66294b6996788dfbd4cd29d0127fdcc8cad62ebe;p=people%2Fpmueller%2Fipfire-2.x.git diff --git a/src/install+setup/install/mountdest.sh b/src/install+setup/install/mountdest.sh index 3e4f4d3a53..749d4fa5e8 100644 --- a/src/install+setup/install/mountdest.sh +++ b/src/install+setup/install/mountdest.sh @@ -1,53 +1,113 @@ -#!/bin/sh +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007-2012 IPFire Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +# Set histchars to an empty string so we are able to replace an +# exclamation mark. +histchars= echo "Scanning for possible destination drives" -# scan IDE devices -echo "--> IDE" -for DEVICE in $(kudzu -qps -t 30 -c HD -b IDE | grep device: | cut -d ' ' -f 2 | sort | uniq); do - mount /dev/${DEVICE}1 /harddisk 2> /dev/null - if [ -n "$(ls /harddisk/ipfire-*.tbz2 2>/dev/null)" ]; then - umount /harddisk 2> /dev/null - echo "${DEVICE} is source drive - SKIP" - continue - else - umount /harddisk 2> /dev/null - echo -n "$DEVICE" > /tmp/dest_device - echo "${DEVICE} - yes, it is our destination" - exit 0 +function _mount() { + local what=${1} + + # Don't mount if the device does not exist. + [ -e "${what}" ] || return 1 + + mount ${what} /harddisk 2>/dev/null +} + +function _umount() { + umount -l /harddisk 2>/dev/null +} + +function check_source_drive() { + local device="/dev/${1}" + + local ret=1 + local dev + for dev in ${device} ${device}1; do + # Mount the device (if possible). + _mount ${dev} || continue + + if [ -n "$(ls /harddisk/ipfire-*.tlz 2>/dev/null)" ]; then + ret=0 fi -done -# scan USB/SCSI devices -echo "--> USB/SCSI" -for DEVICE in $(kudzu -qps -t 30 -c HD -b SCSI | grep device: | cut -d ' ' -f 2 | sort | uniq); do - mount /dev/${DEVICE}1 /harddisk 2> /dev/null - if [ -n "$(ls /harddisk/ipfire-*.tbz2 2>/dev/null)" ]; then - umount /harddisk 2> /dev/null - echo "${DEVICE} is source drive - SKIP" + _umount + + # Stop if the device has been detected as a source drive. + [ "${ret}" = "0" ] && break + done + + return ${ret} +} + +for path in /sys/block/*; do + device=$(basename ${path}) + + # Skip devices which cannot be used. + case "${device}" in + # Virtual devices. + loop*|ram*) continue - else - umount /harddisk 2> /dev/null - echo -n "$DEVICE" > /tmp/dest_device - echo "${DEVICE} - yes, it is our destination" - exit 1 + ;; + # Floppy. + fd*) + continue + ;; + esac + + # Replace any exclamation marks (e.g. cciss!c0d0). + device=${device//!/\/} + + # Guess if this could be a raid device. + for dev in ${device} ${device}p1; do + if [ -e "/dev/${dev}" ]; then + device=${dev} + break fi -done + done -# scan RAID devices -echo "--> RAID" -for DEVICE in $(kudzu -qps -t 30 -c HD -b RAID | grep device: | cut -d ' ' -f 2 | sort | uniq); do - mount /dev/${DEVICE}p1 /harddisk 2> /dev/null - if [ -n "$(ls /harddisk/ipfire-*.tbz2 2>/dev/null)" ]; then - umount /harddisk 2> /dev/null - echo "${DEVICE} is source drive - SKIP" - continue - else - umount /harddisk 2> /dev/null - echo -n "$DEVICE" > /tmp/dest_device - echo "${DEVICE} - yes, it is our destination" + echo "Checking ${device}" + if check_source_drive ${device}; then + echo " is source drive - skipping" + continue + fi + + # Found it. + echo " OK, this is it..." + echo -n "${device}" > /tmp/dest_device + + # Exit code table: + # 1: sda + # 2: RAID + # 10: nothing found + case "${device}" in + *p1|*c0d0) exit 2 - fi + ;; + *) + exit 1 + ;; + esac done -exit 10 # Nothing found +# Nothing found. +exit 10