#!/bin/sh # # VERSION 0.2 # # Author: Adalbert Prokop # # 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. # # 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, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # This script was originally written to make the Tevion USB Card Reader work # together with Fedora Core 2. # # This card reader uses LUNs 0-3 in the USB->SCSI emulation. # Those LUNs are not scanned by the FC2 kernel by default. It's more a quick # hack, than a good software, but it works fine for me. :) # # cardreader by Adalbert Prokop # 13.06.2004 sleep 2 declare -i DEVICECOUNT ID_LINE SCSI_HOST_LINE SCSI_HOST SCSI_CHANNEL SCSI_ID SCSI_LUN # which names are to be created in /dev CF=cardreadercf # compact flash MS=cardreaderms # media stick SM=cardreadersm # smart media SD=cardreadersd # secure disk / mmc device DEVICECOUNT=$(grep -c "Vendor: GENERIC Model: Card Reader" /proc/scsi/scsi) if [ $DEVICECOUNT -ge 4 ]; then # Enough! There are no more devices to detect! exit 0 fi # Find first line with the right card reader descriptor ID_LINE=$(grep -n "Vendor: GENERIC Model: Card Reader" /proc/scsi/scsi | head -n 1 | cut -d: -f1) if [ $ID_LINE -eq 0 ]; then echo "Error in $0. \$ID_LINE should never be zero!" exit 1 fi # The preceeding line holds the SCSI host number SCSI_HOST_LINE=$((${ID_LINE}-1)) # cut out the scsi? part (that is the second word) SCSI_HOSTNAME=$(head -n $SCSI_HOST_LINE /proc/scsi/scsi | tail -n 1 | cut -d" " -f 2) # delete the first four characters SCSI_HOST=${SCSI_HOSTNAME#scsi} SCSI_CHANNEL=0 SCSI_ID=0 # Finaly: add the other three devices with their LUNs! :) for SCSI_LUN in 1 2 3; do echo "scsi add-single-device $SCSI_HOST $SCSI_CHANNEL $SCSI_ID $SCSI_LUN" > /proc/scsi/scsi done # Create symlinks to those devices CF_DEV=$(basename $(readlink /sys/bus/scsi/devices/$SCSI_HOST\:$SCSI_CHANNEL\:$SCSI_ID\:0/block)) SM_DEV=$(basename $(readlink /sys/bus/scsi/devices/$SCSI_HOST\:$SCSI_CHANNEL\:$SCSI_ID\:1/block)) SD_DEV=$(basename $(readlink /sys/bus/scsi/devices/$SCSI_HOST\:$SCSI_CHANNEL\:$SCSI_ID\:2/block)) MS_DEV=$(basename $(readlink /sys/bus/scsi/devices/$SCSI_HOST\:$SCSI_CHANNEL\:$SCSI_ID\:3/block)) # remove old entries rm -f /dev/$CF /dev/$SM /dev/$SD /dev/$MS # make new links to first partition on each device ln -s /dev/${CF_DEV}1 /dev/$CF ln -s /dev/${SM_DEV}1 /dev/$SM ln -s /dev/${SD_DEV}1 /dev/$SD ln -s /dev/${MS_DEV}1 /dev/$MS # if we're given a filename for a remover script, generate one. # it will delete all symlinks to our scsi devices and remove entries in the scsi system if [ "$REMOVER" ]; then cat << EOF > ${REMOVER} #!/bin/bash rm -f /dev/$CF /dev/$SM /dev/$SD /dev/$MS for SCSI_LUN in 3 2 1 0; do echo "scsi remove-single-device $SCSI_HOST $SCSI_CHANNEL $SCSI_ID \$SCSI_LUN" > /proc/scsi/scsi done EOF chmod 755 ${REMOVER} fi