Skip to content
Snippets Groups Projects
usb 1.89 KiB
Newer Older
  • Learn to ignore specific revisions
  • Alberto LIVIO BECCARIA's avatar
    Alberto LIVIO BECCARIA committed
    #!/bin/bash
    
    getconf() {
    	ESAME_USB=${args[1]}
    }
    
    # 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
            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
    		modprobe -r uas
                    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"
    	:
    }
    
    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
        else
    		echo "USBPEN: nothing to do"
    		pkill -ALRM bta-no-usbpen
    		riabilitamodulo
    	fi
    
        # 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')
    	start
    	;;
    'stop')
    	stop
    	;;
    'restart')
    	stop
    	start
    	;;
    *)
    	echo "Usage: $0 { start | stop | restart }";
    	exit 1;
    	;;
    esac
    exit 0