#!/bin/bash
#############################################################################
#                                                                           #
# This file is part of the "ubuntu" module of the otoolbox project.         #
#                                                                           #
# This script is open-source and intended for automation purposes.          #
# It is distributed in the hope that it will be useful, but WITHOUT         #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY        #
# or FITNESS FOR A PARTICULAR PURPOSE.                                      #
#                                                                           #
# Use of this script is entirely at your own risk.                          #
#                                                                           #
# Copyright (c) The otoolbox contributors.                                  #
#############################################################################
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
COMMON_SCRIPT="$SCRIPT_DIR/bulk-common"
if [[ ! -f "$COMMON_SCRIPT" ]]; then
    echo "Error: required script not found: $COMMON_SCRIPT" >&2
    exit 1
fi
# shellcheck source=/dev/null
source "$SCRIPT_DIR/../../.env"
source "$COMMON_SCRIPT"
bulk_init "$@"


########################################################################################
# Pull latest changes from the repositories
# TODO: maso, 2026: add ability in otoolbox to get list of repositories to pull
# from config file or command line arguments.
########################################################################################
echo
echo "[1] Pulling latest changes from odoonix and moonsunsoft repositories..."
otoolbox run update --tags odoonix >> "$LOG_FILE" 2>&1

echo "[2] Pulling latest changes from moonsunsoft repository..."
sudo -u worker otoolbox run update --tags moonsunsoft >> "$LOG_FILE" 2>&1

echo "[3] Pulling latest changes from oca and moonsunsoft repositories..."
otoolbox run update --tags oca >> "$LOG_FILE" 2>&1

echo "[4] Pulling latest changes from odoon and moonsunsoft repositories..."
otoolbox run update --tags odoo >> "$LOG_FILE" 2>&1
