-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome-overlay
executable file
·68 lines (59 loc) · 1.49 KB
/
home-overlay
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
#!/bin/sh
set -e
USERNAME=#TARGETUSER#
USERHOME=`getent passwd "$USERNAME" | cut -d: -f6`
OVERLAYD="/run/local/user/$(id -u "$USERNAME")/overlay.d"
WORKD="$OVERLAYD/work"
UPPERD="$OVERLAYD/upper"
overlay_base_mounted () {
grep -q "^tmpfs $OVERLAYD " /proc/mounts
}
home_overlay_mounted () {
grep -q "^overlay $USERHOME " /proc/mounts
}
start () {
if ! home_overlay_mounted; then
echo "Overlaying $USERNAME home"
if ! overlay_base_mounted; then
echo "Preparing overlay base mounts"
if [ ! -e "$OVERLAYD" ]; then
mkdir -p "$OVERLAYD"
fi
if [ ! -d "$OVERLAYD" ]; then
echo "Overlay base $OVERLAYD is not a directory"
exit 2
fi
mount -t tmpfs tmpfs "$OVERLAYD"
fi
mkdir "$UPPERD" "$WORKD"
chown -R "$USERNAME" "$UPPERD" "$WORKD"
mount -t overlay -o "lowerdir=$USERHOME,upperdir=$UPPERD,workdir=$WORKD" overlay "$USERHOME"
fi
}
stop () {
if home_overlay_mounted; then
umount "$USERHOME"
fi
if overlay_base_mounted; then
umount "$OVERLAYD"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
if home_overlay_mounted; then
echo "Overlay-mount active on $USERHOME"
else
echo "Overlay-mount inactive on $USERHOME"
fi
;;
*)
echo "Usage: $0 [start|stop|status]" 1>&2
exit 1
;;
esac