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.

143 lines
4.0 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. if [ -z "$WITHOUT_DOCKER_CLEAN" ]; then
  48. ln -sfn /opt/apps/0k-docker/src/bin/docker-clean /etc/cron.daily/docker-clean
  49. fi
  50. ## To remove when image in odoo-tecnativa is not used anymore
  51. echo "Login into our server."
  52. docker login -u deploy -p deployinvm git.panda-chi.io:5002
  53. cd /opt/apps/myc-deploy
  54. cat <<EOF > /root/.pgm.rc
  55. prefix_pg_local_command=" " ## otherwise, will default to sudo -u postgres
  56. pgpass="/srv/datastore/data/postgres/var/lib/postgresql/data/pgpass"
  57. [ -f "\$pgpass" ] || {
  58. echo "No '\$pgpass' found. Postgres database doesn't seem to be setup." >&2
  59. exit 1
  60. }
  61. cp "\$pgpass" /root/.pgpass
  62. PGUSER=\${PGUSER:-postgres}
  63. if [ -z "\$PGHOST" ]; then
  64. PGHOST=\$(docker-ip | grep postgres | xargs echo | cut -f 3 -d " ") || {
  65. echo "No local running postgres docker found." >&2
  66. exit 1
  67. }
  68. fi
  69. export PGHOST PGUSER
  70. EOF
  71. if ! [ -s /etc/ssh/vm_git_myceliandre_access_id_rsa ]; then
  72. curl https://docker.0k.io/get/vm_git_myceliandre_access_id_rsa > /etc/ssh/vm_git_myceliandre_access_id_rsa || {
  73. echo "Fatal: Could not retrieve http://docker.0k.io/get/vm_git_myceliandre_access_id_rsa ..." >&2
  74. rm -f /etc/ssh/vm_git_myceliandre_access_id_rsa
  75. exit 1
  76. }
  77. ## Not so usefull as it is public !
  78. chmod 0600 /etc/ssh/vm_git_myceliandre_access_id_rsa
  79. fi
  80. mkdir -p /root/.ssh
  81. cat <<EOF >> /root/.ssh/config
  82. Host git.myceliandre.fr
  83. User git
  84. IdentityFile /etc/ssh/vm_git_myceliandre_access_id_rsa
  85. UserKnownHostsFile /dev/null
  86. StrictHostKeyChecking no
  87. Port 5022
  88. EOF
  89. ##
  90. ## We could need some docker-compose for some quick hacks
  91. ##
  92. if ! type -p docker-compose >/dev/null; then
  93. # seems to require a C compiler
  94. apt-get install -y build-essential </dev/null &&
  95. pip install wheel==0.33.6 &&
  96. pip install pip==19.3.1 cffi==1.12.3 subprocess32==3.5.4 texttable==1.6.2 \
  97. pyrsistent==0.15.7 \
  98. git+https://github.com/0k/compose@run_ignore_orphans || exit 1
  99. ## Bug after updating pip
  100. hash -d pip || exit 1
  101. fi
  102. if [ "$DOMAIN" ]; then
  103. sed -ri "s/^(\s+domain:\s+).*$/\1$DOMAIN/g" compose.yml
  104. fi
  105. if [ "$MAIN_PASSWORD" ]; then
  106. sed -ri "s/^(\s+admin-password:\s+).*$/\1$MAIN_PASSWORD/g" compose.yml
  107. fi
  108. pip install ovh || exit 1
  109. #compose --debug up odoo apache
  110. ## Marker to probe if this script finished it's job
  111. echo "done" > /var/run/myc-installer.0k.io.state