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.

132 lines
3.6 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="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. cd /opt/apps/myc-deploy
  48. cat <<EOF > /root/.pgm.rc
  49. prefix_pg_local_command=" " ## otherwise, will default to sudo -u postgres
  50. pgpass="/srv/datastore/data/postgres/var/lib/postgresql/data/pgpass"
  51. [ -f "\$pgpass" ] || {
  52. echo "No '\$pgpass' found. Postgres database doesn't seem to be setup." >&2
  53. exit 1
  54. }
  55. cp "\$pgpass" /root/.pgpass
  56. PGUSER=\${PGUSER:-postgres}
  57. if [ -z "\$PGHOST" ]; then
  58. PGHOST=\$(docker-ip | grep postgres | xargs echo | cut -f 3 -d " ") || {
  59. echo "No local running postgres docker found." >&2
  60. exit 1
  61. }
  62. fi
  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. # seems to require a C compiler
  87. apt-get install -y build-essential </dev/null &&
  88. pip install wheel==0.33.6 &&
  89. pip install pip==19.3.1 cffi==1.12.3 subprocess32==3.5.4 texttable==1.6.2 \
  90. git+https://github.com/0k/compose@run_ignore_orphans || exit 1
  91. ## Bug after updating pip
  92. hash -d pip || exit 1
  93. if [ "$DOMAIN" ]; then
  94. sed -ri "s/^(\s+domain:\s+).*$/\1$DOMAIN/g" compose.yml
  95. fi
  96. if [ "$MAIN_PASSWORD" ]; then
  97. sed -ri "s/^(\s+admin-password:\s+).*$/\1$MAIN_PASSWORD/g" compose.yml
  98. fi
  99. pip install ovh || exit 1
  100. #compose --debug up odoo apache
  101. ## Marker to probe if this script finished it's job
  102. echo "done" > /var/run/myc-installer.0k.io.state