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

  1. #!/bin/bash
  2. ## 0k git remote path
  3. GIT_0K_BASE=${GIT_0K_BASE:-"0k-ro:/var/git"}
  4. ## 0k git remote options
  5. GIT_0K_CLONE_OPTIONS=${GIT_0K_CLONE_OPTIONS:-""}
  6. ##
  7. ## Install 0k-manage
  8. ##
  9. mkdir -p /opt/apps
  10. (
  11. if ! [ -d "/opt/apps/0k-manage" ]; then
  12. cd /opt/apps &&
  13. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-manage.git" &&
  14. cd /opt/apps/0k-manage &&
  15. git checkout 0k/prod/master
  16. fi
  17. pip install sact.epoch || exit 1
  18. if [ "$(python -c 'import sact.epoch' 2>&1 | tail -n 1)" == "ImportError: No module named interface" ]; then
  19. echo "Error: conflicting installation of zope.interface detected. Trying workaround."
  20. (
  21. cd /usr/local/lib/python2.7/dist-packages
  22. mv zope zope-bad
  23. ) &&
  24. pip install zope.interface --upgrade &&
  25. pip install zope.component --upgrade
  26. if [ "$(python -c 'import sact.epoch' 2>&1 | tail -n 1)" == "" ]; then
  27. echo "Workaround worked."
  28. else
  29. echo "Failed work around."
  30. exit 1
  31. fi
  32. fi
  33. # ln -sf /opt/apps/0k-manage/src/bin/* /usr/local/bin/
  34. )
  35. ##
  36. ## Install 0k-charms
  37. ##
  38. (
  39. if ! [ -d "/opt/apps/0k-charms" ]; then
  40. cd /opt/apps &&
  41. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-charms.git" &&
  42. cd /opt/apps/0k-charms &&
  43. git checkout master
  44. fi
  45. if ! [ -d "/srv/charm-store" ]; then
  46. mkdir -p /srv/charm-store &&
  47. find /opt/apps/0k-charms -type d -exec /usr/bin/test -e {}/metadata.yml \
  48. -o -e {}/metadata.yaml \; -print | while read f; do
  49. ln -sf "$f" /srv/charm-store/
  50. done
  51. fi
  52. )
  53. ##
  54. ## Install lxc-scripts
  55. ##
  56. (
  57. if ! [ -d "/opt/apps/lxc-scripts" ]; then
  58. cd /opt/apps &&
  59. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/lxc-scripts.git" &&
  60. cd /opt/apps/0k-manage &&
  61. git checkout master &&
  62. ln -sf /opt/apps/lxc-scripts/bin/lxc-* /usr/local/sbin/ &&
  63. [ -d /usr/lib/lxc/templates ] && {
  64. ln -sf /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/lib/lxc/templates/
  65. echo TEMPLATE_PATH=/usr/lib/lxc/templates >> /etc/default/lxc
  66. }
  67. [ -d /usr/share/lxc/templates ] && {
  68. ln -sf /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/share/lxc/templates
  69. echo TEMPLATE_PATH=/usr/share/lxc/templates >> /etc/default/lxc
  70. }
  71. fi
  72. )
  73. ##
  74. ## Install 0k.io certificate authority
  75. ##
  76. ## Note that docker should be installed after (or be restarted).
  77. type -p curl >/dev/null 2>&1 || apt-get install -y curl </dev/null
  78. if ! [ -r /etc/ssl/ca.0k.io.pem ]; then
  79. echo "Fetching 0k.io CA certificate..."
  80. curl http://docker.0k.io/get/ca.0k.io.pem > /etc/ssl/ca.0k.io.pem
  81. cat /etc/ssl/ca.0k.io.pem >> /etc/ssl/certs/ca-certificates.crt
  82. fi
  83. service docker restart
  84. echo "Login into our server."
  85. docker login -u vm -p iamavm -e vm@0k.io https://docker.0k.io
  86. sed -ri 's/^#(net\.ipv4\.ip_forward=1)$/\1/g' /etc/sysctl.conf
  87. sysctl -w net.ipv4.ip_forward=1
  88. ##
  89. ## docker-compose
  90. ##
  91. if type -p docker-compose >/dev/null; then
  92. #echo "Found docker-compose..." >&2
  93. if ! docker-compose --version >/dev/null 2>&1; then
  94. echo "'docker-compose' failed ! Please check your docker-compose binary."
  95. echo "Failed install."
  96. docker-compose --version
  97. exit 1
  98. fi
  99. VALID_VERSION_TEXT="docker-compose version 1.6.0dev, build unknown"
  100. if [ "$(docker-compose --version)" != "$VALID_VERSION_TEXT" ]; then
  101. echo "Invalid version of docker-compose: we need exactly:"
  102. echo "version text: $VALID_VERSION_TEXT"
  103. echo "Failed install."
  104. exit 1
  105. fi
  106. else
  107. if ! [ -d /opt/apps/docker-compose ]; then
  108. (
  109. mkdir -p /opt/apps
  110. cd /opt/apps
  111. git clone https://github.com/docker/compose.git docker-compose &&
  112. cd docker-compose &&
  113. git checkout ea8cc1c3dc47c9ed3bff56c5a8d99175b57af650 ## version pinning
  114. )
  115. fi
  116. mkdir -p /opt/venv
  117. if ! type -p virtualenv >/dev/null; then
  118. pip install virtualenv==13.1.2
  119. fi
  120. if ! [ -d /opt/venv/docker-compose ]; then
  121. virtualenv /opt/venv/docker-compose/
  122. fi
  123. . /opt/venv/docker-compose/bin/activate
  124. ( cd /opt/apps/docker-compose &&
  125. python setup.py install )
  126. if ! pip freeze | grep "^requests==2.6.1\$" >/dev/null 2>&1; then
  127. pip install requests==2.6.1 --upgrade
  128. fi
  129. deactivate
  130. mkdir -p /etc/compose
  131. if ! grep "^. /opt/venv/docker-compose/bin/activate$" /etc/compose/local.conf >/dev/null 2>&1; then
  132. cat <<EOF >> /etc/compose/local.conf
  133. . /opt/venv/docker-compose/bin/activate
  134. EOF
  135. fi
  136. fi
  137. if ! [ -d "/opt/apps/0k-compose" ]; then
  138. mkdir -p /opt/apps && cd /opt/apps
  139. git clone "$GIT_0K_BASE"/0k/0k-compose.git
  140. fi
  141. [ -e /usr/local/bin/compose ] || ln -sfv /opt/apps/0k-compose/bin/compose /usr/local/bin/
  142. cat <<EOF > /etc/default/datastore
  143. DATASTORE=/srv/datastore
  144. SNAPSHOT_BACKUP=/var/backups/snapshot
  145. EOF
  146. cat <<EOF > /etc/default/compose
  147. ## if not provided, this will be the default service launched.
  148. export DEFAULT_SERVICES=""
  149. export DEFAULT_PROJECT_NAME=$(hostname | cut -f 2 -d . )
  150. export DOCKER_DATASTORE=\$([ -e /etc/default/datastore ] && . /etc/default/datastore && echo \$DATASTORE)
  151. export DATASTORE=\$DOCKER_DATASTORE/data
  152. export CONFIGSTORE=\$DOCKER_DATASTORE/config
  153. EOF
  154. echo "DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml" >> /etc/compose/local.conf