streams-ops/addhost
Micke Nordin 71e112e009
PREPARE/ADDHOST: allow the ues of proxyjump with ip address
With this patch you can specify a ProxyJump for prepare-iaas-ubuntu,
prepare-iaas-debian and addhost. Example:

./prepare-iaas-debian 89.47.191.7 hj
./addhost -b -n node1.extern.drive.test.sunet.se -p hj -- 89.47.191.7

where hj is a host defined in my .ssh/config suitable for a proxyjump
to the host in question.

This makes it easier to use ip addresses for these scripts which might
be neccessary if dns takes a while to propagate.
2023-11-29 12:10:34 +01:00

70 lines
1.7 KiB
Bash
Executable file

#!/bin/bash
cmd_hostname=""
cmd_do_bootstrap="no"
cmd_fqdn=""
function usage() {
echo "Usage: $0 [-h] [-b] [-n fqdn] [--] [<host>]"
echo " -h show help"
echo " -b bootstrap <host> (using ssh)"
echo " -n specify FQDN (if not the same as <host>)"
echo ""
echo " <host> can be an IP number, or something that resolves to one"
}
while getopts "bhnp:" this; do
case "${this}" in
h) usage; exit 0;;
b) cmd_do_bootstrap="yes" ;;
n) cmd_fqdn="${OPTARG}" ; shift ;;
p) cmd_proxy="${OPTARG}" ; shift ;;
*) echo "Unknown option ${this}"; echo ""; usage; exit 1;;
esac
done
shift $((OPTIND-1))
if [[ ! $cmd_hostname ]]; then
cmd_hostname="$1"
fi
if [[ ! $cmd_fqdn ]]; then
cmd_fqdn="$cmd_hostname"
fi
if test -z "$cmd_hostname"; then
usage
exit 1
fi
if [[ -n $cmd_proxy ]]; then
proxyjump="-o ProxyJump=${cmd_proxy}"
fi
test -f cosmos.conf && . ./cosmos.conf
_remote=${remote:='ro'}
defrepo=$(git remote get-url "${_remote}" 2>/dev/null)
rrepo=${repo:="$defrepo"}
rtag=${tag:="changeme"}
if [[ ! $rrepo ]]; then
echo "$0: repo not set in cosmos.conf and no git remote named '${_remote}' found"
exit 1
fi
if [ ! -d "$cmd_fqdn" ]; then
cp -pr default "$cmd_fqdn"
git add "$cmd_fqdn"
git commit -m "$cmd_fqdn added" "$cmd_fqdn"
./bump-tag
fi
if [ "$cmd_do_bootstrap" = "yes" ]; then
cosmos_deb=$(find apt/ -maxdepth 1 -name 'cosmos_*.deb' | sort -V | tail -1)
scp $proxyjump "$cosmos_deb" apt/bootstrap-cosmos.sh root@"$cmd_hostname":
ssh root@"$cmd_hostname" $proxyjump ./bootstrap-cosmos.sh "$cmd_fqdn" "$rrepo" "$rtag"
ssh root@"$cmd_hostname" $proxyjump cosmos update
ssh root@"$cmd_hostname" $proxyjump cosmos apply
fi