Advertisement
cyril2day2

OpenBSD hotplugd attach script

Apr 6th, 2020
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.14 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. DEVCLASS=$1
  4. DEVNAME=$2
  5. MOUNTROOT="/home/psi/USB"
  6. DEBUG=0
  7. NAMEOFDISK=`/sbin/sysctl -n hw.disknames 2>&1 | sed -e 's/[,=]/\ /g'`
  8.  
  9. case $DEVCLASS in
  10. 2)
  11.     # disk devices
  12.     disklabel=`/sbin/disklabel $DEVNAME 2>&1 | \
  13.     sed -n '/^disk: /s/^disk: //p'`
  14.     [ $DEBUG == 1 ] && logger -i "hotplugd descovered DISKLABEL $disklabel"
  15.     case $disklabel in
  16.     "SCSI disk")
  17.         slices=`/sbin/disklabel $DEVNAME 2>&1 | \
  18.         sed -n '/^ *[abd-z]: /s/^ *\([abd-z]\):.*/\1/p'`
  19.        
  20.         for slice in ${slices}; do
  21.             [ $DEBUG == 1 ] && logger -i "hotplugd attaching SLICE $slice of DEVICE $DEVNAME"
  22.            
  23.             for dname in ${NAMEOFDISK}; do
  24.                 #echo $dname | cut -c 5-
  25.  
  26.                 if [ $dname != 'sd0:88ae7bb778fbc51a' -a $dname != 'sd1:f80f2e3ce5449068' -a $dname != 'cd0:' ]; then
  27.                     while fsck -y /dev/$DEVNAME$slice == true ; do
  28.                         sleep 1
  29.                     done
  30.                     [ ! -d $MOUNTROOT/$DEVNAME$slice ] && mkdir -p -m 1777 $MOUNTROOT/$DEVNAME$slice
  31.                     chown -R psi $MOUNTROOT
  32.                     mount /dev/$DEVNAME$slice $MOUNTROOT/$DEVNAME$slice
  33.                 fi 
  34.             done
  35.            
  36.         done
  37.         ;;
  38.     esac
  39.     ;;
  40. 3)
  41.     # network devices; requires hostname.$DEVNAME
  42.     sh /etc/netstart $DEVNAME
  43.     ;;
  44. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement