#! /bin/sh #---------------------------------------------------------------------------- # system-devices-mount-usb - mount usb device # # Creation : 2003-11-14 fm # Last Update: $Id$ # # Copyright (c) 2001-2010 the eisfair team, team(at)eisfair(dot)org # # 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 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- #---------------------------------------------------------------------------- # print header #---------------------------------------------------------------------------- print_header () { clrhome mecho --info "Mount USB device" echo } #---------------------------------------------------------------------------- # mount USB device # input : $1 - device name # $2 - mount path # output: 0 - mount successful # 1 - mount unsuccessful #---------------------------------------------------------------------------- function mount_usb_drive () { _usb_option='auto' _usb_dev=$1 _usb_mountpath=$2 _usb_retval=1 echo # check mount points for DNAME in ${mountpath} ${_usb_mountpath} do if [ ! -d ${DNAME} ] then mkdir -p -m 0755 ${DNAME} fi done /bin/mount -t ${_usb_option} ${_usb_dev} ${_usb_mountpath} 2>/dev/null if [ $? -eq 0 ] then _mounted_with=`mount | grep "^${_usb_dev}" | awk '{ print $5 }'` mecho --info -n "Mount successful with option " mecho -n "'${_mounted_with}'" mecho --info -n ", path is " mecho -n "'${_usb_mountpath}'" mecho --info "." _usb_retval=0 else mecho --error "Mounting ${_usb_dev} to ${_usb_mountpath} with option ${_usb_option} failed." _usb_option='ntfs-3g' mecho --info "Trying mount with option ${_usb_option} instead ..." /bin/mount -t ${_usb_option} ${_usb_dev} ${_usb_mountpath} if [ $? -eq 0 ] then mecho --info "Mount successful with option ${_usb_option}, path is ${_usb_mountpath}." _usb_retval=0 else mecho --error "Mounting ${_usb_dev} to ${_usb_mountpath} with option ${_usb_option} failed." fi fi anykey return ${_usb_retval} } #---------------------------------------------------------------------------- # remove normal device(s) # input : $1 - device name #---------------------------------------------------------------------------- remove_drive () { _d_dev=$1 _d_idx=1 while [ ${_d_idx} -le ${maxnum} ] do eval _d_tmpdev="\$dev_${_d_idx}_name" echo "${_d_tmpdev}" | grep -q "^${_d_dev}[1-7]$" if [ $? -eq 0 ] then eval "dev_${_d_idx}_stat='blocked'" fi _d_idx=`expr ${_d_idx} + 1` done } #---------------------------------------------------------------------------- # remove RAW device # input : $1 - device name #---------------------------------------------------------------------------- remove_raw_drive () { _rd_dev=`echo $1 | sed 's/[1-7]//'` _rd_idx=1 while [ ${_rd_idx} -le ${maxnum} ] do eval _rd_tmpdev="\$dev_${_rd_idx}_name" echo "${_rd_tmpdev}" | grep -q "^${_rd_dev}$" if [ $? -eq 0 ] then eval "dev_${_rd_idx}_stat='blocked'" fi _rd_idx=`expr ${_rd_idx} + 1` done } #============================================================================ # main #============================================================================ . /var/install/include/eislib #exec 2>./mount-usb-drive-$$.log #set -x mountpath=/usb raidfile=/etc/raidtab tmpfile=/tmp/system-devices-mount-usb.$$ print_header mecho "Checking kernel version ..." case `uname -r` in 2.2.*) mecho --error "Error: you need kernel 2.4.x to mount an USB device." anykey exit 1 ;; esac mecho "Checking USB drivers ..." # load usb drivers /sbin/modprobe usb-storage >/dev/null 2>&1 /sbin/modprobe sd_mod >/dev/null 2>&1 /sbin/modprobe uhci >/dev/null 2>&1 /sbin/modprobe usb-uhci >/dev/null 2>&1 /sbin/modprobe usb-ohci >/dev/null 2>&1 /sbin/modprobe ehci-hcd >/dev/null 2>&1 sleep 3 if [ -z "`mount -t usbdevfs`" ] then /bin/mount -t usbdevfs usbdevfs /proc/bus/usb fi mecho "Looking up devices ..." for a in /dev/sd[a-o] do # check if device has already one mount-point dev_name=`basename ${a}` # get partition table fdisk -l ${a} | grep "^${a}" | sed 's#\*##' | awk '{ print $1":"$5":"$6, $7, $8, $9, $10, $11 }' \ >> ${tmpfile}.${dev_name} if [ -s ${tmpfile}.${dev_name} ] then dev_mounted=`mount | grep "^${a}[1-7]" | cut -d' ' -f1` if [ -z "${dev_mounted}" ] then echo "${a} :RAW device" >> ${tmpfile}.${dev_name}-raw fi else rm -f ${tmpfile}.${dev_name} break fi done # concatenate files ls -al ${tmpfile}.sd* >/dev/null 2>/dev/null if [ $? -eq 0 ] then cat ${tmpfile}.sd* | LANG=C sort > ${tmpfile} rm -f ${tmpfile}.sd* fi # remove already mounted devices from list if [ -s ${tmpfile} ] then while read line do if ! echo "${line}" | grep -q "Linux swap" then # not a swap partition, go on ... dev_name=`echo "${line}" | cut -d: -f1` touch ${tmpfile}.new # not already mounted, go on ... if ! mount | grep -q "^${dev_name} " then raid=1 if [ -f ${raidfile} ] then grep "^[^#].*[[:space:]]${dev_name}.*$" ${raidfile} raid=$? fi if [ ${raid} -ne 0 ] then # not in raid file, go on ... echo "${line}" >> ${tmpfile}.new fi fi fi done < ${tmpfile} fi if [ -f ${tmpfile}.new ] then mv ${tmpfile}.new ${tmpfile} fi u_exit=1 while [ ${u_exit} -eq 1 ] do print_header if [ -s ${tmpfile} ] then # devices found, go on... techo --begin '2 3r 2 10 2 30 2 23' techo --row "" --info "Nr" "" --info "Device" "" --info "Description" "" --info "Status" maxnum=`grep -c . ${tmpfile}` idx=1 while [ ${idx} -le ${maxnum} ] do eval "dev_${idx}_name=`sed -n "${idx}p" ${tmpfile} | cut -d: -f1`" eval devname="\$dev_${idx}_name" eval "dev_${idx}_desc=\"`sed -n "${idx}p" ${tmpfile} | awk -F: '{ print $2, $3 }'`\"" eval devdesc="\$dev_${idx}_desc" eval devstat="\$dev_${idx}_stat" if [ "${devstat}" = "" ] then eval "dev_${idx}_stat=`sed -n "${idx}p" ${tmpfile} | cut -d: -f4`" eval devstat="\$dev_${idx}_stat" fi if [ -z "${devstat}" ] then devstat='not mounted' eval "dev_${idx}_stat='${devstat}'" fi if [ "${devstat}" = "not mounted" ] then techo --row "" "${idx}" "" "${devname}" "" "${devdesc}" "" "${devstat}" else techo --row "" "${idx}" "" "${devname}" "" "${devdesc}" "" -warn "${devstat}" fi idx=`expr ${idx} + 1` done techo --end echo /var/install/bin/ask "Select" "" "1-${maxnum}" "^$=Return" "0=Exit" > /tmp/ask.$$ rc=$? devnbr="`cat /tmp/ask.$$`" rm -f /tmp/ask.$$ if [ ${rc} = 255 ] then devnbr=0 fi echo case ${devnbr} in '' ) # quit program u_exit=0 ;; 0 ) # exit program rm -f ${tmpfile}* exit 127 ;; * ) # mount device eval dev="\$dev_${devnbr}_name" eval stat="\$dev_${devnbr}_stat" if [ "${stat}" = 'blocked' -o "${stat}" = 'mounted' ] then # blocked mecho --error "Device cannot be mounted!" else # go on ... devname=`basename ${dev}` mount_usb_drive ${dev} ${mountpath}/${devname} if [ $? -eq 0 ] then devstat='mounted' eval "dev_${devnbr}_stat='${devstat}'" echo "${dev}" | grep -q "[1-7]" if [ $? -eq 0 ] then # partition, block raw device remove_raw_drive ${dev} else # raw device, block partitions remove_drive ${dev} fi fi fi sleep 2 ;; esac else mecho --warn "No mountable USB device found or all USB devices are already mounted!" u_exit=0 anykey fi done rm -f ${tmpfile} exit 0 #============================================================================ # end #============================================================================