new addhost

This commit is contained in:
Leif Johansson 2013-10-31 23:26:16 +01:00
parent db83b79024
commit 54000987a0
3 changed files with 24 additions and 11 deletions

21
addhost
View file

@ -2,15 +2,17 @@
cmd_hostname="" cmd_hostname=""
cmd_do_bootstrap="no" cmd_do_bootstrap="no"
cmd_fqdn=""
set -- $(getopt b?h? "$@") set -- $(getopt b?h?n: "$@")
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
(-h) echo "Usage: $0 [-h] [-b] [--] [<host>]"; exit 0;; (-h) echo "Usage: $0 [-h] [-b] [--] [<host>]"; exit 0;;
(-b) cmd_do_bootstrap="yes" ;; (-b) cmd_do_bootstrap="yes" ;;
(-n) cmd_fqdn="$2" ; shift ;;
(--) shift; break;; (--) shift; break;;
(-*) echo "Unknown option $1\nUsage: $0 [-b] [-h] [--] <host>"; exit 1;; (-*) echo "Unknown option $1\nUsage: $0 [-b] [-h] [-n fqdn] [--] <host>"; exit 1;;
(*) break;; (*) break;;
esac esac
shift shift
@ -20,8 +22,12 @@ if [ ! -z "$1" -a -z "$cmd_hostname" ]; then
cmd_hostname="$1" cmd_hostname="$1"
fi fi
if [ ! -z "$cmd_hostname" -a -z "$cmd_fqdn" ]; then
cmd_fqdn="$cmd_hostname"
fi
if test -z "$cmd_hostname"; then if test -z "$cmd_hostname"; then
echo "Usage: $0 [-h] [-b] [--] <host>" echo "Usage: $0 [-h] [-b] [-n fqdn] [--] <host>"
exit 1 exit 1
fi fi
@ -29,17 +35,18 @@ test -f cosmos.conf && . ./cosmos.conf
defrepo=`git remote -v | grep ${remote:="ro"} | grep fetch | awk '{print $2}'` defrepo=`git remote -v | grep ${remote:="ro"} | grep fetch | awk '{print $2}'`
rrepo=${repo:="$defrepo"} rrepo=${repo:="$defrepo"}
rtag=${tag:="changeme"}
if [ ! -d $cmd_hostname ]; then if [ ! -d $cmd_hostname ]; then
cp -pr default $cmd_hostname cp -pr default $cmd_fqdn
git add $cmd_hostname git add $cmd_fqdn
git commit -m "$cmd_hostname added" $cmd_hostname 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.2-2_all.deb apt/bootstrap-cosmos.sh root@$cmd_hostname: scp apt/cosmos_1.2-2_all.deb apt/bootstrap-cosmos.sh root@$cmd_hostname:
ssh root@$cmd_hostname ./bootstrap-cosmos.sh $cmd_hostname $rrepo 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

View file

@ -4,16 +4,22 @@ set -e
cmd_hostname="$1" cmd_hostname="$1"
if test -z "$cmd_hostname"; then if test -z "$cmd_hostname"; then
echo "Usage: $0 HOSTNAME REPO" echo "Usage: $0 HOSTNAME REPO TAGPATTERN"
exit 1 exit 1
fi fi
cmd_repo="$2" cmd_repo="$2"
if test -z "$cmd_repo"; then if test -z "$cmd_repo"; then
echo "Usage $0 HOSTNAME REPO" echo "Usage $0 HOSTNAME REPO TAGPATTERN"
exit 2 exit 2
fi fi
cmd_tags="$3"
if test -z "$cmd_tags"; then
echo "Usage $0 HOSTNAME REPO TAGPATTERN"
exit 3
fi
set -x set -x
apt-get -y install rsync git-core apt-get -y install rsync git-core
@ -26,7 +32,7 @@ fi
hostname $cmd_hostname hostname $cmd_hostname
perl -pi -e "s,#COSMOS_REPO_MODELS=.*,COSMOS_REPO_MODELS=\"\\\$COSMOS_REPO/global/:\\\$COSMOS_REPO/$cmd_hostname/\"," /etc/cosmos/cosmos.conf perl -pi -e "s,#COSMOS_REPO_MODELS=.*,COSMOS_REPO_MODELS=\"\\\$COSMOS_REPO/global/:\\\$COSMOS_REPO/$cmd_hostname/\"," /etc/cosmos/cosmos.conf
perl -pi -e 's,#COSMOS_UPDATE_VERIFY_GIT_TAG_PATTERN=.*,COSMOS_UPDATE_VERIFY_GIT_TAG_PATTERN="eduid-cosmos*",' /etc/cosmos/cosmos.conf perl -pi -e 's,#COSMOS_UPDATE_VERIFY_GIT_TAG_PATTERN=.*,COSMOS_UPDATE_VERIFY_GIT_TAG_PATTERN="${cmd_tags}*",' /etc/cosmos/cosmos.conf
env COSMOS_BASE=/var/cache/cosmos COSMOS_KEYS=/var/cache/cosmos/repo/global/overlay/etc/cosmos/keys /var/cache/cosmos/repo/global/post-tasks.d/015cosmos-trust env COSMOS_BASE=/var/cache/cosmos COSMOS_KEYS=/var/cache/cosmos/repo/global/overlay/etc/cosmos/keys /var/cache/cosmos/repo/global/post-tasks.d/015cosmos-trust

View file

@ -11,7 +11,7 @@ done
for fp in `cosmos gpg --with-colons --fingerprint | awk -F: '$1 == "pub" {print $5}'`; do for fp in `cosmos gpg --with-colons --fingerprint | awk -F: '$1 == "pub" {print $5}'`; do
seen="no" seen="no"
for k in /etc/cosmos/keys/*.pub; do for k in $COSMOS_KEYS/*.pub; do
cosmos gpg --with-colons --with-fingerprint < $k | grep -q ":$fp:" && seen="yes" cosmos gpg --with-colons --with-fingerprint < $k | grep -q ":$fp:" && seen="yes"
done done
if [ "x$seen" = "xno" ]; then if [ "x$seen" = "xno" ]; then