2022-04-14 10:31:27 +00:00
|
|
|
#!/bin/bash
|
2013-09-02 14:01:50 +00:00
|
|
|
|
|
|
|
cmd_hostname=""
|
|
|
|
cmd_do_bootstrap="no"
|
2013-10-31 22:26:16 +00:00
|
|
|
cmd_fqdn=""
|
2013-09-02 14:01:50 +00:00
|
|
|
|
2022-04-14 10:31:27 +00:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2023-11-29 11:10:34 +00:00
|
|
|
while getopts "bhnp:" this; do
|
2022-04-14 10:31:27 +00:00
|
|
|
case "${this}" in
|
|
|
|
h) usage; exit 0;;
|
|
|
|
b) cmd_do_bootstrap="yes" ;;
|
|
|
|
n) cmd_fqdn="${OPTARG}" ; shift ;;
|
2023-11-29 11:10:34 +00:00
|
|
|
p) cmd_proxy="${OPTARG}" ; shift ;;
|
2022-04-14 10:31:27 +00:00
|
|
|
*) echo "Unknown option ${this}"; echo ""; usage; exit 1;;
|
2013-09-02 14:01:50 +00:00
|
|
|
esac
|
|
|
|
done
|
2022-04-14 10:31:27 +00:00
|
|
|
shift $((OPTIND-1))
|
2013-09-02 14:01:50 +00:00
|
|
|
|
2022-04-14 10:31:27 +00:00
|
|
|
if [[ ! $cmd_hostname ]]; then
|
2013-09-02 14:01:50 +00:00
|
|
|
cmd_hostname="$1"
|
|
|
|
fi
|
|
|
|
|
2022-04-14 10:31:27 +00:00
|
|
|
if [[ ! $cmd_fqdn ]]; then
|
2013-10-31 22:26:16 +00:00
|
|
|
cmd_fqdn="$cmd_hostname"
|
|
|
|
fi
|
|
|
|
|
2013-09-02 14:01:50 +00:00
|
|
|
if test -z "$cmd_hostname"; then
|
2022-04-14 10:31:27 +00:00
|
|
|
usage
|
2013-09-02 14:01:50 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-11-29 11:10:34 +00:00
|
|
|
if [[ -n $cmd_proxy ]]; then
|
|
|
|
proxyjump="-o ProxyJump=${cmd_proxy}"
|
|
|
|
fi
|
|
|
|
|
2013-09-02 14:01:50 +00:00
|
|
|
test -f cosmos.conf && . ./cosmos.conf
|
|
|
|
|
2022-04-14 10:31:27 +00:00
|
|
|
_remote=${remote:='ro'}
|
|
|
|
defrepo=$(git remote get-url "${_remote}" 2>/dev/null)
|
2013-09-02 14:01:50 +00:00
|
|
|
rrepo=${repo:="$defrepo"}
|
2013-10-31 22:26:16 +00:00
|
|
|
rtag=${tag:="changeme"}
|
2013-09-02 14:01:50 +00:00
|
|
|
|
2022-04-14 10:31:27 +00:00
|
|
|
if [[ ! $rrepo ]]; then
|
|
|
|
echo "$0: repo not set in cosmos.conf and no git remote named '${_remote}' found"
|
2019-02-13 14:46:57 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-04-14 10:31:27 +00:00
|
|
|
if [ ! -d "$cmd_fqdn" ]; then
|
|
|
|
cp -pr default "$cmd_fqdn"
|
|
|
|
git add "$cmd_fqdn"
|
|
|
|
git commit -m "$cmd_fqdn added" "$cmd_fqdn"
|
2013-09-02 14:01:50 +00:00
|
|
|
./bump-tag
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$cmd_do_bootstrap" = "yes" ]; then
|
2022-11-15 17:11:51 +00:00
|
|
|
cosmos_deb=$(find apt/ -maxdepth 1 -name 'cosmos_*.deb' | sort -V | tail -1)
|
2023-11-29 11:10:34 +00:00
|
|
|
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
|
2013-09-02 14:01:50 +00:00
|
|
|
fi
|