#!/bin/sh # Helper script for ZFS users that want to view DRM protected content # with pipelight # Author: Kris Moore # 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} Remove UFS formatted ZVOL: ${0} --remove " 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 # Get user group usergroup=`groups $username | cut -d " " -f 1` # Chown the directory chown $username:$usergroup ${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"