-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclose.sh
executable file
·76 lines (67 loc) · 1.59 KB
/
close.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/zsh
PREFIX=/usr/lib/priv
source $PREFIX/colors.sh
source $PREFIX/conf.sh
source $PREFIX/kill.sh
if [ $UID != 0 ]; then
red Root access needed.
exit 1
fi
[ -f /run/priv.pid ] && MPID=$(cat /run/priv.pid)
[ -f /run/privu.pid ] && UPID=$(cat /run/privu.pid)
if ! [ -z $MPID ] && kill -0 $MPID 2> /dev/null; then
if ! [ -z $UPID ] && kill -0 $UPID 2> /dev/null; then
blue "sending SIGINT to umount daemon..."
kill -SIGINT $UPID
blue "waiting it to exit..."
while kill -0 $UPID 2> /dev/null; do
sleep 1
done
else
blue "sending SIGINT to mount daemon..."
kill -SIGINT $MPID
fi
blue "waiting for mount daemon to exit..."
while kill -0 $MPID 2> /dev/null; do
sleep 1
done
fi
if ! [ -z $PRIV_NFS ] && mountpoint -q $PRIV_NFS; then
blue "killing processes and umounting $PRIV_NFS..."
kill_processes
systemctl stop nfs-server
if ! umount $PRIV_NFS; then
red "could not umount nfs: $PRIV_NFS"
systemctl start nfs-server
exit 1
else
green " --> Ok"
fi
fi
if mountpoint -q $PRIV_MOUNT; then
blue "priv is mounted, killing pending processes..."
kill_processes
blue "unmounting $PRIV_MOUNT... "
if ! umount $PRIV_MOUNT; then
red " --> FAIL"
red "could not umount: $PRIV_MOUNT"
exit 1
else
green " --> OK"
fi
else
blue "priv is not mounted"
fi
if dmsetup ls --target crypt | grep -q $PRIV_DEVICE; then
blue "closing mapping..."
if ! cryptsetup close $PRIV_DEVICE; then
red " --> FAIL"
red "could not close mapping"
exit 1
else
green " --> OK"
fi
else
blue "mapping isn't open"
fi
blue Done