While I am at writing a search logic for the init , I came to the conclusion, that the PMEDIA filter is really weird, and could need a better understandable one .
Any mistakes I have made ?
Code: Select all
#!/bin/sh
# Karl Reimer Godt April 2013
ERR=/dev/null ##change if required
ALLDRIVES=`ls -1 /sys/block | grep -vE 'ram|loop|mtd|md'`
for drive in $ALLDRIVES ; do
[ -f /sys/block/$drive/removable ] && read REMOVABLE </sys/block/$drive/removable
case $drive in
sd*)
[ "$REMOVABLE" = 0 ] && KIND=IntSata || KIND=ExtSata ;;
sr*)
[ "$REMOVABLE" = 1 ] && KIND=CdDvd || KIND=unknown ;;
fd*)
[ "$REMOVABLE" = 1 ] && KIND=Floppy || KIND=unknown ;;
hd*)
[ "$REMOVABLE" = 0 ] && KIND=IntIde || KIND=IdeCd ;;
scd*)
[ "$REMOVABLE" = 1 ] && KIND=ScsiCd || KIND=unknown ;;
mmc*)
[ "$REMOVABLE" = 1 ] && KIND=Card || KIND=unknown ;;
esac
[ -f /sys/block/$drive/device/vendor ] && read VEND </sys/block/$drive/device/vendor
[ -f /sys/block/$drive/device/model ] && read MODL </sys/block/$drive/device/model
[ "$VEND" ] || VEND=Unknown
[ "$MODL" ] || MODL=Unknown
PARTS=`ls -1 /sys/block/$drive/$drive[0-9]* 2>$ERR | grep -o -e '[0-9]*' |tr '\n' ' '`
echo "$drive|$KIND|$VEND $MODL|$PARTS"
done
Version 2 :sda|IntSata|ATA ST500DM002-1BD14|1 2 3 4 5 6 7 8 9
sdb|IntSata|ATA ST3250310AS|1 10 11 2 3 4 5 6 7 8 9
sdc|ExtSata|Mass Storage Device|1 2 3 5 6
sr0|CdDvd|PLDS DVD-ROM DH-16D3S|
sr1|CdDvd|HL-DT-ST DVD-RAM GH10L|
sr2|CdDvd|TSSTcorp CDDVDW SE-208AB|
Code: Select all
#!/bin/ash
# Karl Reimer Godt May, 2013
# Thanks to jamesbond, R-S-H, Ted Dog, vovchick.
# Different probedisk attempt to be used in
# the init script of the Puppy Linux initrd.gz
for p in $*
do
P=${p//-/}
case $P in
everything) EVERYTHING=YES;;
esac
done
if_then(){
if [ "$PMEDIA" = usb ] ; then
[ "$REMOVABLE" = 1 ] && PMEDIA=$1 || PMEDIA=$2
else
[ "$REMOVABLE" = 1 ] && PMEDIA=$3 || PMEDIA=$4
fi; }
ERR=/dev/null ##change if required ie ERR=/dev/stderr
QUIET='-q' ##change if required ie QUIET=''
alias ls='busybox ls'
alias sed='busybox sed'
alias grep='busybox grep'
alias readlink='busybox readlink'
for block_device in `ls -1d /sys/block/*` ; do
[ "$EVERYTHING" ] || { echo "$block_device" | grep $QUIET -E 'md|mtd|ram|loop|nbd' && continue; }
#RESET EVERYTHING
REMOVABLE='';VEND='';MODL='';MAMI='';PMEDIA='';SIZE=''
[ -f $block_device/removable ] && read REMOVABLE <$block_device/removable
READLINK=`readlink -f "$block_device"`
TNR=`echo "$READLINK" | grep -o -m1 -e '/target[0-9]*:' | tr -d '[[:alpha:][:punct:]]'`
echo "$READLINK" | grep $QUIET 'usb' && { REMOVABLE=1; PMEDIA=usb; }
case ${block_device##*/} in
sd*) if_then usbflash usbhd ataflash atahd ;;
sr*) if_then usbcd unknowncd atacd unknowncd ;;
fd*) if_then usbfd unknownfd genericfd unknownfd ;;
hd*) if_then usbidecd usbidehd idecd idehd ;;
scd*) if_then usbscsicd unknownscsi scsicd unknownscsi ;;
mmc*) if_then usbflashcard unknownusbflash cardflash cardflash ;;
loop*) if_then usbloopd usbloopd loopd loopd ;;
ram*) if_then usbramd usbramd ramd ramd ;;
md*) if_then usbraidhd usbraidhd raidhd raidhd ;;
mtd*) if_then usbrawflash usbrawflash rawflash rawflash ;;
nbd*) if_then usbnethd unknownusbnetd nethd unknownnet ;;
*) if_then removableusb fixedusb removable fixed ;;
esac
[ -f $block_device/device/vendor ] && read VEND <$block_device/device/vendor
[ -f $block_device/device/model ] && read MODL <$block_device/device/model
[ -f $block_device/size ] && read SIZE <$block_device/size
SIZE=$(( (SIZE*8*512) / (8*1000*1000) )) ##change to 1024 if you want
[ "$VEND" ] || VEND=Unknown
[ "$MODL" ] || MODL=Unknown
if [ "$EVERYTHING" ] ; then
[ -f $block_device/dev ] && read MAMI <$block_device/dev
PARTS=`ls -1 $block_device/${block_device##*/}[0-9]* 2>$ERR | grep -o -e '[0-9]*' |tr '\n' ' '`
if [ "`echo "${block_device}" | grep -E '/sd|/sr'`" ] ; then
echo
echo "$block_device|$SIZE MB|$PMEDIA|$MAMI|$VEND $MODL|$PARTS"
grep -A2 -w "scsi$TNR" /proc/scsi/scsi 2>$ERR
sed -n "/.*scsi$TNR/,/QUIRKS/p" /proc/scsi/usb-storage/$TNR 2>$ERR
if [ "`echo "${block_device}" | grep '/sr'`" ] ; then
INFO=`sed 's% %_%g' /proc/sys/dev/cdrom/info`
LINE=`echo "$INFO" | grep -m1 -w "${block_device##*/}"`
c=0;for item in $LINE ; do c=$((c+1)) ; [ "$item" = "${block_device##*/}" ] && break ; done
echo "$INFO" | tr '\t' ' ' | tr -s ' ' | cut -f1,$c -d ' '
fi
else
echo "$block_device|$SIZE MB|$PMEDIA|$MAMI|$VEND $MODL|$PARTS"
fi
else
echo "${block_device##*/}|$SIZE|$PMEDIA|$VEND $MODL"
fi
done