-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm
executable file
·98 lines (81 loc) · 1.79 KB
/
m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
# simple mount function
#
# by Jack ([email protected])
#
# requires udevil
#
# to allow mounting of mapper devices change these lines in /etc/udevil/udevil.conf
# allowed_devices = /dev/*, /dev/mapper/*
# allowed_internal_devices = /dev/mapper/*
#
unset GREP_OPTIONS
function usage(){
echo "$0 [-h, --help]"
echo
echo " -h, --help, print usage"
echo
echo " stdin, [1..n] mount/unmount"
echo " r reload list"
echo " a abort"
echo
echo "This prints a list of numbered mountable volumes and mounts a chosen device via pmount."
echo "To mount oder unmount a volume enter its number. Any other input will lead to no operation."
}
function main(){
# list all devices
args="/dev/**"
filter='-oe /dev/sd.* -oe /dev/mmcblk.* -oe /dev/cdrom*'
if [ -e /dev/mapper ]; then
args="$args /dev/mapper/*"
filter="$filter -oe /dev/mapper/[^c].*"
fi
devList=$(ls -dt --color=never ${args} | grep ${filter})
# walk through devices, check if mounted, echo
declare -a dev
j=0
for i in $devList; do
j=$((j+1))
if [ "`mount|grep -o \"$i \"`" != "" ];then
echo -en "\e[1;32m"
m=`mount | grep "$i" | cut -d " " -f 3`
else
m=$(cat /sys/block/$(basename $i)/device/vendor > /dev/null 2>&1)
fi
echo -e "\t$j $i\t\t$m\e[0m"
m=""
dev[$j]=$i
done
# get user choice
echo "(1)"
read b
# no input use 1
if [ "$b" = "" ];then
b=1
fi
# command from user
if [ "$b" = "r" ]; then
main
b="a"
fi
# invalid device number
if ! [[ $(seq 1 $j) =~ $b ]];then
echo "No operation" >&2
return
fi
# use udevil to mount or unmount
x=`mount|grep ${dev[$b]}`
if [ "$x" = "" ];then
echo "udevil mount ${dev[$b]}";
ret=$(udevil mount ${dev[$b]})
else
echo "udevil umount ${dev[$b]}";
ret=$(udevil umount ${dev[$b]})
fi
echo $ret
}
if [ ! "$1" = "" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage
return
fi
main