-
Notifications
You must be signed in to change notification settings - Fork 41
/
mount_uzip
executable file
·125 lines (114 loc) · 3.22 KB
/
mount_uzip
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/sh
#
# Copyright (c) 2021, The NomadBSD Project
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# PROVIDE: mount_uzip
# BEFORE: ldconfig NETWORKING
# REQUIRE: FILESYSTEMS
. /etc/rc.subr
name=mount_uzip
start_cmd=do_mount_uzip
stop_cmd=do_unmount
: ${unionfs_maxfiles:=65536}
spinner_pid=-1
is_zfs_root()
{
local rootfs=$(mount -p | awk '$2 == "/" {print $3}')
[ "${rootfs}" = "zfs" ]
}
#
# Make sure to kill the spinner if the script receives a signal
#
kill_spinner() {
[ ${spinner_pid} -gt -1 ] && kill -KILL ${spinner_pid}
exit 1
}
do_mount_uzip()
{
if (mount | grep -q '/unionfs/usr/local'); then
# The uzip image is already mounted. Try to mount
# the unionfs.
do_mount_unionfs
return
fi
if (! kldstat -q -m geom_uzip); then
kldload geom_uzip 2>/dev/null
fi
#
# Create a spinner to indicate progress
#
{
spinner="| / - \\ | / - \\"
while [ true ]; do
for i in ${spinner}; do
printf "\r"
# Use the alias'd echo from rc.subr
echo -n "Mounting uzip image [$i]"
sleep 0.2
done
done
}&
spinner_pid=$!
trap kill_spinner SIGINT SIGTERM SIGHUP
mdmfs -P -F /uzip/usr.local.uzip -oro md.uzip /unionfs/usr/local
kill ${spinner_pid}
echo
do_mount_unionfs
}
do_mount_unionfs()
{
local rwdir
if (mount | grep -q ' /usr/local '); then
return
fi
if is_zfs_root; then
rwdir=/rwlocal
[ ! -d "${rwdir}" ] && return
else
rwdir=/data/usr/local
if !(mount | grep -q '/data '); then
return
fi
[ ! -d "${rwdir}" ] && mkdir -p "${rwdir}"
fi
kldstat -q -n fusefs && kldunload fusefs
if (! kldstat -q -n fusefs2 && ! kldstat -q -n fusefs); then
kldload fusefs2 2>/dev/null || kldload fusefs 2>/dev/null
fi
unionfs -o cow,max_files=${unionfs_maxfiles} \
-o allow_other,use_ino,suid,nonempty,kernel_cache \
"${rwdir}"=RW:/unionfs/usr/local=RO /usr/local
service ldconfig start
}
do_unmount()
{
if (mount | grep -q ' /usr/local '); then
echo "Unmounting /usr/local ..."
umount -f /usr/local
fi
}
load_rc_config $name
run_rc_command "$1"