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.

286 lines
7.6 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. ## XXXvlab: docker version 3.5.0 is bugged on its requirement list:
  168. ## error: Setup script exited with error in docker setup command: 'tests_require' must be a string or list of strings containing valid project/version requirement specifiers; Expected ',' or end-of-list in pytest==2.9.1; python_version == '3.3' at ; python_version == '3.3'
  169. pip install docker==3.4.1
  170. ( cd /opt/apps/docker-compose &&
  171. python setup.py install )
  172. if ! pip freeze | grep "^requests==2.17.3\$" >/dev/null 2>&1; then
  173. pip install requests==2.17.3 --upgrade
  174. fi
  175. deactivate
  176. mkdir -p /etc/compose
  177. if ! grep "^. /opt/venv/docker-compose/bin/activate$" /etc/compose/local.conf >/dev/null 2>&1; then
  178. cat <<EOF >> /etc/compose/local.conf
  179. . /opt/venv/docker-compose/bin/activate
  180. EOF
  181. fi
  182. fi
  183. if [ -d "/opt/apps/0k-compose" ]; then
  184. cd "/opt/apps/0k-compose" &&
  185. git pull -r
  186. else
  187. mkdir -p /opt/apps && cd /opt/apps
  188. git clone "$GIT_0K_BASE"/0k/0k-compose.git
  189. fi
  190. [ -e /usr/local/bin/compose ] || ln -sfv /opt/apps/0k-compose/bin/compose /usr/local/bin/
  191. rm -rf /var/cache/compose
  192. cat <<EOF > /etc/default/datastore
  193. DATASTORE=/srv/datastore
  194. SNAPSHOT_BACKUP=/var/backups/snapshot
  195. EOF
  196. cat <<EOF > /etc/default/compose
  197. ## if not provided, this will be the default service launched.
  198. export DEFAULT_SERVICES=""
  199. export DEFAULT_PROJECT_NAME=$(hostname | cut -f 2 -d . )
  200. export DOCKER_DATASTORE=\$([ -e /etc/default/datastore ] && . /etc/default/datastore && echo \$DATASTORE)
  201. export DATASTORE=\$DOCKER_DATASTORE/data
  202. export CONFIGSTORE=\$DOCKER_DATASTORE/config
  203. EOF
  204. if ! egrep "^DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml$" /etc/compose/local.conf >/dev/null 2>&1; then
  205. echo "DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml" >> /etc/compose/local.conf
  206. fi
  207. ##
  208. ## Install pgm
  209. ##
  210. (
  211. if [ -d "/opt/apps/0k-pgm" ]; then
  212. cd /opt/apps/0k-pgm &&
  213. git pull -r
  214. else
  215. cd /opt/apps &&
  216. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-pgm.git" &&
  217. cd /opt/apps/0k-pgm &&
  218. git checkout master
  219. fi
  220. ln -sf /opt/apps/0k-pgm/bin/* /usr/local/bin/
  221. apt-get install -y --force-yes pv buffer < /dev/null
  222. apt-get install -y postgresql-client </dev/null
  223. )