#!/bin/bash # $Id: mac_inst_pkg.sh 1299 2008-05-12 14:55:08Z admin $ BASEURL=$1 VERSION=$2 PKGNAME=$3 CHKSUM=$4 EXTENSION=$5 REMOVE=$6 CHECKONLY=$7 # this is the naming scheme of the packages: PKGNS="${PKGNAME}_${VERSION}.${EXTENSION}" # ZIPFILE ZIPFILE="${PKGNS}.zip" # ------------------------------ Functions ---------------------------- function is_installed_with_any_version { if [ "`ls \"/Library/Receipts/${PGKNS}\"* 2>/dev/null`" != "" ] ; then return 1 fi return 0 } function is_installed_with_req_version { ## echo "Testing whether /Library/Receipts/${PKGNS} exists" if [ -e "/Library/Receipts/${PKGNS}" ] ; then return 1 fi return 0 } function remove_old { echo "Removing old not yet implemented!" } # ------------------------------ Installed? --------------------------- is_installed_with_req_version if [ $? -eq 1 ] ; then echo "Required Version of ${PKGNAME} (${PKGNS}) already installed --> Done." exit 1; fi if [ "$CHECKONLY" != "" ] ; then exit 0; fi is_installed_with_any_version if [ $? -eq 1 ] ; then echo "Other Version of ${PKGNAME} already installed --> Updating." if [ "$REMOVE" == "true" ] ; then remove_old fi else echo "No Version of ${PKGNAME} already installed --> Installing." fi # ------------------------------ Download ---------------------------- cd /tmp ZIPFILE=`echo $ZIPFILE | perl -npe 's/ /%20/g'` curl "${BASEURL}/$ZIPFILE" -o "/tmp/$ZIPFILE" # ------------------------------ Checksum ---------------------------- if [ -e "/sw/bin/md5sum" ] ; then DLMD5=`/sw/bin/md5sum "$ZIPFILE" | cut -f1 -d' '` else DLMD5=`md5 "$ZIPFILE" | cut -f4 -d' '` fi if [ "0" != "$CHKSUM" ] ; then if [ "$DLMD5" != "$CHKSUM" ] ; then echo "Could not verify checksum: Mismatch!" exit 1 fi else echo "WARNING: Ignoring checksum check" fi # ------------------------------ Install ---------------------------- # -o: force overwrite unzip -o "$ZIPFILE" if installer -pkg "${PKGNS}" -target / ; then touch "/Library/Receipts/${PKGNS}" exit 0 fi echo "Installer failed." exit 1