Skip to content

Instantly share code, notes, and snippets.

@scriptingosx
Created October 17, 2016 12:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scriptingosx/4aa3c030ca593bcf43525e3c53879f39 to your computer and use it in GitHub Desktop.
Save scriptingosx/4aa3c030ca593bcf43525e3c53879f39 to your computer and use it in GitHub Desktop.
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