add -p to addhost

This commit is contained in:
Valerio Lomanto 2025-02-04 11:25:34 +01:00
parent 2c8f4712d5
commit 8211a6eb6b
Signed by: verglasz
GPG key ID: 33263D8CFCFEC285

32
addhost
View file

@ -3,22 +3,27 @@
cmd_hostname=""
cmd_do_bootstrap="no"
cmd_fqdn=""
cmd_prepare=""
function usage() {
echo "Usage: $0 [-h] [-b] [-n fqdn] [--] [<host>]"
echo "Usage: $0 [-h] [-b] [-n <fqdn>] [-p <proxy host>] [-r debian|ubuntu] [--] [<host>]"
echo " -h show help"
echo " -b bootstrap <host> (using ssh)"
echo " -n specify FQDN (if not the same as <host>)"
echo " -p specify proxyjump host (used for bootstrap)"
echo " -r run prepare-iaas script (implies -b), supports debian and ubuntu"
echo ""
echo " <host> can be an IP number, or something that resolves to one"
}
while getopts "bhnp:" this; do
while getopts "bhn:p:r:" this; do
case "${this}" in
h) usage; exit 0;;
b) cmd_do_bootstrap="yes" ;;
n) cmd_fqdn="${OPTARG}" ; shift ;;
p) cmd_proxy="${OPTARG}" ; shift ;;
n) cmd_fqdn="${OPTARG}" ;;
p) cmd_proxy="${OPTARG}" ;;
r) cmd_prepare="${OPTARG}" ; cmd_do_bootstrap="yes" ;;
*) echo "Unknown option ${this}"; echo ""; usage; exit 1;;
esac
done
@ -32,15 +37,24 @@ 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
case "$cmd_prepare" in
""| "debian" | "ubuntu" ) ;; # valid value
*) echo "$0: don't know how to prepare '$cmd_prepare', only 'debian' and 'ubuntu' supported"
usage
exit 1;;
esac
test -f cosmos.conf && . ./cosmos.conf
_remote=${remote:='ro'}
@ -60,7 +74,17 @@ if [ ! -d "$cmd_fqdn" ]; then
./bump-tag
fi
if [ "$cmd_do_bootstrap" = "yes" ]; then
echo "Bootstrapping $cmd_hostname"
if [ -n "$cmd_prepare" ]; then
if ! ./prepare-iaas-$cmd_prepare $cmd_hostname $cmd_proxy ; then
echo "Failed to prepare $cmd_prepare host, check that the setup is correct"
echo "Aborting"
exit 1
fi
fi
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"