-
Notifications
You must be signed in to change notification settings - Fork 2
/
servo.sh
57 lines (51 loc) · 1.24 KB
/
servo.sh
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
#!/bin/bash
#check for root priv
if [ "$(id -u)" != "0" ]; then
echo -ne "This script must be executed as root. Exiting\n" >&2
exit 1
fi
SUDOUSER=$(who am i | awk '{print $1}')
if [ "$1" = "load" ];then
if lsmod | grep a64servo &> /dev/null ; then
echo "Module already loaded! Exiting..."
exit 0
else
insmod a64servo.ko
echo "Module loaded"
fi
if ls /dev | grep servo &> /dev/null ; then
echo "Node existed! Exiting..."
exit 0
else
mknod /dev/servo c 215 0
chgrp servo /dev/servo
chmod 665 /dev/servo
if cat /etc/group | grep servo &> /dev/null; then
echo Group servo exist. Skipping next...
else
groupadd servo
echo Group servo added. Adding $SUDOUSER to group
fi
if id -Gn $SUDOUSER | grep servo &> /dev/null; then
echo $SUDOUSER already member to group servo
else
usermod -a -G servo $SUDOUSER
echo $SUDOUSER added to group servo
echo Loging again as $SUDOUSER
echo exec su -l $SUDOUSER
exec su -l $SUDOUSER
fi
echo "Node created"
fi
elif [ "$1" = "unload" ];then
if lsmod | grep a64servo &> /dev/null ; then
rmmod a64servo.ko
echo "Module unloaded"
fi
if ls /dev | grep servo &> /dev/null ; then
rm /dev/servo
echo "Node deleted"
fi
else
echo "usage: servo (un)load"
fi