Created
October 17, 2016 12:25
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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