From 585f3dac8a507a07900f36837f5c60eb218eb189 Mon Sep 17 00:00:00 2001 From: Maria Haider Date: Tue, 13 Sep 2022 14:46:08 +0200 Subject: [PATCH] New boostrap and addhost scripts for servers in Test environment --- addhost-test | 57 +++++++++++++++++++ .../etc/cosmos/apt/bootstrap-cosmos-test.sh | 49 ++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100755 addhost-test create mode 100755 global/overlay/etc/cosmos/apt/bootstrap-cosmos-test.sh diff --git a/addhost-test b/addhost-test new file mode 100755 index 00000000..f2f7897e --- /dev/null +++ b/addhost-test @@ -0,0 +1,57 @@ +#!/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] [--] []"; exit 0;; + (-b) cmd_do_bootstrap="yes" ;; + (-n) cmd_fqdn="$2" ; shift ;; + (--) shift; break;; + (-*) echo "Unknown option $1\nUsage: $0 [-b] [-h] [-n fqdn] [--] "; 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] [--] " + 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-test.sh root@$cmd_hostname: + ssh root@$cmd_hostname ./bootstrap-cosmos-test.sh $cmd_fqdn $rrepo $rtag + ssh root@$cmd_hostname cosmos -v update + ssh root@$cmd_hostname cosmos -v apply +fi diff --git a/global/overlay/etc/cosmos/apt/bootstrap-cosmos-test.sh b/global/overlay/etc/cosmos/apt/bootstrap-cosmos-test.sh new file mode 100755 index 00000000..6ebf5620 --- /dev/null +++ b/global/overlay/etc/cosmos/apt/bootstrap-cosmos-test.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +#set -e +# not all breakage is un-recoverable... + +cmd_hostname="$1" +if test -z "$cmd_hostname"; then + echo "Usage: $0 HOSTNAME REPO TAGPATTERN" + exit 1 +fi + +cmd_repo="$2" +if test -z "$cmd_repo"; then + echo "Usage $0 HOSTNAME REPO TAGPATTERN" + exit 2 +fi + +cmd_tags="$3" +if test -z "$cmd_tags"; then + echo "Usage $0 HOSTNAME REPO TAGPATTERN" + exit 3 +fi + +apt-get -y update +apt-get -y upgrade +for pkg in rsync git git-core wget; do + apt-get -y install $pkg +done +dpkg -i cosmos_1.5-1_all.deb + +if ! test -d /var/cache/cosmos/repo; then + cosmos clone "$cmd_repo" +fi + +hostname $cmd_hostname +short=`echo ${cmd_hostname} | awk -F. '{print $1}'` +echo "127.0.1.1 ${cmd_hostname} ${short}" >> /etc/hosts + +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=\"${cmd_tags}*\"," /etc/cosmos/cosmos.conf + +echo "CONFIG=/etc/puppet/cosmos-modules-test.conf" >> /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 + +(date; nohup cosmos -v update && nohup cosmos -v apply; date) 2>&1 | tee /var/log/cosmos.log + + +exit 0