|
#!/bin/sh
#判断是否用root登陆,否则退出
user=`id -un`
if [ "$user" != "root" ]; then
echo "Can\047t do mount operations! Please \"su\" to root first!"
exit 1;
fi
#挂载所有windows分区到/mnt/hd*下
if [ $# -eq 0 ]; then
fdisk -l | awk '$1 ~ /\dev/ && $NF ~ /FAT/ || $NF ~ /NTFS/{print $1;}' > /tmp/temp$$
if [ ! -f /etc/fstab~~ ]; then
cp /etc/fstab /etc/fstab~~
fi
awk 'NR==FNR{ a[$1]=$1 } NR>FNR{ if( $1 != a[$1] ) print $0; }' /tmp/temp$$ /etc/fstab > /tmp/temp${$}$
awk '{split($1,dir,"/");printf("%s\t\t/mnt/%s\t\tauto\tiocharset=cp936,umask=0,exec,sync 0 0\n",$1,dir[3])}' /tmp/temp$$ >> /tmp/temp${$}$
mv /tmp/temp${$}$ /etc/fstab
awk -F [/] '{print "/mnt/"$3;}' /tmp/temp$$ | xargs mkdir 2>/dev/null
rm -f /tmp/temp$$
mount -a
if [ $? -eq 0 ]; then
echo "All Windows Partitions are mounted into the /mnt !";
fi
else
USAGE=" \t`basename $0` -m \t\t -- Umount all Windows Partitions!\n "
while getopts m option 2> /dev/null
do
case $option in
m)
#卸载所有windows分区
mount|grep /mnt/hd > /dev/null
if [ $? -eq 0 ]; then
dirs=`mount|awk '$3 ~ /\mnt\/hd/{ print $3;}'`
for dir in $dirs
do
umount $dir 2> /dev/null
if [ $? -eq 0 ]; then
echo "$dir is umounted!"
rmdir $dir
else echo -e "\\a\33[31m$dir can\047t be umounted! Please try again!\33[0m"
fi
done
if [ -f /etc/fstab~~ ];then
mv /etc/fstab~~ /etc/fstab
fi
fi
break
;;
* ) echo -e " Usage:\n $USAGE ";
exit 1
;;
esac
done
fi |
|