#!/bin/bash set -eux ## 0k git remote path GIT_0K_BASE=${GIT_0K_BASE:-"0k-ro:/var/git"} ## 0k git remote options GIT_0K_CLONE_OPTIONS=${GIT_0K_CLONE_OPTIONS:-""} ## ## Install 0k-manage ## mkdir -p /opt/apps ( 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 && git checkout 0k/prod/master fi pip install sact.epoch || exit 1 if [ "$(python -c 'import sact.epoch' 2>&1 | tail -n 1)" == "ImportError: No module named interface" ]; then echo "Error: conflicting installation of zope.interface detected. Trying workaround." ( cd /usr/local/lib/python2.7/dist-packages mv zope zope-bad ) && pip install zope.interface --upgrade && pip install zope.component --upgrade if [ "$(python -c 'import sact.epoch' 2>&1 | tail -n 1)" == "" ]; then echo "Workaround worked." else echo "Failed work around." exit 1 fi fi # ln -sf /opt/apps/0k-manage/src/bin/* /usr/local/bin/ ) ## ## Install 0k-charm ## ( apt-get install -y kal-shlib-charm kal-shlib-cache kal-shlib-cmdline > /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 } fi ) ## ## Install 0k-docker ## ( if [ -d "/opt/apps/0k-docker" ]; then cd /opt/apps/0k-docker && git checkout master && git pull -r else cd /opt/apps && git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-docker" fi ln -sfn /opt/apps/0k-docker/bin/* /usr/local/sbin/ ln -sfn /opt/apps/0k-docker/bin/docker-clean /etc/cron.daily/docker-clean ## in update, will remove broken links to binaries that were removed find -L /usr/local/sbin -maxdepth 1 -type l -delete ) ## ## Install 0k.io certificate authority ## ## Note that docker should be installed after (or be restarted). 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 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 service docker restart echo "Login into our server." docker login -u vm -p iamavm https://docker.0k.io sed -ri 's/^#(net\.ipv4\.ip_forward=1)$/\1/g' /etc/sysctl.conf sysctl -w net.ipv4.ip_forward=1 ## ## Installation of compose ## docker pull docker.0k.io/compose 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 [ -e /usr/local/bin/compose ] || ln -sfv /opt/apps/0k-compose/bin/compose /usr/local/bin/ rm -rf /var/cache/compose cat < /etc/default/datastore DATASTORE=/srv/datastore SNAPSHOT_BACKUP=/var/backups/snapshot EOF cat < /etc/default/compose ## if not provided, this will be the default service launched. export DEFAULT_SERVICES="" export DEFAULT_PROJECT_NAME=\$(hostname | cut -f 2 -d . ) DEFAULT_PROJECT_NAME=\${DEFAULT_PROJECT_NAME,,} ## to lowercase export DOCKER_DATASTORE=\$([ -e /etc/default/datastore ] && . /etc/default/datastore && echo \$DATASTORE) export DATASTORE=\$DOCKER_DATASTORE/data export CONFIGSTORE=\$DOCKER_DATASTORE/config EOF if ! egrep "^DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml$" /etc/compose/local.conf >/dev/null 2>&1; then mkdir /etc/compose -p touch /etc/compose/local.conf echo "DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml" >> /etc/compose/local.conf fi ## ## Install pgm ## ( 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 && git checkout master fi ln -sf /opt/apps/0k-pgm/bin/* /usr/local/bin/ apt-get install -y --force-yes pv buffer < /dev/null apt-get install -y postgresql-client