1#!/bin/bash 2# 3# install.sh [--uninstall] sourcefile targetfile [install options] 4# 5 6 7# Check for uninstall option 8if test "x$1" == "x--uninstall" ; then 9 UNINSTALL=true 10 SOURCE=$2 11 TARGET=$3 12 shift 3 13else 14 UNINSTALL=false 15 SOURCE=$1 16 TARGET=$2 17 shift 2 18fi 19 20# Check usage 21if test -z "$SOURCE" || test -z "$TARGET" ; then 22 echo Usage: install.sh [--uninstall] source target [install options] >&2 23 exit 1 24fi 25 26 27# 28# do_install(SOURCE_FILE, TARGET_FILE) 29# 30 31do_install() 32{ 33 local SOURCE=$1 34 local TARGET=$2 35 local PARAMS=$3 36 37 install -p -D $PARAMS $SOURCE $TARGET 38} 39 40 41# 42# do_uninstall(SOURCE_FILE, TARGET_FILE) 43# 44 45do_uninstall() 46{ 47 local SOURCE=$1 48 local TARGET=$2 49 50 # Does target exist? 51 if test -r $TARGET ; then 52 # Is target of the same version as this package? 53 if diff $SOURCE $TARGET >/dev/null; then 54 rm -f $TARGET 55 else 56 echo WARNING: Skipping uninstall for $TARGET - versions differ! >&2 57 fi 58 else 59 echo WARNING: Skipping uninstall for $TARGET - not installed! >&2 60 fi 61} 62 63 64# Call sub routine 65if $UNINSTALL ; then 66 do_uninstall $SOURCE $TARGET 67else 68 do_install $SOURCE $TARGET "$*" 69fi 70 71exit 0 72