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.

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