All pastes #369509 Raw Edit

Miscellany

public text v1 · immutable
#369509 ·published 2007-02-23 21:58 UTC
rendered paste body
mount_storage() {
        cd /dev/discs
        for dev in disc*; do
                [ -f /tmp/.${dev}_id ] || {
                        echo ${INTERFACE}${PRODUCT} > /tmp/.${dev}_id
                        mount | grep /mnt/${dev} || (
                                [ -d /mnt/. ] || {
                                        mkdir -p /tmp/mnt
                                        ln -s /tmp/mnt /
                                }
                                cd $dev
                                fulldev="/dev$(ls -l "$dev" | sed -e 's/^.*\.\.//')"
                                for part in part*; do
                                        if [ $part != "part*" ] ; then
                                                path=/mnt/${dev}_${part##*part}
                                                mkdir -p ${path}
                                                mount ${fulldev}/${part} ${path}
                                        fi
                                done
                        )
                }
        done
}

umount_storage() {
        for tmp in /tmp/.*_id; do
                id=$(cat $tmp 2>&-)
                [ "${INTERFACE}${PRODUCT}" = "$id" ] && {
                        rm -f $tmp
                        disc=${tmp##*disc}
                        disc=${disc%%_id}
                        for disc in /mnt/disc${disc}*; do
                                umount -f $disc || umount -l $disc
                        done
                }
        done
}

[ -f /proc/bus/usb/devices ] || mount -t usbfs none /proc/bus/usb

case "$ACTION" in
        add)
                case "${INTERFACE%%/*}" in
                        8) mount_storage ;;
                esac
        ;;
        remove)
                case "${INTERFACE%%/*}" in
                        8) umount_storage ;;
                esac
        ;;
esac