注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

神魔破杜梓的叨叨堂

Programming every day!

 
 
 

日志

 
 
 
 

usbmount : create symlink to mount point by label  

2012-12-03 12:21:41|  分类: My Tech |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
create_label_symlink

#!/bin/sh
# This script creates the label name symlink in /var/run/usbmedia.
# Copyright (C) 2005 Martin Dickopp
#
# This file is free software; the copyright holder gives unlimited
# permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
#
set -e

if [ ! -e /var/run/usbmedia ]; then
mkdir -p /var/run/usbmedia
fi

# Replace spaces with underscores, remove special characters in label..
UM_DEVINFO=$(/sbin/blkid -p $UM_DEVICE)
UM_LABEL=$(echo "$UM_DEVINFO" | sed 's/.*[[:blank:]]LABEL="\([^"]*\)".*/\1/g; s/[[:blank:]]*//g;')
UM_LABEL=`echo "$UM_LABEL" | sed 's/ /_/g; s/[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._-]//g'`

# Exit if both vendor and model name are empty.
test -n "$UM_LABEL" || exit 0

# Build symlink name.
if test -n "$UM_LABEL" ; then
name="$UM_LABEL"
fi

# If the symlink does not yet exist, create it.
test -e "/var/run/usbmedia/$name" || ln -sf "$UM_MOUNTPOINT" "/var/run/usbmedia/$name"

exit 0

remove_label_symlink

#!/bin/sh
# This script removes the label name symlink in /var/run/usbmedia.
# Copyright (C) 2005 Martin Dickopp
#
# This file is free software; the copyright holder gives unlimited
# permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
#
set -e

test -e /var/run/usbmedia || exit 0

ls /var/run/usbmedia | while read name; do
if test "`readlink \"/var/run/usbmedia/$name\" || :`" = "$UM_MOUNTPOINT"; then
rm -f "/var/run/usbmedia/$name"
break
fi
done

exit 0

USAGE:

sudo apt-get install usbmount
cd /etc/usbmount/mount.d
sudo wget http://raw.github.com/gist/4192667/cce9e7a5f52a25badba43f5c19ca69558a2193e7/create_label_symlink

sudo chmod 755 create_label_symlink

cd /etc/usbmount/umount.d

sudo wget http://raw.github.com/gist/4192669/04516d86a237fe7754e631b13d93e74b189bc09b/remove_label_symlink

sudo chmod 755 remove_label_symlink


  评论这张
 
阅读(611)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017