main.sh 2.21 KB
Newer Older
1 2 3 4 5
#!/bin/bash

ci_dir="/home/django/third-party/scripts/src"
ci_data_dir="/home/django/third-party/scripts/data"

6 7

coop=$1
8
instance=$2
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#move to the third argument
shift
shift

send_mails=true

#https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
while [[ "$#" -gt 0 ]]; do
    case $1 in
        -n|--nomail) send_mails=false ;;
        *) echo "arguments : ${coop} ${instance} $1 not supported (Unknown parameter passed: $1)"
          if ${send_mails}; then
            python3 "${ci_dir}/send_error_mail.py" "arguments : ${coop} ${instance} $1 not supported (Unknown parameter passed: $1)"
          fi
          exit 1 ;;
    esac
    shift
done

if ! python3 "${ci_dir}/supported_coops.py" "${coop}" "${instance}"; then
  echo "arguments : ${coop} ${instance} not supported"
  if ${send_mails}; then
    python3 "${ci_dir}/send_error_mail.py" "arguments : ${coop} ${instance} not supported"
  fi
33 34 35 36 37
  exit 1
fi

now=$( date +%Y%m%d_%H%M%S )

38 39 40 41 42 43 44 45 46 47 48 49
source "${ci_dir}/prepare_mail.sh"
source "${ci_dir}/update_instance.sh"

if [[ "${instance}" == "preprod" ]]; then
  repo="third-party"
  echo "Prepare mail" "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" "${ci_dir}" "${ci_data_dir}"
  prepare_mail "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" "${ci_dir}" "${ci_data_dir}"|| exit 1

  repo="Odoo"
  echo "Prepare mail" "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" "${ci_dir}" "${ci_data_dir}"
  prepare_mail "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" "${ci_dir}" "${ci_data_dir}" || exit 1
fi
50 51

repo="third-party"
52 53
echo "Update instance" "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" "${ci_dir}" "${ci_data_dir}"
update_instance "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" "${ci_dir}" "${ci_data_dir}" || exit 1
54 55

repo="Odoo"
56 57
echo "Update instance" "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" "${ci_dir}" "${ci_data_dir}"
update_instance "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" "${ci_dir}" "${ci_data_dir}" || exit 1
58

Yvon committed
59
if [[ "${instance}" == "preprod" ]] && ${send_mails}; then
60
    python3 "${ci_dir}/send_mail.py" "${ci_data_dir}/ci_diff_third-party_${now}.txt" "${ci_data_dir}/ci_diff_Odoo_${now}.txt" "${coop}"
61
fi