drive-ops/addhost

53 lines
1.2 KiB
Plaintext
Raw Normal View History

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