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.

136 lines
3.8 KiB

  1. #!/bin/bash
  2. ## Installing base docker-host
  3. wget http://docker.0k.io/get/ -qO - | bash || exit 1
  4. ## shlib is now available
  5. . /etc/shlib || {
  6. echo "shlib is not available. Bailing out." >&2
  7. exit 1
  8. }
  9. clone_or_update() {
  10. local pkg="$1" branch=${2:-master} \
  11. DEPLOY_PATH="/opt/apps" \
  12. GIT_BASE="https://git.myceliandre.fr/Myceliandre" \
  13. current_branch
  14. if [ -d "$DEPLOY_PATH/$pkg" ]; then
  15. cd "$DEPLOY_PATH/$pkg"
  16. current_branch=$(git rev-parse --abbrev-ref HEAD)
  17. if [ "$current_branch" != "$branch" ]; then
  18. echo "Fatal: $DEPLOY_PATH/$pkg git repos has unexpected branch checkouted."
  19. echo " To avoid changing thing, we prefer to bailout."
  20. return 1
  21. fi
  22. git pull -r || return 1
  23. else
  24. mkdir -p "$DEPLOY_PATH" && cd "$DEPLOY_PATH"
  25. git clone "$GIT_BASE/${pkg}" -b "$branch" --depth=1
  26. fi
  27. }
  28. install_bin() {
  29. local path="$1" DEST_PATH=/usr/local/bin
  30. ln -sfnv "$path"/* "$DEST_PATH" || return 1
  31. find -L "$DEST_PATH" -maxdepth 1 -type l -ilname "$path"/\* -exec rm -v {} \; || return 1
  32. }
  33. set -e
  34. clone_or_update myc-manage || exit 1
  35. install_bin /opt/apps/myc-manage/bin
  36. clone_or_update myc-deploy || exit 1
  37. #[ -e /etc/compose.conf ] || ln -sfv /opt/apps/myc-deploy/etc/compose.conf /etc/compose.conf
  38. ## XXXvlab: should get rid of this file in some future
  39. cd /opt/apps/myc-deploy
  40. if ! grep "^DEFAULT_COMPOSE_FILE=$PWD/compose.yml$" /etc/compose/local.conf >/dev/null 2>&1; then
  41. echo "Adding CWD=$PWD to docker-compose."
  42. cat <<EOF >> /etc/compose/local.conf
  43. DEFAULT_COMPOSE_FILE=$PWD/compose.yml
  44. EOF
  45. fi
  46. type -t docker-clean || ln -sfv /opt/apps/0k-docker/src/bin/docker-clean /usr/local/bin
  47. ## To remove when image in odoo-tecnativa is not used anymore
  48. echo "Login into our server."
  49. docker login -u deploy -p deployinvm git.panda-chi.io:5002
  50. cd /opt/apps/myc-deploy
  51. cat <<EOF > /root/.pgm.rc
  52. prefix_pg_local_command=" " ## otherwise, will default to sudo -u postgres
  53. pgpass="/srv/datastore/data/postgres/var/lib/postgresql/data/pgpass"
  54. [ -f "\$pgpass" ] || {
  55. echo "No '\$pgpass' found. Postgres database doesn't seem to be setup." >&2
  56. exit 1
  57. }
  58. cp "\$pgpass" /root/.pgpass
  59. PGUSER=\${PGUSER:-postgres}
  60. if [ -z "\$PGHOST" ]; then
  61. PGHOST=\$(docker-ip | grep postgres | xargs echo | cut -f 3 -d " ") || {
  62. echo "No local running postgres docker found." >&2
  63. exit 1
  64. }
  65. fi
  66. export PGHOST PGUSER
  67. EOF
  68. if ! [ -s /etc/ssh/vm_git_myceliandre_access_id_rsa ]; then
  69. curl https://docker.0k.io/get/vm_git_myceliandre_access_id_rsa > /etc/ssh/vm_git_myceliandre_access_id_rsa || {
  70. echo "Fatal: Could not retrieve http://docker.0k.io/get/vm_git_myceliandre_access_id_rsa ..." >&2
  71. rm -f /etc/ssh/vm_git_myceliandre_access_id_rsa
  72. exit 1
  73. }
  74. ## Not so usefull as it is public !
  75. chmod 0600 /etc/ssh/vm_git_myceliandre_access_id_rsa
  76. fi
  77. mkdir -p /root/.ssh
  78. cat <<EOF >> /root/.ssh/config
  79. Host git.myceliandre.fr
  80. User git
  81. IdentityFile /etc/ssh/vm_git_myceliandre_access_id_rsa
  82. UserKnownHostsFile /dev/null
  83. StrictHostKeyChecking no
  84. Port 5022
  85. EOF
  86. ##
  87. ## We could need some docker-compose for some quick hacks
  88. ##
  89. # seems to require a C compiler
  90. apt-get install -y build-essential </dev/null &&
  91. pip install wheel==0.33.6 &&
  92. pip install pip==19.3.1 cffi==1.12.3 subprocess32==3.5.4 texttable==1.6.2 \
  93. git+https://github.com/0k/compose@run_ignore_orphans || exit 1
  94. ## Bug after updating pip
  95. hash -d pip || exit 1
  96. if [ "$DOMAIN" ]; then
  97. sed -ri "s/^(\s+domain:\s+).*$/\1$DOMAIN/g" compose.yml
  98. fi
  99. if [ "$MAIN_PASSWORD" ]; then
  100. sed -ri "s/^(\s+admin-password:\s+).*$/\1$MAIN_PASSWORD/g" compose.yml
  101. fi
  102. pip install ovh || exit 1
  103. #compose --debug up odoo apache
  104. ## Marker to probe if this script finished it's job
  105. echo "done" > /var/run/myc-installer.0k.io.state