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.

278 lines
7.1 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-charm
  40. ##
  41. (
  42. if [ -d "/opt/apps/0k-charm" ]; then
  43. cd /opt/apps/0k-charm &&
  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-charm.git"
  49. fi
  50. ln -sfn /opt/apps/0k-charm/bin/charm /usr/local/sbin/
  51. )
  52. apt-get install -y kal-shlib-charm </dev/null
  53. ##
  54. ## Install 0k-charms
  55. ##
  56. (
  57. if [ -d "/opt/apps/0k-charms" ]; then
  58. cd /opt/apps/0k-charms &&
  59. git checkout master &&
  60. git pull -r
  61. else
  62. cd /opt/apps &&
  63. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-charms.git"
  64. fi
  65. if ! [ -d "/srv/charm-store" ]; then
  66. mkdir -p /srv/charm-store
  67. fi
  68. ln -sfn /opt/apps/0k-charms /srv/charm-store/0k-charms
  69. )
  70. ##
  71. ## Install lxc-scripts
  72. ##
  73. (
  74. if ! [ -d "/opt/apps/lxc-scripts" ]; then
  75. cd /opt/apps &&
  76. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/lxc-scripts.git"
  77. fi
  78. cd /opt/apps/lxc-scripts &&
  79. git checkout master &&
  80. git pull -r &&
  81. ln -sfn /opt/apps/lxc-scripts/bin/lxc-* /usr/local/sbin/ &&
  82. if [ -f /etc/default/lxc.pre-install ]; then
  83. cp /etc/default/lxc.pre-install /etc/default/lxc
  84. else
  85. cp /etc/default/lxc /etc/default/lxc.pre-install
  86. fi
  87. [ -d /usr/lib/lxc/templates ] && {
  88. ln -sfn /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/lib/lxc/templates/
  89. echo TEMPLATE_PATH=/usr/lib/lxc/templates >> /etc/default/lxc
  90. }
  91. [ -d /usr/share/lxc/templates ] && {
  92. ln -sfn /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/share/lxc/templates
  93. echo TEMPLATE_PATH=/usr/share/lxc/templates >> /etc/default/lxc
  94. }
  95. )
  96. ##
  97. ## Install 0k-docker
  98. ##
  99. (
  100. if [ -d "/opt/apps/0k-docker" ]; then
  101. cd /opt/apps/0k-docker &&
  102. git checkout master &&
  103. git pull -r
  104. else
  105. cd /opt/apps &&
  106. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-docker"
  107. fi
  108. ln -sfn /opt/apps/0k-docker/bin/* /usr/local/sbin/
  109. ## in update, will remove broken links to binaries that were removed
  110. find -L /usr/local/sbin -maxdepth 1 -type l -delete
  111. )
  112. ##
  113. ## Install 0k.io certificate authority
  114. ##
  115. ## Note that docker should be installed after (or be restarted).
  116. apt-get install -y curl </dev/null
  117. ## This does not seem to work anymore (docker v1.12, ubutnu 14.04 on gani)
  118. echo "Fetching 0k.io CA certificate..."
  119. curl http://docker.0k.io/get/ca.0k.io.pem > /etc/ssl/ca.0k.io.pem
  120. cat /etc/ssl/ca.0k.io.pem >> /etc/ssl/certs/ca-certificates.crt
  121. ## This is the new way: https://docs.docker.com/engine/security/certificates/
  122. mkdir -p /etc/docker/certs.d/docker.0k.io
  123. ln -sfn /etc/ssl/ca.0k.io.pem /etc/docker/certs.d/docker.0k.io/ca.crt
  124. service docker restart
  125. echo "Login into our server."
  126. docker login -u vm -p iamavm https://docker.0k.io
  127. sed -ri 's/^#(net\.ipv4\.ip_forward=1)$/\1/g' /etc/sysctl.conf
  128. sysctl -w net.ipv4.ip_forward=1
  129. ##
  130. ## docker-compose
  131. ##
  132. if type -p docker-compose >/dev/null; then
  133. #echo "Found docker-compose..." >&2
  134. if ! docker-compose --version >/dev/null 2>&1; then
  135. echo "'docker-compose' failed ! Please check your docker-compose binary."
  136. echo "Failed install."
  137. docker-compose --version
  138. exit 1
  139. fi
  140. VALID_VERSION_TEXT="docker-compose version 1.21.2, build a133471"
  141. if [ "$(docker-compose --version)" != "$VALID_VERSION_TEXT" ]; then
  142. echo "Invalid version of docker-compose: we need exactly:"
  143. echo "version text: $VALID_VERSION_TEXT"
  144. echo "Failed install."
  145. exit 1
  146. fi
  147. else
  148. if ! [ -d /opt/apps/docker-compose ]; then
  149. (
  150. mkdir -p /opt/apps
  151. cd /opt/apps
  152. git clone https://github.com/docker/compose.git docker-compose &&
  153. cd docker-compose &&
  154. git checkout 0898c783ad2e0d01bd55b47fcb9eb7183edc1015 ## version pinning
  155. )
  156. fi
  157. mkdir -p /opt/venv
  158. if ! type -p virtualenv >/dev/null; then
  159. pip install virtualenv==13.1.2
  160. fi
  161. if ! [ -d /opt/venv/docker-compose ]; then
  162. virtualenv /opt/venv/docker-compose/
  163. fi
  164. . /opt/venv/docker-compose/bin/activate
  165. ( cd /opt/apps/docker-compose &&
  166. python setup.py install )
  167. if ! pip freeze | grep "^requests==2.17.3\$" >/dev/null 2>&1; then
  168. pip install requests==2.17.3 --upgrade
  169. fi
  170. deactivate
  171. mkdir -p /etc/compose
  172. if ! grep "^. /opt/venv/docker-compose/bin/activate$" /etc/compose/local.conf >/dev/null 2>&1; then
  173. cat <<EOF >> /etc/compose/local.conf
  174. . /opt/venv/docker-compose/bin/activate
  175. EOF
  176. fi
  177. fi
  178. if [ -d "/opt/apps/0k-compose" ]; then
  179. cd "/opt/apps/0k-compose" &&
  180. git pull -r
  181. else
  182. mkdir -p /opt/apps && cd /opt/apps
  183. git clone "$GIT_0K_BASE"/0k/0k-compose.git
  184. fi
  185. [ -e /usr/local/bin/compose ] || ln -sfv /opt/apps/0k-compose/bin/compose /usr/local/bin/
  186. cat <<EOF > /etc/default/datastore
  187. DATASTORE=/srv/datastore
  188. SNAPSHOT_BACKUP=/var/backups/snapshot
  189. EOF
  190. cat <<EOF > /etc/default/compose
  191. ## if not provided, this will be the default service launched.
  192. export DEFAULT_SERVICES=""
  193. export DEFAULT_PROJECT_NAME=$(hostname | cut -f 2 -d . )
  194. export DOCKER_DATASTORE=\$([ -e /etc/default/datastore ] && . /etc/default/datastore && echo \$DATASTORE)
  195. export DATASTORE=\$DOCKER_DATASTORE/data
  196. export CONFIGSTORE=\$DOCKER_DATASTORE/config
  197. EOF
  198. if ! egrep "^DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml$" /etc/compose/local.conf >/dev/null 2>&1; then
  199. echo "DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml" >> /etc/compose/local.conf
  200. fi
  201. ##
  202. ## Install pgm
  203. ##
  204. (
  205. if [ -d "/opt/apps/0k-pgm" ]; then
  206. cd /opt/apps/0k-pgm &&
  207. git pull -r
  208. else
  209. cd /opt/apps &&
  210. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-pgm.git" &&
  211. cd /opt/apps/0k-pgm &&
  212. git checkout master
  213. fi
  214. ln -sf /opt/apps/0k-pgm/bin/* /usr/local/bin/
  215. apt-get install -y --force-yes pv buffer < /dev/null
  216. apt-get install -y postgresql-client </dev/null
  217. )