matrix-ops/addhost
Fredrik Thulin 7c5a063045
gpg import with --no-tty
With recent GPG versions, a TTY seems to be required to import keys.

Since importing of keys need to work when running from cron, we
pass --no-tty to those commands. This should mean that -t doesn't
have to be passed to SSH on bootstrapping for new Debian hosts
(tested on Raspbian).
2019-03-17 13:26:54 +01:00

58 lines
1.4 KiB
Bash
Executable file

#!/bin/sh
cmd_hostname=""
cmd_do_bootstrap="no"
cmd_fqdn=""
set -- $(getopt b?h?n: "$@")
while [ $# -gt 0 ]; do
case "$1" in
(-h) echo "Usage: $0 [-h] [-b] [--] [<host>]"; exit 0;;
(-b) cmd_do_bootstrap="yes" ;;
(-n) cmd_fqdn="$2" ; shift ;;
(--) shift; break;;
(-*) echo "Unknown option $1\nUsage: $0 [-b] [-h] [-n fqdn] [--] <host>"; exit 1;;
(*) break;;
esac
shift
done
if [ ! -z "$1" -a -z "$cmd_hostname" ]; then
cmd_hostname="$1"
fi
if [ ! -z "$cmd_hostname" -a -z "$cmd_fqdn" ]; then
cmd_fqdn="$cmd_hostname"
fi
if test -z "$cmd_hostname"; then
echo "Usage: $0 [-h] [-b] [-n fqdn] [--] <host>"
exit 1
fi
test -f cosmos.conf && . ./cosmos.conf
defrepo=`git remote -v | grep ${remote:="ro"} | grep fetch | awk '{print $2}'`
rrepo=${repo:="$defrepo"}
rtag=${tag:="changeme"}
if [ "x$rrepo" = "x" ]; then
echo "$0: repo not set in cosmos.conf and no git remote named 'ro' found"
exit 1
fi
if [ ! -d $cmd_hostname ]; 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
scp apt/cosmos_1.5-1_all.deb apt/bootstrap-cosmos.sh root@$cmd_hostname:
ssh root@$cmd_hostname ./bootstrap-cosmos.sh $cmd_fqdn $rrepo $rtag
ssh root@$cmd_hostname cosmos update
ssh root@$cmd_hostname cosmos apply
fi