You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

197 lines
5.5 KiB

#!/bin/bash
## 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 &&
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-charms
##
(
if ! [ -d "/opt/apps/0k-charms" ]; then
cd /opt/apps &&
git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-charms.git" &&
cd /opt/apps/0k-charms &&
git checkout master
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
fi
)
##
## Install lxc-scripts
##
(
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
}
fi
)
##
## Install 0k.io certificate authority
##
## Note that docker should be installed after (or be restarted).
type -p curl >/dev/null 2>&1 || apt-get install -y curl </dev/null
if ! [ -r /etc/ssl/ca.0k.io.pem ]; then
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
fi
service docker restart
echo "Login into our server."
docker login -u vm -p iamavm -e vm@0k.io https://docker.0k.io
sed -ri 's/^#(net\.ipv4\.ip_forward=1)$/\1/g' /etc/sysctl.conf
sysctl -w net.ipv4.ip_forward=1
##
## docker-compose
##
if type -p docker-compose >/dev/null; then
#echo "Found docker-compose..." >&2
if ! docker-compose --version >/dev/null 2>&1; then
echo "'docker-compose' failed ! Please check your docker-compose binary."
echo "Failed install."
docker-compose --version
exit 1
fi
VALID_VERSION_TEXT="docker-compose version 1.6.0dev, build unknown"
if [ "$(docker-compose --version)" != "$VALID_VERSION_TEXT" ]; then
echo "Invalid version of docker-compose: we need exactly:"
echo "version text: $VALID_VERSION_TEXT"
echo "Failed install."
exit 1
fi
else
if ! [ -d /opt/apps/docker-compose ]; then
(
mkdir -p /opt/apps
cd /opt/apps
git clone https://github.com/docker/compose.git docker-compose &&
cd docker-compose &&
git checkout ea8cc1c3dc47c9ed3bff56c5a8d99175b57af650 ## version pinning
)
fi
mkdir -p /opt/venv
if ! type -p virtualenv >/dev/null; then
pip install virtualenv==13.1.2
fi
if ! [ -d /opt/venv/docker-compose ]; then
virtualenv /opt/venv/docker-compose/
fi
. /opt/venv/docker-compose/bin/activate
( cd /opt/apps/docker-compose &&
python setup.py install )
if ! pip freeze | grep "^requests==2.6.1\$" >/dev/null 2>&1; then
pip install requests==2.6.1 --upgrade
fi
deactivate
mkdir -p /etc/compose
if ! grep "^. /opt/venv/docker-compose/bin/activate$" /etc/compose/local.conf >/dev/null 2>&1; then
cat <<EOF >> /etc/compose/local.conf
. /opt/venv/docker-compose/bin/activate
EOF
fi
fi
if ! [ -d "/opt/apps/0k-compose" ]; then
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/
cat <<EOF > /etc/default/datastore
DATASTORE=/srv/datastore
SNAPSHOT_BACKUP=/var/backups/snapshot
EOF
cat <<EOF > /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 . )
export DOCKER_DATASTORE=\$([ -e /etc/default/datastore ] && . /etc/default/datastore && echo \$DATASTORE)
export DATASTORE=\$DOCKER_DATASTORE/data
export CONFIGSTORE=\$DOCKER_DATASTORE/config
EOF
echo "DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml" >> /etc/compose/local.conf