sddev (1762B)
1 #!/bin/busybox ash 2 3 # $MDEV 4 # $ACTION 5 6 blkidstr=$(blkid $(pwd)/${MDEV}) 7 UUID=$(echo -n "$blkidstr" \ 8 | grep UUID \ 9 | sed -e 's,.*UUID="\([^"]*\)".*,\1,') 10 LABEL=$(echo -n "$blkidstr" \ 11 | grep LABEL \ 12 | sed -e 's,.*LABEL="\([^"]*\)".*,\1,') 13 14 BLOCK="" 15 [ -e /sys${DEVPATH}/dev ] && BLOCK=$(cat /sys${DEVPATH}/dev) 16 17 case "$ACTION" in 18 add|"") 19 if [ -n "${UUID}" ]; 20 then 21 mkdir -p disk/by-uuid 22 cd disk/by-uuid 23 [ -e "${UUID}" ] && rm -f ${UUID} 24 ln -s ../../${MDEV} ${UUID} 25 cd ../.. 26 fi 27 28 if [ -n "${LABEL}" ]; 29 then 30 mkdir -p disk/by-label 31 cd disk/by-uuid 32 [ -e "${LABEL}" ] && rm -f ${LABEL} 33 ln -s ../../${MDEV} ${LABEL} 34 cd ../.. 35 fi 36 37 if [ -n "${BLOCK}" ]; 38 then 39 mkdir -p block 40 cd block 41 [ -e "${BLOCK}" ] && rm -f ${BLOCK} 42 ln -s ../${MDEV} ${BLOCK} 43 cd .. 44 fi 45 ;; 46 remove) 47 [ -n "${UUID}" ] && [ -e disk/by-uuid/${UUID} ] \ 48 && rm -f disk/by-uuid/${UUID} 49 [ -n "${LABEL}" ] && [ -e disk/by-uuid/${LABEL} ] \ 50 && rm -f disk/by-uuid/${LABEL} 51 [ -n "${BLOCK}" ] && [ -e block/${BLOCK} ] \ 52 && rm -f block/${BLOCK} 53 54 if [ -e disk/by-uuid ]; 55 then 56 cd disk/by-uuid 57 SLS=$(ls -l \ 58 | awk "/..\/..\/${MDEV}/ {print \$9 }") 59 for FILE in ${SLS}; 60 do 61 rm -f ${FILE} 62 done 63 cd ../.. 64 65 rmdir disk/by-uuid 2>/dev/null 66 fi 67 if [ -e disk/by-label ]; 68 then 69 cd disk/by-label 70 SLS=$(ls -l \ 71 | awk "/..\/..\/${MDEV}/ {print \$9 }") 72 for FILE in ${SLS}; 73 do 74 rm -f ${FILE} 75 done 76 cd ../.. 77 78 rmdir disk/by-label 2>/dev/null 79 fi 80 rmdir disk/ 2>/dev/null 81 82 if [ -e block ]; 83 then 84 cd block 85 SLS=$(ls -l \ 86 | awk "/..\/${MDEV}/ {print \$9 }") 87 for FILE in ${SLS}; 88 do 89 rm -f ${FILE} 90 done 91 cd .. 92 93 rmdir block 2>/dev/null 94 fi 95 ;; 96 esac 97 98 exit 0 99