cleanups, and install cosmos_1.5-2~sunet20220414_all.deb
- shellcheck fixes - rewrite argument parsing - install new version of cosmos (cosmos_1.5-2~sunet20220414_all.deb)
This commit is contained in:
parent
d033b58909
commit
7323626efe
56
addhost
56
addhost
|
@ -1,57 +1,63 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
cmd_hostname=""
|
cmd_hostname=""
|
||||||
cmd_do_bootstrap="no"
|
cmd_do_bootstrap="no"
|
||||||
cmd_fqdn=""
|
cmd_fqdn=""
|
||||||
|
|
||||||
set -- $(getopt b?h?n: "$@")
|
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 [ $# -gt 0 ]; do
|
while getopts "bhn:" this; do
|
||||||
case "$1" in
|
case "${this}" in
|
||||||
(-h) echo "Usage: $0 [-h] [-b] [--] [<host>]"; exit 0;;
|
h) usage; exit 0;;
|
||||||
(-b) cmd_do_bootstrap="yes" ;;
|
b) cmd_do_bootstrap="yes" ;;
|
||||||
(-n) cmd_fqdn="$2" ; shift ;;
|
n) cmd_fqdn="${OPTARG}" ; shift ;;
|
||||||
(--) shift; break;;
|
*) echo "Unknown option ${this}"; echo ""; usage; exit 1;;
|
||||||
(-*) echo "Unknown option $1\nUsage: $0 [-b] [-h] [-n fqdn] [--] <host>"; exit 1;;
|
|
||||||
(*) break;;
|
|
||||||
esac
|
esac
|
||||||
shift
|
|
||||||
done
|
done
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
if [ ! -z "$1" -a -z "$cmd_hostname" ]; then
|
if [[ ! $cmd_hostname ]]; then
|
||||||
cmd_hostname="$1"
|
cmd_hostname="$1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z "$cmd_hostname" -a -z "$cmd_fqdn" ]; then
|
if [[ ! $cmd_fqdn ]]; then
|
||||||
cmd_fqdn="$cmd_hostname"
|
cmd_fqdn="$cmd_hostname"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -z "$cmd_hostname"; then
|
if test -z "$cmd_hostname"; then
|
||||||
echo "Usage: $0 [-h] [-b] [-n fqdn] [--] <host>"
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
test -f cosmos.conf && . ./cosmos.conf
|
test -f cosmos.conf && . ./cosmos.conf
|
||||||
|
|
||||||
defrepo=`git remote -v | grep ${remote:="ro"} | grep fetch | awk '{print $2}'`
|
_remote=${remote:='ro'}
|
||||||
|
defrepo=$(git remote get-url "${_remote}" 2>/dev/null)
|
||||||
rrepo=${repo:="$defrepo"}
|
rrepo=${repo:="$defrepo"}
|
||||||
rtag=${tag:="changeme"}
|
rtag=${tag:="changeme"}
|
||||||
|
|
||||||
if [ "x$rrepo" = "x" ]; then
|
if [[ ! $rrepo ]]; then
|
||||||
echo "$0: repo not set in cosmos.conf and no git remote named 'ro' found"
|
echo "$0: repo not set in cosmos.conf and no git remote named '${_remote}' found"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d $cmd_hostname ]; then
|
if [ ! -d "$cmd_fqdn" ]; then
|
||||||
cp -pr default $cmd_fqdn
|
cp -pr default "$cmd_fqdn"
|
||||||
git add $cmd_fqdn
|
git add "$cmd_fqdn"
|
||||||
git commit -m "$cmd_fqdn added" $cmd_fqdn
|
git commit -m "$cmd_fqdn added" "$cmd_fqdn"
|
||||||
./bump-tag
|
./bump-tag
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$cmd_do_bootstrap" = "yes" ]; then
|
if [ "$cmd_do_bootstrap" = "yes" ]; then
|
||||||
scp apt/cosmos_1.5-1_all.deb apt/bootstrap-cosmos.sh root@$cmd_hostname:
|
scp apt/cosmos_1.5-2~sunet20220414_all.deb apt/bootstrap-cosmos.sh root@"$cmd_hostname":
|
||||||
ssh root@$cmd_hostname ./bootstrap-cosmos.sh $cmd_fqdn $rrepo $rtag
|
ssh root@"$cmd_hostname" ./bootstrap-cosmos.sh "$cmd_fqdn" "$rrepo" "$rtag"
|
||||||
ssh root@$cmd_hostname cosmos update
|
ssh root@"$cmd_hostname" cosmos update
|
||||||
ssh root@$cmd_hostname cosmos apply
|
ssh root@"$cmd_hostname" cosmos apply
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue