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.

237 lines
6.3 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/0k-manage &&
  13. git pull -r
  14. else
  15. cd /opt/apps &&
  16. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-manage.git" &&
  17. cd /opt/apps/0k-manage &&
  18. git checkout 0k/prod/master
  19. fi
  20. pip install sact.epoch || exit 1
  21. if [ "$(python -c 'import sact.epoch' 2>&1 | tail -n 1)" == "ImportError: No module named interface" ]; then
  22. echo "Error: conflicting installation of zope.interface detected. Trying workaround."
  23. (
  24. cd /usr/local/lib/python2.7/dist-packages
  25. mv zope zope-bad
  26. ) &&
  27. pip install zope.interface --upgrade &&
  28. pip install zope.component --upgrade
  29. if [ "$(python -c 'import sact.epoch' 2>&1 | tail -n 1)" == "" ]; then
  30. echo "Workaround worked."
  31. else
  32. echo "Failed work around."
  33. exit 1
  34. fi
  35. fi
  36. # ln -sf /opt/apps/0k-manage/src/bin/* /usr/local/bin/
  37. )
  38. ##
  39. ## Install 0k-charms
  40. ##
  41. (
  42. if [ -d "/opt/apps/0k-charms" ]; then
  43. cd /opt/apps/0k-charms &&
  44. git checkout master &&
  45. git pull -r
  46. else
  47. cd /opt/apps &&
  48. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-charms.git"
  49. fi
  50. if ! [ -d "/srv/charm-store" ]; then
  51. mkdir -p /srv/charm-store
  52. fi
  53. ln -sfn /opt/apps/0k-charms /srv/charm-store/0k-charms
  54. )
  55. ##
  56. ## Install lxc-scripts
  57. ##
  58. (
  59. if ! [ -d "/opt/apps/lxc-scripts" ]; then
  60. cd /opt/apps &&
  61. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/lxc-scripts.git"
  62. fi
  63. cd /opt/apps/lxc-scripts &&
  64. git checkout master &&
  65. git pull -r &&
  66. ln -sfn /opt/apps/lxc-scripts/bin/lxc-* /usr/local/sbin/ &&
  67. if [ -f /etc/default/lxc.pre-install ]; then
  68. cp /etc/default/lxc.pre-install /etc/default/lxc
  69. else
  70. cp /etc/default/lxc /etc/default/lxc.pre-install
  71. fi
  72. [ -d /usr/lib/lxc/templates ] && {
  73. ln -sfn /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/lib/lxc/templates/
  74. echo TEMPLATE_PATH=/usr/lib/lxc/templates >> /etc/default/lxc
  75. }
  76. [ -d /usr/share/lxc/templates ] && {
  77. ln -sfn /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/share/lxc/templates
  78. echo TEMPLATE_PATH=/usr/share/lxc/templates >> /etc/default/lxc
  79. }
  80. )
  81. ##
  82. ## Install 0k.io certificate authority
  83. ##
  84. ## Note that docker should be installed after (or be restarted).
  85. apt-get install -y curl </dev/null
  86. ## This does not seem to work anymore (docker v1.12, ubutnu 14.04 on gani)
  87. echo "Fetching 0k.io CA certificate..."
  88. curl http://docker.0k.io/get/ca.0k.io.pem > /etc/ssl/ca.0k.io.pem
  89. cat /etc/ssl/ca.0k.io.pem >> /etc/ssl/certs/ca-certificates.crt
  90. ## This is the new way: https://docs.docker.com/engine/security/certificates/
  91. mkdir -p /etc/docker/certs.d/docker.0k.io
  92. ln -sfn /etc/ssl/ca.0k.io.pem /etc/docker/certs.d/docker.0k.io/ca.crt
  93. service docker restart
  94. echo "Login into our server."
  95. docker login -u vm -p iamavm -e vm@0k.io https://docker.0k.io
  96. sed -ri 's/^#(net\.ipv4\.ip_forward=1)$/\1/g' /etc/sysctl.conf
  97. sysctl -w net.ipv4.ip_forward=1
  98. ##
  99. ## docker-compose
  100. ##
  101. if type -p docker-compose >/dev/null; then
  102. #echo "Found docker-compose..." >&2
  103. if ! docker-compose --version >/dev/null 2>&1; then
  104. echo "'docker-compose' failed ! Please check your docker-compose binary."
  105. echo "Failed install."
  106. docker-compose --version
  107. exit 1
  108. fi
  109. VALID_VERSION_TEXT="docker-compose version 1.21.2, build a133471"
  110. if [ "$(docker-compose --version)" != "$VALID_VERSION_TEXT" ]; then
  111. echo "Invalid version of docker-compose: we need exactly:"
  112. echo "version text: $VALID_VERSION_TEXT"
  113. echo "Failed install."
  114. exit 1
  115. fi
  116. else
  117. if ! [ -d /opt/apps/docker-compose ]; then
  118. (
  119. mkdir -p /opt/apps
  120. cd /opt/apps
  121. git clone https://github.com/docker/compose.git docker-compose &&
  122. cd docker-compose &&
  123. git checkout 0898c783ad2e0d01bd55b47fcb9eb7183edc1015 ## version pinning
  124. )
  125. fi
  126. mkdir -p /opt/venv
  127. if ! type -p virtualenv >/dev/null; then
  128. pip install virtualenv==13.1.2
  129. fi
  130. if ! [ -d /opt/venv/docker-compose ]; then
  131. virtualenv /opt/venv/docker-compose/
  132. fi
  133. . /opt/venv/docker-compose/bin/activate
  134. ( cd /opt/apps/docker-compose &&
  135. python setup.py install )
  136. if ! pip freeze | grep "^requests==2.17.3\$" >/dev/null 2>&1; then
  137. pip install requests==2.17.3 --upgrade
  138. fi
  139. deactivate
  140. mkdir -p /etc/compose
  141. if ! grep "^. /opt/venv/docker-compose/bin/activate$" /etc/compose/local.conf >/dev/null 2>&1; then
  142. cat <<EOF >> /etc/compose/local.conf
  143. . /opt/venv/docker-compose/bin/activate
  144. EOF
  145. fi
  146. fi
  147. if [ -d "/opt/apps/0k-compose" ]; then
  148. cd "/opt/apps/0k-compose" &&
  149. git pull -r
  150. else
  151. mkdir -p /opt/apps && cd /opt/apps
  152. git clone "$GIT_0K_BASE"/0k/0k-compose.git
  153. fi
  154. [ -e /usr/local/bin/compose ] || ln -sfv /opt/apps/0k-compose/bin/compose /usr/local/bin/
  155. cat <<EOF > /etc/default/datastore
  156. DATASTORE=/srv/datastore
  157. SNAPSHOT_BACKUP=/var/backups/snapshot
  158. EOF
  159. cat <<EOF > /etc/default/compose
  160. ## if not provided, this will be the default service launched.
  161. export DEFAULT_SERVICES=""
  162. export DEFAULT_PROJECT_NAME=$(hostname | cut -f 2 -d . )
  163. export DOCKER_DATASTORE=\$([ -e /etc/default/datastore ] && . /etc/default/datastore && echo \$DATASTORE)
  164. export DATASTORE=\$DOCKER_DATASTORE/data
  165. export CONFIGSTORE=\$DOCKER_DATASTORE/config
  166. EOF
  167. if ! egrep "^DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml$" /etc/compose/local.conf >/dev/null 2>&1; then
  168. echo "DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml" >> /etc/compose/local.conf
  169. fi
  170. ##
  171. ## Install pgm
  172. ##
  173. (
  174. if [ -d "/opt/apps/0k-pgm" ]; then
  175. cd /opt/apps/0k-pgm &&
  176. git pull -r
  177. else
  178. cd /opt/apps &&
  179. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-pgm.git" &&
  180. cd /opt/apps/0k-pgm &&
  181. git checkout master
  182. fi
  183. ln -sf /opt/apps/0k-pgm/bin/* /usr/local/bin/
  184. apt-get install -y --force-yes pv buffer < /dev/null
  185. apt-get install -y postgresql-client </dev/null
  186. )