Skip to content
Snippets Groups Projects
usb 1.95 KiB
Newer Older
  • Learn to ignore specific revisions
  • Alberto LIVIO BECCARIA's avatar
    Alberto LIVIO BECCARIA committed
    #!/bin/bash
    
    # Un'idea alternativa sarebbe impedire il caricamento del modulo
    # usb-storage. Occorre pero' rimuoverlo dai moduli gia' caricati,
    # e fare qualcosa nel caso in cui sia impossibile rimuoverlo
    # (magari riavviare la macchina, ma al termine del processo per
    # lanciare l'esame).
    # echo 'install usb-storage : ' >> /etc/modprobe.conf
    
    smontaerimuovimodulo() {
    
        modprobe -r uas
        modprobe -r usb_storage
    
    Alberto LIVIO BECCARIA's avatar
    Alberto LIVIO BECCARIA committed
            while lsmod | grep usb_storage; do
                    cat /proc/mounts |grep "/run/media" | awk '{print $2}' | xargs -L 1 umount
                    echo "Can't remove usb_storage on `uname -n`, sleeping for 10 s"
                    sleep 10
    
    Alberto LIVIO BECCARIA's avatar
    Alberto LIVIO BECCARIA committed
                    modprobe -r usb_storage
            done
    }
    
    disabilitamodulo() {
            cat <<EOF_MODPROBE >/etc/modprobe.d/nousbpen.conf
    install usb_storage /bin/true
    EOF_MODPROBE
    }
    
    riabilitamodulo() {
            rm -f /etc/modprobe.d/nousbpen.conf
    }
    
    stop() {
    
        pkill -ALRM bta-no-usbpen
        riabilitamodulo
        echo "STOP ESAME-USB"
    
    Alberto LIVIO BECCARIA's avatar
    Alberto LIVIO BECCARIA committed
    }
    
    start() {
        echo "ESAME_USB = ${ESAME_USB}"
    
        if [ ${ESAME_USB} -eq 0 ]; then
            # Fedora 13
            #nohup udisks --inhibit -- /opt/esame/bin/bta-no-usbpen 999999 &
            nohup udisks --inhibit-all-polling -- /opt/esame/bin/bta-no-usbpen 999999 &
    
            smontaerimuovimodulo
            disabilitamodulo
    
    Alberto LIVIO BECCARIA's avatar
    Alberto LIVIO BECCARIA committed
        else
    
            echo "USBPEN: nothing to do"
            pkill -ALRM bta-no-usbpen
            riabilitamodulo
        fi
    
    Alberto LIVIO BECCARIA's avatar
    Alberto LIVIO BECCARIA committed
    
        # A new idea to test: a /etc/udev/rules.d file (but does it get
        # loaded if added after the boot, or does it requires a reboot,
        # and so it's useless for the lab?)
        # CAT <<EOF >/etc/udev/rules.d/10-bta-local.rules
        # ACTION=="add|change", SUBSYSTEM=="block", KERNEL=="sd[b-e]*|sr", ENV{UDISKS_PRESENTATION_HIDE}="1"
        # EOF
        #
    }
    
    args=("$@")
    
    case "$1" in
    'start')
    
    Alberto LIVIO BECCARIA's avatar
    Alberto LIVIO BECCARIA committed
    'stop')
    
    Alberto LIVIO BECCARIA's avatar
    Alberto LIVIO BECCARIA committed
    'restart')
    
    Alberto LIVIO BECCARIA's avatar
    Alberto LIVIO BECCARIA committed
    *)
    
        echo "Usage: $0 { start | stop | restart }";
        exit 1;
        ;;
    
    Alberto LIVIO BECCARIA's avatar
    Alberto LIVIO BECCARIA committed
    esac
    exit 0