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.

127 lines
3.4 KiB

  1. #!/bin/bash
  2. ## Installing base docker-host
  3. wget http://docker.0k.io/get/ -qO - | bash
  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="git.0k.io:/var/git/0k" \
  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 pandachi-manage || exit 1
  35. install_bin /opt/apps/pandachi-manage/bin
  36. clone_or_update pandachi-deploy || exit 1
  37. #[ -e /etc/compose.conf ] || ln -sfv /opt/apps/pandachi-deploy/etc/compose.conf /etc/compose.conf
  38. ## XXXvlab: should get rid of this file in some future
  39. cd /opt/apps/pandachi-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. echo "Login into our server."
  48. docker login -u deploy -p deployinvm git.panda-chi.io:5002
  49. cd /opt/apps/pandachi-deploy
  50. cat <<EOF > /root/.pgm.rc
  51. prefix_pg_local_command=" " ## otherwise, will default to sudo -u postgres
  52. pgpass="/srv/datastore/data/postgres/var/lib/postgresql/data/pgpass"
  53. [ -f "\$pgpass" ] || {
  54. echo "No '\$pgpass' found. Postgres database doesn't seem to be setup." >&2
  55. exit 1
  56. }
  57. cp "\$pgpass" /root/.pgpass
  58. PGUSER=postgres
  59. PGHOST=\$(docker-ip | grep postgres | xargs echo | cut -f 3 -d " ") || {
  60. echo "No local running postgres docker found." >&2
  61. exit 1
  62. }
  63. export PGHOST PGUSER
  64. EOF
  65. if ! [ -s /etc/ssh/vm_git_myceliandre_access_id_rsa ]; then
  66. curl https://docker.0k.io/get/vm_git_myceliandre_access_id_rsa > /etc/ssh/vm_git_myceliandre_access_id_rsa || {
  67. echo "Fatal: Could not retrieve http://docker.0k.io/get/vm_git_myceliandre_access_id_rsa ..." >&2
  68. rm -f /etc/ssh/vm_git_myceliandre_access_id_rsa
  69. exit 1
  70. }
  71. ## Not so usefull as it is public !
  72. chmod 0600 /etc/ssh/vm_git_myceliandre_access_id_rsa
  73. fi
  74. mkdir -p /root/.ssh
  75. cat <<EOF >> /root/.ssh/config
  76. Host git.myceliandre.fr
  77. User git
  78. IdentityFile /etc/ssh/vm_git_myceliandre_access_id_rsa
  79. UserKnownHostsFile /dev/null
  80. StrictHostKeyChecking no
  81. Port 5022
  82. EOF
  83. ##
  84. ## We could need some docker-compose for some quick hacks
  85. ##
  86. pip install cffi==1.12.3 docker-compose
  87. if [ "$DOMAIN" ]; then
  88. sed -ri "s/^(\s+domain:\s+).*$/\1$DOMAIN/g" compose.yml
  89. fi
  90. if [ "$MAIN_PASSWORD" ]; then
  91. sed -ri "s/^(\s+admin-password:\s+).*$/\1$MAIN_PASSWORD/g" compose.yml
  92. fi
  93. pip install ovh
  94. #compose --debug up odoo apache
  95. ## Marker to probe if this script finished it's job
  96. echo "done" > /var/run/pandachi-installer.0k.io.state