#!/bin/bash

# $1 : project name
# $2 : prod or preprod (only preprod is supported for now)

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

if ! python3 "${ci_dir}/supported_coops.py" "${1}" "${2}"; then
  echo "arguments : ${1} ${2} not supported"
  python3 "${ci_dir}/send_error_mail.py" "arguments : ${1} ${2} not supported"
  exit 1
fi

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

source "${ci_dir}/update_code.sh"

repo="third-party"
echo "START PROCESS" "${1}" "${2}" "${repo}" "${now}"
update_code "${1}" "${2}" "${repo}" "${now}" || exit 1
echo "DONE"

repo="Odoo"
echo "START PROCESS" "${1}" "${2}" "${repo}" "${now}"
update_code "${1}" "${2}" "${repo}" "${now}" || exit 1
echo "DONE"

python3 "${ci_dir}/send_mail.py" "${ci_data_dir}/ci_diff_third-party_${now}.txt" "${ci_data_dir}/ci_diff_Odoo_${now}.txt" "${1}"