update.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. set -o pipefail
  3. export LC_ALL=C
  4. DATE=$(date +%Y-%m-%d_%H_%M_%S)
  5. BRANCH=$(git rev-parse --abbrev-ref HEAD)
  6. if [[ -f mailcow.conf ]]; then
  7. source mailcow.conf
  8. else
  9. echo -e "\e[31mNo mailcow.conf - is mailcow installed?\e[0m"
  10. exit 1
  11. fi
  12. # Stopping mailcow
  13. docker-compose down
  14. for image in "phpfpm" "dovecot" "postfix" "sogo" "unbound" "rspamd" "clamd" "fail2ban"; do
  15. if [[ ! -z $(docker images mailcow/${image} -q) ]]; then
  16. echo -e "\e[32mSaving mailcow/${image} to mailcow/${image}:${DATE}...\e[90m"
  17. docker tag mailcow/${image} mailcow/${image}:${DATE}
  18. fi
  19. done
  20. # Silently fixing remote url from andryyy to mailcow
  21. git remote set-url origin https://github.com/mailcow/mailcow-dockerized
  22. echo -e "\e[32mCommitting current status...\e[90m"
  23. git add -u
  24. git commit -am "Before update on ${DATE}" > /dev/null
  25. echo -e "\e[32mFetching updated code from remote...\e[90m"
  26. git fetch origin ${BRANCH}
  27. echo -e "\e[32mMerging local with remote code...\e[90m"
  28. git merge -Xtheirs -Xpatience -m "After update on ${DATE}"
  29. if [[ $? == 1 ]]; then
  30. echo -e "\e[31mRun into conflict, trying to fix...\e[90m"
  31. git status --porcelain | grep -E "UD|DU" | awk '{print $2}' | xargs rm -v
  32. git add -A
  33. git commit -m "After update on ${DATE}" > /dev/null
  34. git checkout .
  35. echo -e "\e[32mRemoved and recreated files if necessary.\e[90m"
  36. fi
  37. echo -e "\e[32mFetching new images, if any...\e[0m"
  38. docker-compose pull
  39. echo
  40. #echo -e "\e[32mHashes to revert to:\e[0m"
  41. #git reflog --color=always | grep "Before update on "
  42. # TODO: Menu, select hard reset, select reset to "before update" etc.
  43. #git reset --hard origin/${BRANCH}
  44. # Fix missing SSL, does not overwrite existing files
  45. [[ ! -d data/assets/ssl ]] && mkdir -p data/assets/ssl
  46. cp -n data/assets/ssl-example/*.pem data/assets/ssl/