Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ssh-installer tool for macOS to `scp` a package to a remote host and install it
#!/bin/sh
PATH=/usr/bin:/bin:/usr/sbin:/sbin export PATH
# ssh-installer
# copies a pkg with scp and runs installer on target
# usage: ssh-installer [USER@]HOST PKGFILE [other installer options]
TMPPKGDIR="/private/tmp/ssh-installer/"
usage() {
(>&2 echo "usage: ssh-installer [USER@]HOST PKGFILE [other installer options]")
exit 1
}
if [ "$#" -lt 2 ]; then
usage
fi
# read arguments
HOST=$1
PKGFILE=$2
shift 2
if [ ! -f ${PKGFILE} ]; then
(>&2 echo "can't find ${PKGFILE}")
exit 2
fi
PKGFILENAME=$(basename ${PKGFILE})
# grab everything after the @
HOSTNAME=$(echo "${HOST}" | cut -d @ -f 2)
if ! nc -z "${HOSTNAME}" 22; then
(>&2 echo "host ${HOSTNAME} seems to be unreachable")
exit 3
fi
ssh "${HOST}" "mkdir -p ${TMPPKGDIR}"
scp "${PKGFILE}" "${HOST}":"${TMPPKGDIR}"
echo "this next step may prompt for sudo on ${HOST}"
ssh -t "${HOST}" "sudo installer -pkg \"${TMPPKGDIR}${PKGFILENAME}\" $@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment