From 894bf065f9b9cb125369d84cadc131870ba65df7 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Thu, 19 Jul 2018 17:28:31 +0200 Subject: [PATCH] new: [docker-host] change all install script to support update. --- precise/base-0k/hooks/install.d/05-shyaml.sh | 2 +- .../base-0k/hooks/install.d/15-etckeeper.sh | 7 +- .../base-0k/hooks/install.d/30-customize.sh | 6 ++ .../base-0k/hooks/install.d/35-git-access.sh | 12 ++- precise/base-0k/hooks/install.d/36-gitsub.sh | 16 ++-- precise/host/hooks/install.d/70-0k.sh | 90 +++++++++++-------- 6 files changed, 83 insertions(+), 50 deletions(-) diff --git a/precise/base-0k/hooks/install.d/05-shyaml.sh b/precise/base-0k/hooks/install.d/05-shyaml.sh index 2760292..b5bbb38 100755 --- a/precise/base-0k/hooks/install.d/05-shyaml.sh +++ b/precise/base-0k/hooks/install.d/05-shyaml.sh @@ -4,4 +4,4 @@ apt-get install -y --force-yes python-pip libyaml-dev python-dev > /root/.bashrc ## History management diff --git a/precise/base-0k/hooks/install.d/35-git-access.sh b/precise/base-0k/hooks/install.d/35-git-access.sh index 45e0ff2..f687226 100755 --- a/precise/base-0k/hooks/install.d/35-git-access.sh +++ b/precise/base-0k/hooks/install.d/35-git-access.sh @@ -12,8 +12,14 @@ SSH_CONFIG_DIR=~/.ssh mkdir -p "$SSH_CONFIG_DIR" -if ! grep '^Host 0k-ro' "$SSH_CONFIG_DIR"/config >/dev/null 2>&1; then - cat <> "$SSH_CONFIG_DIR"/config +if ! [ -e "$SSH_CONFIG_DIR/config.pre-install" ]; then + cp "$SSH_CONFIG_DIR/config" "$SSH_CONFIG_DIR/config.pre-install" +else + cp "$SSH_CONFIG_DIR/config.pre-install" "$SSH_CONFIG_DIR/config" +fi + + +cat <> "$SSH_CONFIG_DIR"/config Host 0k-ro Hostname git.0k.io @@ -24,5 +30,3 @@ Host 0k-ro StrictHostKeyChecking no EOF - -fi diff --git a/precise/base-0k/hooks/install.d/36-gitsub.sh b/precise/base-0k/hooks/install.d/36-gitsub.sh index 7e43796..dcb4556 100755 --- a/precise/base-0k/hooks/install.d/36-gitsub.sh +++ b/precise/base-0k/hooks/install.d/36-gitsub.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -eux # -x for verbose logging to juju debug-log +set -eux ## 0k git remote path @@ -14,7 +14,13 @@ GIT_0K_CLONE_OPTIONS=${GIT_0K_CLONE_OPTIONS:-""} ## install git sub ## -mkdir -p /opt/apps && -cd /opt/apps && -git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE"/0k/git-sub && -ln -sf /opt/apps/git-sub/bin/git-sub /usr/lib/git-core/ +if [ -d /opt/apps/git-sub ]; then + cd /opt/apps/git-sub && + git pull -r +else + mkdir -p /opt/apps && + cd /opt/apps && + git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE"/0k/git-sub +fi + +ln -sf /opt/apps/git-sub/bin/git-sub /usr/lib/git-core/git-sub diff --git a/precise/host/hooks/install.d/70-0k.sh b/precise/host/hooks/install.d/70-0k.sh index adc8aa4..7c0ee31 100755 --- a/precise/host/hooks/install.d/70-0k.sh +++ b/precise/host/hooks/install.d/70-0k.sh @@ -15,7 +15,10 @@ GIT_0K_CLONE_OPTIONS=${GIT_0K_CLONE_OPTIONS:-""} mkdir -p /opt/apps ( - if ! [ -d "/opt/apps/0k-manage" ]; then + if [ -d "/opt/apps/0k-manage" ]; then + cd /opt/apps/0k-manage && + git pull -r + else cd /opt/apps && git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-manage.git" && cd /opt/apps/0k-manage && @@ -48,20 +51,19 @@ mkdir -p /opt/apps ## ( - if ! [ -d "/opt/apps/0k-charms" ]; then - cd /opt/apps && - git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-charms.git" && + if [ -d "/opt/apps/0k-charms" ]; then cd /opt/apps/0k-charms && - git checkout master + git checkout master && + git pull -r + else + cd /opt/apps && + git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-charms.git" fi if ! [ -d "/srv/charm-store" ]; then - mkdir -p /srv/charm-store && - find /opt/apps/0k-charms -type d -exec /usr/bin/test -e {}/metadata.yml \ - -o -e {}/metadata.yaml \; -print | while read f; do - ln -sf "$f" /srv/charm-store/ - done + mkdir -p /srv/charm-store fi + ln -sfn /opt/apps/0k-charms /srv/charm-store/0k-charms ) @@ -73,19 +75,27 @@ mkdir -p /opt/apps ( if ! [ -d "/opt/apps/lxc-scripts" ]; then cd /opt/apps && - git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/lxc-scripts.git" && - cd /opt/apps/0k-manage && - git checkout master && - ln -sf /opt/apps/lxc-scripts/bin/lxc-* /usr/local/sbin/ && - [ -d /usr/lib/lxc/templates ] && { - ln -sf /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/lib/lxc/templates/ - echo TEMPLATE_PATH=/usr/lib/lxc/templates >> /etc/default/lxc - } - [ -d /usr/share/lxc/templates ] && { - ln -sf /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/share/lxc/templates - echo TEMPLATE_PATH=/usr/share/lxc/templates >> /etc/default/lxc - } + git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/lxc-scripts.git" + fi + + cd /opt/apps/lxc-scripts && + git checkout master && + git pull -r && + ln -sfn /opt/apps/lxc-scripts/bin/lxc-* /usr/local/sbin/ && + + if [ -f /etc/default/lxc.pre-install ]; then + cp /etc/default/lxc.pre-install /etc/default/lxc + else + cp /etc/default/lxc /etc/default/lxc.pre-install fi + [ -d /usr/lib/lxc/templates ] && { + ln -sfn /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/lib/lxc/templates/ + echo TEMPLATE_PATH=/usr/lib/lxc/templates >> /etc/default/lxc + } + [ -d /usr/share/lxc/templates ] && { + ln -sfn /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/share/lxc/templates + echo TEMPLATE_PATH=/usr/share/lxc/templates >> /etc/default/lxc + } ) ## @@ -94,19 +104,18 @@ mkdir -p /opt/apps ## Note that docker should be installed after (or be restarted). -type -p curl >/dev/null 2>&1 || apt-get install -y curl /etc/ssl/ca.0k.io.pem - cat /etc/ssl/ca.0k.io.pem >> /etc/ssl/certs/ca-certificates.crt +## This does not seem to work anymore (docker v1.12, ubutnu 14.04 on gani) +echo "Fetching 0k.io CA certificate..." +curl http://docker.0k.io/get/ca.0k.io.pem > /etc/ssl/ca.0k.io.pem +cat /etc/ssl/ca.0k.io.pem >> /etc/ssl/certs/ca-certificates.crt + +## This is the new way: https://docs.docker.com/engine/security/certificates/ +mkdir -p /etc/docker/certs.d/docker.0k.io +ln -sfn /etc/ssl/ca.0k.io.pem /etc/docker/certs.d/docker.0k.io/ca.crt - ## This is the new way: https://docs.docker.com/engine/security/certificates/ - mkdir -p /etc/docker/certs.d/docker.0k.io - ln -sf /etc/ssl/ca.0k.io.pem /etc/docker/certs.d/docker.0k.io/ca.crt -fi service docker restart @@ -173,7 +182,10 @@ EOF fi fi -if ! [ -d "/opt/apps/0k-compose" ]; then +if [ -d "/opt/apps/0k-compose" ]; then + cd "/opt/apps/0k-compose" && + git pull -r +else mkdir -p /opt/apps && cd /opt/apps git clone "$GIT_0K_BASE"/0k/0k-compose.git fi @@ -197,8 +209,9 @@ export CONFIGSTORE=\$DOCKER_DATASTORE/config EOF - -echo "DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml" >> /etc/compose/local.conf +if ! egrep "^DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml$" /etc/compose/local.conf >/dev/null 2>&1; then + echo "DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml" >> /etc/compose/local.conf +fi ## @@ -207,7 +220,10 @@ echo "DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml" >> /etc/compose/local.conf ( - if ! [ -d "/opt/apps/0k-pgm" ]; then + if [ -d "/opt/apps/0k-pgm" ]; then + cd /opt/apps/0k-pgm && + git pull -r + else cd /opt/apps && git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-pgm.git" && cd /opt/apps/0k-pgm && @@ -216,6 +232,6 @@ echo "DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml" >> /etc/compose/local.conf ln -sf /opt/apps/0k-pgm/bin/* /usr/local/bin/ apt-get install -y --force-yes pv buffer < /dev/null - require psql || apt-get install -y postgresql-client