blob: 3a0c1d6cf120066de586ba088a31af62a440dff3 (
plain) (
blame)
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
|
#!/bin/sh
# Helper script for ZFS users that want to view DRM protected content
# with pipelight
# Author: Kris Moore <kris@pcbsd.org>
# License: BSD
destroy_old()
{
umount ${userhome}/.wine-pipelight
zfs destroy ${zpool}/$username-pipelight
cat /etc/fstab | grep -v "$zpool/$username-pipelight " > /etc/fstab.new
mv /etc/fstab.new /etc/fstab
}
if [ -z "$1" ] ; then
echo "Create UFS formatted ZVOL:
${0} <username>
Remove UFS formatted ZVOL:
${0} --remove <username>"
exit 1
fi
doDestroy=0
if [ "$1" = '--remove' ] ; then
doDestroy=1
username="$2"
else
username="$1"
fi
# Get users HOME
userhome=`cat /etc/passwd | grep "^$username:" | cut -d ':' -f 6`
if [ -z "$userhome" ] ; then
echo "No such user: $userhome"
exit 1
fi
if [ ! -d "$userhome" ] ; then
echo "No such home directory: $userhome"
exit 1
fi
zpool=`mount | grep 'on / ' | awk '{print $1}' | cut -d '/' -f 1`
if [ -z "$zpool" ] ; then
echo "Unable to detect zpool!"
exit 1
fi
# If the user wants to remove the zvol
if [ $doDestroy -eq 1 ] ; then
destroy_old
exit 0
fi
# Running this on a user which already has the file-system, lets remove it first
zfs list ${zpool}/$username-pipelight >/dev/null 2>/dev/null
if [ $? -eq 0 ] ; then
echo "Removing old UFS ZVOL"
destroy_old
fi
# Create the ZVOL
zfs create -V 400M $zpool/$username-pipelight
if [ $? -ne 0 ] ; then
echo "Failed creating ZVOL"
exit 1
fi
# Format it with UFS
newfs -U /dev/zvol/$zpool/$username-pipelight
if [ $? -ne 0 ] ; then
echo "Failed formatting ZVOL"
exit 1
fi
# Create the directory
if [ ! -d "${userhome}/.wine-pipelight" ] ; then
mkdir ${userhome}/.wine-pipelight
fi
# Mount the directory
mount /dev/zvol/$zpool/$username-pipelight ${userhome}/.wine-pipelight
if [ $? -ne 0 ] ; then
echo "Failed mounting ZVOL"
exit 1
fi
# Chown the directory
chown $username:$username ${userhome}/.wine-pipelight
# Save to fstab
echo "/dev/zvol/$zpool/$username-pipelight ${userhome}/.wine-pipelight ufs rw,late 0 0" >> /etc/fstab
echo "ZVOL created and mounted to: ${userhome}/.wine-pipelight"
|