maczip

#!/bin/sh
#
# Copyright (c) 2007 TrueStep
#
# Name: maczip
# Author: Rory Arms - http://www.TrueStep.com/
# CDate: 2007-04-20
# Description: uses ditto(1) on OSX to generate PKZip archives that can
# store HFS metadata, such as resource forks and POSIX modes, just as 
# the "Create Archive" command in the contextual menu of the Finder can.
# When calling this script as "macunzip" it will merge the resource forks 
# with their corresponding data forks, just as BOMArchiveHelper does with the 
# Finder. If you want to just use this script for yourself, I'd suggest 
# installing it in ~/bin and making sure that path is added to your shell's 
# PATH environment variable.
# Tested With: Mac OS X/powerpc 10.4.8
# 

# $Id: maczip,v 1.2 2007/11/26 22:58:57 rorya Exp $

NAME=`basename $0`

if [ ! `uname -s` = "Darwin" ]; then
	echo "This OS is not supported. maczip requires Mac OS X"
	exit 2
fi

if [ ! -x /usr/bin/ditto ]; then
	echo "ditto(1) not found. Are you sure this is Mac OS X?"
	exit 2
fi

usage() {
	case $NAME in
		maczip)
			echo "usage: $NAME archive.zip path"
			break
		;;
		unmaczip|macunzip)
			echo "usage: $NAME archive.zip destination";
			break
		;;
	esac
}

maczip() {
	#echo "ditto(1) -c runs here"
	if [ -z $1 ]; then
		echo "zipfile name missing"
		usage
		exit 1
	elif [[ ! $(echo $1|grep -i '\.zip$') ]]; then
		echo "Archive name must end with .zip"
		usage
		exit 1
	elif [ -z $2 ]; then
		echo "list of files missing"
		exit 1
	fi
	ARCHIVE=$1
	SRC=$2
	# run ditto(1)
	echo "ditto -V -c -k --sequesterRsrc --keepParent $SRC $ARCHIVE"
	ditto -V -c -k --sequesterRsrc --keepParent $SRC $ARCHIVE
	if [ $? != 0 ]; then
		echo "error occurred"
		exit 2
	fi
}

unmaczip() {
	#echo "ditto(1) -x runs here"
	if [ -z "$1" ]; then
		echo "Archive missing"
		usage
		exit 2
	else
		ARCHIVE=$1
	fi
	if [ -z "$2" ]; then
		DEST=`pwd`
	else
		DEST=$2
	fi
	# run ditto(1)
	ditto -V -x -k --sequesterRsrc $ARCHIVE $DEST
	if [ $? != 0 ]; then
		echo "error occurred"
		exit 2
	fi
}

case $NAME in
	maczip)
		maczip $*
		break
	;;
	unmaczip|macunzip)
		unmaczip $*
		break
	;;
esac

Generated by GNU enscript 1.6.4.