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.

236 lines
5.9 KiB

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