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.

287 lines
7.7 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 ! CURRENT_VERSION_TEXT="$(docker-compose --version 2>/dev/null)"; 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 "
  143. if ! [[ "$CURRENT_VERSION_TEXT" == "$VALID_VERSION_TEXT"* ]]; then
  144. echo "Invalid version of docker-compose: we need exactly:"
  145. echo "version text: $VALID_VERSION_TEXT"
  146. echo "current version: $CURRENT_VERSION_TEXT"
  147. echo "Failed install."
  148. exit 1
  149. fi
  150. else
  151. if ! [ -d /opt/apps/docker-compose ]; then
  152. (
  153. mkdir -p /opt/apps
  154. cd /opt/apps
  155. git clone https://github.com/docker/compose.git docker-compose &&
  156. cd docker-compose &&
  157. git checkout 0898c783ad2e0d01bd55b47fcb9eb7183edc1015 ## version pinning
  158. )
  159. fi
  160. mkdir -p /opt/venv
  161. if ! type -p virtualenv >/dev/null; then
  162. pip install virtualenv==13.1.2
  163. fi
  164. if ! [ -d /opt/venv/docker-compose ]; then
  165. virtualenv /opt/venv/docker-compose/
  166. fi
  167. . /opt/venv/docker-compose/bin/activate
  168. ## XXXvlab: docker version 3.5.0 is bugged on its requirement list:
  169. ## 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'
  170. pip install docker==3.4.1
  171. ( cd /opt/apps/docker-compose &&
  172. python setup.py install )
  173. if ! pip freeze | grep "^requests==2.17.3\$" >/dev/null 2>&1; then
  174. pip install requests==2.17.3 --upgrade
  175. fi
  176. deactivate
  177. mkdir -p /etc/compose
  178. if ! grep "^. /opt/venv/docker-compose/bin/activate$" /etc/compose/local.conf >/dev/null 2>&1; then
  179. cat <<EOF >> /etc/compose/local.conf
  180. . /opt/venv/docker-compose/bin/activate
  181. EOF
  182. fi
  183. fi
  184. if [ -d "/opt/apps/0k-compose" ]; then
  185. cd "/opt/apps/0k-compose" &&
  186. git pull -r
  187. else
  188. mkdir -p /opt/apps && cd /opt/apps
  189. git clone "$GIT_0K_BASE"/0k/0k-compose.git
  190. fi
  191. [ -e /usr/local/bin/compose ] || ln -sfv /opt/apps/0k-compose/bin/compose /usr/local/bin/
  192. rm -rf /var/cache/compose
  193. cat <<EOF > /etc/default/datastore
  194. DATASTORE=/srv/datastore
  195. SNAPSHOT_BACKUP=/var/backups/snapshot
  196. EOF
  197. cat <<EOF > /etc/default/compose
  198. ## if not provided, this will be the default service launched.
  199. export DEFAULT_SERVICES=""
  200. export DEFAULT_PROJECT_NAME=$(hostname | cut -f 2 -d . )
  201. export DOCKER_DATASTORE=\$([ -e /etc/default/datastore ] && . /etc/default/datastore && echo \$DATASTORE)
  202. export DATASTORE=\$DOCKER_DATASTORE/data
  203. export CONFIGSTORE=\$DOCKER_DATASTORE/config
  204. EOF
  205. if ! egrep "^DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml$" /etc/compose/local.conf >/dev/null 2>&1; then
  206. echo "DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml" >> /etc/compose/local.conf
  207. fi
  208. ##
  209. ## Install pgm
  210. ##
  211. (
  212. if [ -d "/opt/apps/0k-pgm" ]; then
  213. cd /opt/apps/0k-pgm &&
  214. git pull -r
  215. else
  216. cd /opt/apps &&
  217. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-pgm.git" &&
  218. cd /opt/apps/0k-pgm &&
  219. git checkout master
  220. fi
  221. ln -sf /opt/apps/0k-pgm/bin/* /usr/local/bin/
  222. apt-get install -y --force-yes pv buffer < /dev/null
  223. apt-get install -y postgresql-client </dev/null
  224. )