#!/bin/bash
#  remote - remote host command support

set -e

lib_load 'net/tool/ssh'


######
# Stub functions

# remote_host - Map a hostname to a name that will allow remote connections
#  $1 - name of host
is_function remote_host || remote_host() { echo "$1"; }

# remote_host_port - Print an alternative port for connecting to a host.
#  $1 - name of host
is_function remote_port || remote_port() { true; }


######
# Public interface

_remote_command() {
	min_args 3 "$@"
	local func=$1
	local host=$2
	shift 2
	local ssh_host ssh_port
	ssh_host=$(remote_host $host)
	ssh_port=$(remote_port $host)
	$func "$@"
}

remote_run() { _remote_command run_ssh "$@"; }
remote_sudo() { _remote_command run_ssh_sudo "$@"; }
remote_deploy_file() { _remote_command ssh_deploy_file "$@"; }

remote_copy_to() { _remote_command ssh_copy_to "$@"; }
remote_copy_from() { _remote_command ssh_copy_from "$@"; }

remote_pkg_install() {
	min_args 2 "$@"
	local pkg_host=$1
	shift
	remote_sudo $pkg_host apt install "$@"
}

remote_class_install() {
	local host=$1
	local class=$2
	local -a deps
	deps=( $(tool_class_deps_all $class) )
	remote_pkg_install "$host" "${deps[@]}"
}

remote_backup() {
	local host=$1
	local target=$2
	warn "$FUNCNAME: FIXME: $target backup unimplemented ($host)"
}

remote_restore() {
	local host=$1
	local target=$2
	warn "$FUNCNAME: FIXME: $target restore unimplemented ($host)"
}

View the Script Reference Index


Generated on Tue Apr 25 21:21:07 PDT 2017 by mcsh i7 v0.18.0.