diff --git a/.cursor/hooks/remonter-mails.sh b/.cursor/hooks/remonter-mails.sh index 7cdabbf..28fbb49 100755 --- a/.cursor/hooks/remonter-mails.sh +++ b/.cursor/hooks/remonter-mails.sh @@ -8,6 +8,12 @@ cat > /dev/null SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" IA_DEV="$(cd "${SCRIPT_DIR}/../.." && pwd)" +if [[ -f "${IA_DEV}/lib/smart_ide_logs.sh" ]]; then + # shellcheck source=../../lib/smart_ide_logs.sh + source "${IA_DEV}/lib/smart_ide_logs.sh" + smart_ide_logs_begin "$IA_DEV" "$0" "$*" + smart_ide_logs_register_exit_trap +fi CONTENT="" for spool in "${IA_DEV}/projects/"*/data/issues; do diff --git a/ai_working_help/notary-ai/lib.sh b/ai_working_help/notary-ai/lib.sh index 7760ddc..a581838 100644 --- a/ai_working_help/notary-ai/lib.sh +++ b/ai_working_help/notary-ai/lib.sh @@ -30,3 +30,10 @@ export DATA_NOTARY_AI_RESPONDED_DIR export PROJECT_ID export IA_DEV_ROOT export PROJECT_ROOT + +if [[ -f "${IA_DEV_ROOT}/lib/smart_ide_logs.sh" ]]; then + # shellcheck source=../../lib/smart_ide_logs.sh + source "${IA_DEV_ROOT}/lib/smart_ide_logs.sh" + smart_ide_logs_begin "$IA_DEV_ROOT" "${BASH_SOURCE[1]}" "$*" + smart_ide_logs_register_exit_trap +fi diff --git a/deploy/branch-align.sh b/deploy/branch-align.sh index b45f8d0..b0e9d14 100755 --- a/deploy/branch-align.sh +++ b/deploy/branch-align.sh @@ -7,6 +7,10 @@ SCRIPT_REAL="$(readlink -f "${BASH_SOURCE[0]:-$0}" 2>/dev/null || realpath "${BA DEPLOY_DIR="$(cd "$(dirname "$SCRIPT_REAL")" && pwd)" IA_DEV_ROOT="$(cd "$DEPLOY_DIR/.." && pwd)" +# shellcheck source=../lib/smart_ide_logs.sh +source "${IA_DEV_ROOT}/lib/smart_ide_logs.sh" +smart_ide_logs_begin "$IA_DEV_ROOT" "$0" "$*" + # Optional first arg: project id (must exist as projects//conf.json); then re-exec from project root if [[ -n "${1:-}" && -f "${IA_DEV_ROOT}/projects/${1}/conf.json" && ! "$1" =~ ^(main|test|pprod|prod)$ ]]; then export IA_PROJECT_ID="$1" @@ -90,6 +94,8 @@ tmp1="$(mktemp -t branch-align-test.XXXXXX)" tmp2="$(mktemp -t branch-align-pprod.XXXXXX)" tmp3="$(mktemp -t branch-align-prod.XXXXXX)" cleanup() { + local ec=$? + smart_ide_log_end_with_status "$ec" rm -f "$tmp1" "$tmp2" "$tmp3" } trap cleanup EXIT diff --git a/deploy/bump-version.sh b/deploy/bump-version.sh index 7b4e577..3e98f71 100644 --- a/deploy/bump-version.sh +++ b/deploy/bump-version.sh @@ -8,6 +8,11 @@ SCRIPT_REAL="$(readlink -f "${BASH_SOURCE[0]:-$0}" 2>/dev/null || realpath "${BA DEPLOY_DIR="$(cd "$(dirname "$SCRIPT_REAL")" && pwd)" IA_DEV_ROOT="$(cd "$DEPLOY_DIR/.." && pwd)" +# shellcheck source=../lib/smart_ide_logs.sh +source "${IA_DEV_ROOT}/lib/smart_ide_logs.sh" +smart_ide_logs_begin "$IA_DEV_ROOT" "$0" "$*" +smart_ide_logs_register_exit_trap + # Optional first arg: project id (must exist as projects//conf.json) if [[ -n "${1:-}" && -f "${IA_DEV_ROOT}/projects/${1}/conf.json" && "$1" != *.* ]]; then export IA_PROJECT_ID="$1" diff --git a/deploy/change-to-all-branches.sh b/deploy/change-to-all-branches.sh index b999fa7..e1678f5 100755 --- a/deploy/change-to-all-branches.sh +++ b/deploy/change-to-all-branches.sh @@ -7,6 +7,11 @@ SCRIPT_REAL="$(readlink -f "${BASH_SOURCE[0]:-$0}" 2>/dev/null || realpath "${BA DEPLOY_DIR="$(cd "$(dirname "$SCRIPT_REAL")" && pwd)" IA_DEV_ROOT="$(cd "$DEPLOY_DIR/.." && pwd)" +# shellcheck source=../lib/smart_ide_logs.sh +source "${IA_DEV_ROOT}/lib/smart_ide_logs.sh" +smart_ide_logs_begin "$IA_DEV_ROOT" "$0" "$*" +smart_ide_logs_register_exit_trap + # Optional first arg: project id (must exist as projects//conf.json); then re-exec from project root if [[ -n "${1:-}" && -f "${IA_DEV_ROOT}/projects/${1}/conf.json" ]]; then export IA_PROJECT_ID="$1" diff --git a/deploy/deploy-by-script-to.sh b/deploy/deploy-by-script-to.sh index 8603140..58a7c41 100755 --- a/deploy/deploy-by-script-to.sh +++ b/deploy/deploy-by-script-to.sh @@ -8,6 +8,11 @@ SCRIPT_REAL="$(readlink -f "${BASH_SOURCE[0]:-$0}" 2>/dev/null || realpath "${BA DEPLOY_IA="$(cd "$(dirname "$SCRIPT_REAL")" && pwd)" IA_DEV_ROOT="$(cd "$DEPLOY_IA/.." && pwd)" +# shellcheck source=../lib/smart_ide_logs.sh +source "${IA_DEV_ROOT}/lib/smart_ide_logs.sh" +smart_ide_logs_begin "$IA_DEV_ROOT" "$0" "$*" +smart_ide_logs_register_exit_trap + # Optional first arg: project id (must exist as projects//conf.json) if [[ -n "${1:-}" && ! "$1" =~ ^(pprod|prod)$ && -f "${IA_DEV_ROOT}/projects/${1}/conf.json" ]]; then export IA_PROJECT_ID="$1" diff --git a/deploy/deploy.sh b/deploy/deploy.sh index b263175..dccda21 100755 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -8,6 +8,10 @@ SCRIPT_REAL="$(readlink -f "${BASH_SOURCE[0]:-$0}" 2>/dev/null || realpath "${BA DEPLOY_DIR="$(cd "$(dirname "$SCRIPT_REAL")" && pwd)" IA_DEV_ROOT="$(cd "$DEPLOY_DIR/.." && pwd)" +# shellcheck source=../lib/smart_ide_logs.sh +source "${IA_DEV_ROOT}/lib/smart_ide_logs.sh" +smart_ide_logs_begin "$IA_DEV_ROOT" "$0" "$*" + # shellcheck source=lib/deploy-methodology.sh source "${DEPLOY_DIR}/lib/deploy-methodology.sh" diff --git a/deploy/lib/README.md b/deploy/lib/README.md index 5b6b140..eaab65d 100644 --- a/deploy/lib/README.md +++ b/deploy/lib/README.md @@ -3,7 +3,7 @@ ## `ssh.sh` Canonical SSH/SCP helpers (`ssh_run`, `scp_copy`, `require_ssh_key`, `ssh_common_opts`) used across projects. -**LeCoffre** : `deploy/scripts_v2/_lib/ssh.sh` sources `ia_dev/deploy/lib/ssh.sh` when the submodule path `ia_dev/deploy/lib/ssh.sh` exists from the repo root; otherwise it embeds the same implementation. +**LeCoffre** : `deploy/scripts_v2/_lib/ssh.sh` sources `ia_dev/deploy/lib/ssh.sh` when the path `ia_dev/deploy/lib/ssh.sh` exists from the repo root; otherwise it embeds the same implementation. ## `deploy-log.sh` diff --git a/deploy/lib/deploy-log.sh b/deploy/lib/deploy-log.sh index 0b5401d..999104f 100644 --- a/deploy/lib/deploy-log.sh +++ b/deploy/lib/deploy-log.sh @@ -21,6 +21,12 @@ deploy_script_tee_log_if_requested() { printf '%s\n' "=== LeCoffre deploy log ===" printf '%s\n' "environment=${deploy_env:-} started_at=${DEPLOY_STARTED_AT:-} project_root=${project_root}" } >"$log_file" + _IA_DEV_DEPLOY_LOG="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" + if [[ -f "${_IA_DEV_DEPLOY_LOG}/lib/smart_ide_logs.sh" ]]; then + # shellcheck source=../../lib/smart_ide_logs.sh + SMART_IDE_LOG_IA_DEV_ROOT="$_IA_DEV_DEPLOY_LOG" source "${_IA_DEV_DEPLOY_LOG}/lib/smart_ide_logs.sh" + smart_ide_log_event "deploy_script_tee_log project_root=${project_root} log_file=${log_file}" + fi exec > >(tee -a "$log_file") info "[deploy] Teeing output to ${log_file}" } diff --git a/deploy/lib/ssh.sh b/deploy/lib/ssh.sh index f13b3fa..6368933 100644 --- a/deploy/lib/ssh.sh +++ b/deploy/lib/ssh.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # Shared SSH/SCP helpers for deploy scripts (ProxyJump, BatchMode, keepalive). -# Sourced by project deploy/_lib/ssh.sh when ia_dev is present as submodule/sibling. +# Sourced by project deploy/_lib/ssh.sh when ia_dev is present under the repo root (or sibling layout). set -euo pipefail diff --git a/deploy/orchestrator.sh b/deploy/orchestrator.sh index a3eb413..d529cda 100755 --- a/deploy/orchestrator.sh +++ b/deploy/orchestrator.sh @@ -10,6 +10,11 @@ SCRIPT_REAL="$(readlink -f "${BASH_SOURCE[0]:-$0}" 2>/dev/null || realpath "${BA DEPLOY_DIR="$(cd "$(dirname "$SCRIPT_REAL")" && pwd)" IA_DEV_ROOT="$(cd "$DEPLOY_DIR/.." && pwd)" +# shellcheck source=../lib/smart_ide_logs.sh +source "${IA_DEV_ROOT}/lib/smart_ide_logs.sh" +smart_ide_logs_begin "$IA_DEV_ROOT" "$0" "$*" +smart_ide_logs_register_exit_trap + _ORCH_TAG="[orchestrator]" # shellcheck source=lib/deploy-methodology.sh @@ -60,6 +65,7 @@ if [[ -n "$PROJECT_ORCH_REL" && "$PROJECT_ORCH_REL" != "null" ]]; then echo "${_ORCH_TAG}[WARN] deploy.hooks.phases is non-empty but project_orchestrator_path takes precedence; phases are ignored." >&2 fi echo "${_ORCH_TAG} Project orchestrator: ${PROJECT_ORCH_REL} $*" + smart_ide_log_event "HANDOFF project_orchestrator ${PROJECT_ORCH_ABS} $*" exec bash "$PROJECT_ORCH_ABS" "$@" fi @@ -71,12 +77,14 @@ fi PHASE_COUNT="$(jq '.deploy.hooks.phases // [] | length' "$CONF")" if [[ "$PHASE_COUNT" == "0" ]]; then echo "${_ORCH_TAG}[WARN] deploy.project_orchestrator_path unset; falling back to deploy_script_path only." >&2 + smart_ide_log_event "HANDOFF deploy_script_path ${DEPLOY_SCRIPT_PATH} $*" exec bash "$DEPLOY_SCRIPT_PATH" "$@" fi mapfile -t PHASE_SCRIPTS < <(jq -r '.deploy.hooks.phases[]? | if type == "string" then . elif type == "object" and (.run | type == "string") then .run else empty end' "$CONF") if [[ ${#PHASE_SCRIPTS[@]} -eq 0 ]]; then + smart_ide_log_event "HANDOFF deploy_script_path ${DEPLOY_SCRIPT_PATH} $*" exec bash "$DEPLOY_SCRIPT_PATH" "$@" fi diff --git a/deploy/pousse.sh b/deploy/pousse.sh index 932f2bb..9561155 100755 --- a/deploy/pousse.sh +++ b/deploy/pousse.sh @@ -11,6 +11,10 @@ SCRIPT_REAL="$(readlink -f "${BASH_SOURCE[0]:-$0}" 2>/dev/null || realpath "${BA DEPLOY_DIR="$(cd "$(dirname "$SCRIPT_REAL")" && pwd)" IA_DEV_ROOT="$(cd "$DEPLOY_DIR/.." && pwd)" +# shellcheck source=../lib/smart_ide_logs.sh +source "${IA_DEV_ROOT}/lib/smart_ide_logs.sh" +smart_ide_logs_begin "$IA_DEV_ROOT" "$0" "$*" + # Optional project id: --project or first positional if projects//conf.json exists while [[ $# -gt 0 ]]; do if [[ "$1" == --project ]]; then @@ -151,6 +155,8 @@ fi msg_file="$(mktemp -t pousse-commit-msg.XXXXXX)" cleanup() { + local ec=$? + smart_ide_log_end_with_status "$ec" rm -f "$msg_file" } trap cleanup EXIT diff --git a/deploy/run-project-hooks.sh b/deploy/run-project-hooks.sh index 65c199b..634daf0 100755 --- a/deploy/run-project-hooks.sh +++ b/deploy/run-project-hooks.sh @@ -6,4 +6,8 @@ set -euo pipefail SCRIPT_REAL="$(readlink -f "${BASH_SOURCE[0]:-$0}" 2>/dev/null || realpath "${BASH_SOURCE[0]:-$0}" 2>/dev/null || echo "${BASH_SOURCE[0]:-$0}")" DEPLOY_DIR="$(cd "$(dirname "$SCRIPT_REAL")" && pwd)" +IA_DEV_ROOT="$(cd "$DEPLOY_DIR/.." && pwd)" +# shellcheck source=../lib/smart_ide_logs.sh +source "${IA_DEV_ROOT}/lib/smart_ide_logs.sh" +smart_ide_logs_begin "$IA_DEV_ROOT" "$0" "$*" exec "$DEPLOY_DIR/orchestrator.sh" "$@" diff --git a/deploy/scripts/add-ssh-key-anthony.sh b/deploy/scripts/add-ssh-key-anthony.sh index a7dc054..51086da 100755 --- a/deploy/scripts/add-ssh-key-anthony.sh +++ b/deploy/scripts/add-ssh-key-anthony.sh @@ -6,6 +6,13 @@ set -euo pipefail SCRIPT_DIR="${BASH_SOURCE%/*}" [[ -d "$SCRIPT_DIR" ]] || SCRIPT_DIR=. +IA_DEV_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" +if [[ -f "${IA_DEV_ROOT}/lib/smart_ide_logs.sh" ]]; then + # shellcheck source=../../lib/smart_ide_logs.sh + source "${IA_DEV_ROOT}/lib/smart_ide_logs.sh" + smart_ide_logs_begin "$IA_DEV_ROOT" "$0" "$*" + smart_ide_logs_register_exit_trap +fi LIB_DIR="$(cd "$SCRIPT_DIR/../_lib" && pwd)" # shellcheck source=../_lib/ssh.sh source "$LIB_DIR/ssh.sh" diff --git a/deploy/scripts/install-lpldf-https-watch-on-proxy.sh b/deploy/scripts/install-lpldf-https-watch-on-proxy.sh index a8333ea..3e46329 100755 --- a/deploy/scripts/install-lpldf-https-watch-on-proxy.sh +++ b/deploy/scripts/install-lpldf-https-watch-on-proxy.sh @@ -4,6 +4,12 @@ set -euo pipefail IA_DEV_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +if [[ -f "${IA_DEV_ROOT}/lib/smart_ide_logs.sh" ]]; then + # shellcheck source=../../lib/smart_ide_logs.sh + source "${IA_DEV_ROOT}/lib/smart_ide_logs.sh" + smart_ide_logs_begin "$IA_DEV_ROOT" "$0" "$*" + smart_ide_logs_register_exit_trap +fi # shellcheck source=deploy/_lib/ssh.sh source "${IA_DEV_ROOT}/deploy/_lib/ssh.sh" diff --git a/gitea-issues/lib.sh b/gitea-issues/lib.sh index 4231553..884283b 100755 --- a/gitea-issues/lib.sh +++ b/gitea-issues/lib.sh @@ -33,6 +33,14 @@ fi export PROJECT_LOGS_DIR export DATA_ISSUES_DIR +if [[ -f "${GITEA_ISSUES_DIR}/../lib/smart_ide_logs.sh" ]]; then + # shellcheck source=../lib/smart_ide_logs.sh + source "${GITEA_ISSUES_DIR}/../lib/smart_ide_logs.sh" + _IA_DEV_ROOT_FOR_LOG="$(cd "${GITEA_ISSUES_DIR}/.." && pwd)" + smart_ide_logs_begin "$_IA_DEV_ROOT_FOR_LOG" "${BASH_SOURCE[1]}" "$*" + smart_ide_logs_register_exit_trap +fi + # Load token: GITEA_TOKEN env, then project config git.token_file (path relative to ia_dev root), then default load_gitea_token() { if [[ -n "${GITEA_TOKEN:-}" ]]; then diff --git a/gitea-issues/mail-create-issue-from-email.sh b/gitea-issues/mail-create-issue-from-email.sh index 630a521..5332f76 100755 --- a/gitea-issues/mail-create-issue-from-email.sh +++ b/gitea-issues/mail-create-issue-from-email.sh @@ -5,4 +5,10 @@ set -euo pipefail GITEA_ISSUES_DIR="${GITEA_ISSUES_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}" export GITEA_ISSUES_DIR export REPO_ROOT="${GITEA_ISSUES_DIR}/.." +_IA_FOR_LOG="$(cd "${GITEA_ISSUES_DIR}/.." && pwd)" +if [[ -f "${_IA_FOR_LOG}/lib/smart_ide_logs.sh" ]]; then + # shellcheck source=../lib/smart_ide_logs.sh + source "${_IA_FOR_LOG}/lib/smart_ide_logs.sh" + smart_ide_logs_begin "$_IA_FOR_LOG" "$0" "$*" +fi exec python3 "${GITEA_ISSUES_DIR}/mail-create-issue-from-email.py" "$@" diff --git a/gitea-issues/mail-get-thread.sh b/gitea-issues/mail-get-thread.sh index 01a77eb..f4b6fe1 100755 --- a/gitea-issues/mail-get-thread.sh +++ b/gitea-issues/mail-get-thread.sh @@ -9,4 +9,10 @@ if [ $# -lt 1 ]; then echo "Usage: $0 " >&2 exit 1 fi +_IA_FOR_LOG="$(cd "${GITEA_ISSUES_DIR}/.." && pwd)" +if [[ -f "${_IA_FOR_LOG}/lib/smart_ide_logs.sh" ]]; then + # shellcheck source=../lib/smart_ide_logs.sh + source "${_IA_FOR_LOG}/lib/smart_ide_logs.sh" + smart_ide_logs_begin "$_IA_FOR_LOG" "$0" "$*" +fi exec python3 "${GITEA_ISSUES_DIR}/mail-get-thread.py" "$1" diff --git a/gitea-issues/mail-list-unread.sh b/gitea-issues/mail-list-unread.sh index 56136db..9cf53db 100755 --- a/gitea-issues/mail-list-unread.sh +++ b/gitea-issues/mail-list-unread.sh @@ -5,4 +5,10 @@ GITEA_ISSUES_DIR="${GITEA_ISSUES_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && p # REPO_ROOT = ia_dev so mail_common.repo_root() finds .secrets under ia_dev export GITEA_ISSUES_DIR export REPO_ROOT="${GITEA_ISSUES_DIR}/.." +_IA_FOR_LOG="$(cd "${GITEA_ISSUES_DIR}/.." && pwd)" +if [[ -f "${_IA_FOR_LOG}/lib/smart_ide_logs.sh" ]]; then + # shellcheck source=../lib/smart_ide_logs.sh + source "${_IA_FOR_LOG}/lib/smart_ide_logs.sh" + smart_ide_logs_begin "$_IA_FOR_LOG" "$0" "$*" +fi exec python3 "${GITEA_ISSUES_DIR}/mail-list-unread.py" diff --git a/gitea-issues/mail-mark-read.sh b/gitea-issues/mail-mark-read.sh index b04369b..213b4f3 100755 --- a/gitea-issues/mail-mark-read.sh +++ b/gitea-issues/mail-mark-read.sh @@ -5,4 +5,10 @@ set -euo pipefail GITEA_ISSUES_DIR="${GITEA_ISSUES_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}" export GITEA_ISSUES_DIR export REPO_ROOT="${GITEA_ISSUES_DIR}/.." +_IA_FOR_LOG="$(cd "${GITEA_ISSUES_DIR}/.." && pwd)" +if [[ -f "${_IA_FOR_LOG}/lib/smart_ide_logs.sh" ]]; then + # shellcheck source=../lib/smart_ide_logs.sh + source "${_IA_FOR_LOG}/lib/smart_ide_logs.sh" + smart_ide_logs_begin "$_IA_FOR_LOG" "$0" "$*" +fi exec python3 "${GITEA_ISSUES_DIR}/mail-mark-read.py" "$@" diff --git a/gitea-issues/mail-send-reply.sh b/gitea-issues/mail-send-reply.sh index 35ae397..cd87e69 100755 --- a/gitea-issues/mail-send-reply.sh +++ b/gitea-issues/mail-send-reply.sh @@ -5,4 +5,10 @@ set -euo pipefail GITEA_ISSUES_DIR="${GITEA_ISSUES_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}" export GITEA_ISSUES_DIR export REPO_ROOT="${GITEA_ISSUES_DIR}/.." +_IA_FOR_LOG="$(cd "${GITEA_ISSUES_DIR}/.." && pwd)" +if [[ -f "${_IA_FOR_LOG}/lib/smart_ide_logs.sh" ]]; then + # shellcheck source=../lib/smart_ide_logs.sh + source "${_IA_FOR_LOG}/lib/smart_ide_logs.sh" + smart_ide_logs_begin "$_IA_FOR_LOG" "$0" "$*" +fi exec python3 "${GITEA_ISSUES_DIR}/mail-send-reply.py" "$@" diff --git a/gitea-issues/mail-thread-log.sh b/gitea-issues/mail-thread-log.sh index 49bceef..3f08bd4 100755 --- a/gitea-issues/mail-thread-log.sh +++ b/gitea-issues/mail-thread-log.sh @@ -10,4 +10,10 @@ set -euo pipefail GITEA_ISSUES_DIR="${GITEA_ISSUES_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}" export GITEA_ISSUES_DIR export REPO_ROOT="${GITEA_ISSUES_DIR}/.." +_IA_FOR_LOG="$(cd "${GITEA_ISSUES_DIR}/.." && pwd)" +if [[ -f "${_IA_FOR_LOG}/lib/smart_ide_logs.sh" ]]; then + # shellcheck source=../lib/smart_ide_logs.sh + source "${_IA_FOR_LOG}/lib/smart_ide_logs.sh" + smart_ide_logs_begin "$_IA_FOR_LOG" "$0" "$*" +fi exec python3 "${GITEA_ISSUES_DIR}/mail-thread-log.py" "$@" diff --git a/gitea-issues/mail-to-issue.sh b/gitea-issues/mail-to-issue.sh index cd54049..326cfd8 100755 --- a/gitea-issues/mail-to-issue.sh +++ b/gitea-issues/mail-to-issue.sh @@ -9,4 +9,10 @@ set -euo pipefail GITEA_ISSUES_DIR="${GITEA_ISSUES_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}" export GITEA_ISSUES_DIR export REPO_ROOT="${GITEA_ISSUES_DIR}/.." +_IA_FOR_LOG="$(cd "${GITEA_ISSUES_DIR}/.." && pwd)" +if [[ -f "${_IA_FOR_LOG}/lib/smart_ide_logs.sh" ]]; then + # shellcheck source=../lib/smart_ide_logs.sh + source "${_IA_FOR_LOG}/lib/smart_ide_logs.sh" + smart_ide_logs_begin "$_IA_FOR_LOG" "$0" "$*" +fi exec python3 "${GITEA_ISSUES_DIR}/mail-to-issue.py" diff --git a/gitea-issues/write-response-spooler.sh b/gitea-issues/write-response-spooler.sh index 133160b..f9cee75 100755 --- a/gitea-issues/write-response-spooler.sh +++ b/gitea-issues/write-response-spooler.sh @@ -5,4 +5,10 @@ set -euo pipefail GITEA_ISSUES_DIR="${GITEA_ISSUES_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}" export GITEA_ISSUES_DIR export REPO_ROOT="${GITEA_ISSUES_DIR}/.." +_IA_FOR_LOG="$(cd "${GITEA_ISSUES_DIR}/.." && pwd)" +if [[ -f "${_IA_FOR_LOG}/lib/smart_ide_logs.sh" ]]; then + # shellcheck source=../lib/smart_ide_logs.sh + source "${_IA_FOR_LOG}/lib/smart_ide_logs.sh" + smart_ide_logs_begin "$_IA_FOR_LOG" "$0" "$*" +fi exec python3 "${GITEA_ISSUES_DIR}/write-response-spooler.py" "$@" diff --git a/lib/smart_ide_logs.sh b/lib/smart_ide_logs.sh new file mode 100644 index 0000000..44ae64f --- /dev/null +++ b/lib/smart_ide_logs.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# Append one line per event to /logs/ia_dev.log when ia_dev lives inside smart_ide. +# Usage: export SMART_IDE_LOG_IA_DEV_ROOT after cd to ia_dev root, then smart_ide_log_event / smart_ide_logs_begin. + +smart_ide_logs_resolve_root_for_ia_dev() { + local ia_root="${1:?}" + local parent base_name + base_name="$(basename "$ia_root")" + if [[ "$base_name" != "ia_dev" ]]; then + return 1 + fi + parent="$(cd "$ia_root/.." && pwd)" + if [[ -f "${parent}/cron/git-pull-wrapper.sh" ]] || [[ -d "${parent}/projects/smart_ide" ]]; then + printf '%s\n' "$parent" + return 0 + fi + return 1 +} + +smart_ide_log_event() { + local ia_root="${SMART_IDE_LOG_IA_DEV_ROOT:-}" + if [[ -z "$ia_root" ]]; then + return 0 + fi + local smart_root logf + smart_root="$(smart_ide_logs_resolve_root_for_ia_dev "$ia_root" 2>/dev/null)" || return 0 + logf="${smart_root}/logs/ia_dev.log" + mkdir -p "$(dirname "$logf")" + printf '%s %s\n' "$(date -Iseconds)" "$*" >>"$logf" +} + +smart_ide_logs_begin() { + export SMART_IDE_LOG_IA_DEV_ROOT="${1:?}" + export SMART_IDE_LOG_SCRIPT_PATH="${2:?}" + shift 2 + smart_ide_log_event "START ${SMART_IDE_LOG_SCRIPT_PATH} $*" +} + +smart_ide_logs_register_exit_trap() { + trap 'smart_ide_logs_on_exit_trap' EXIT +} + +smart_ide_logs_on_exit_trap() { + local ec=$? + smart_ide_log_event "END ${SMART_IDE_LOG_SCRIPT_PATH:-?} exit=${ec}" +} + +smart_ide_log_end_with_status() { + local ec="${1:?}" + smart_ide_log_event "END ${SMART_IDE_LOG_SCRIPT_PATH:-${0:-?}} exit=${ec}" +} diff --git a/tools/proxy-https-watch-lpldf.sh b/tools/proxy-https-watch-lpldf.sh index 8508fa6..02feebd 100755 --- a/tools/proxy-https-watch-lpldf.sh +++ b/tools/proxy-https-watch-lpldf.sh @@ -5,6 +5,14 @@ # Syslog identifier: lpldf-https-watch (for SIEM / Wazuh-style log collection). set -euo pipefail +_IA_DEV_TOOLS="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +if [[ -f "${_IA_DEV_TOOLS}/lib/smart_ide_logs.sh" ]]; then + # shellcheck source=../lib/smart_ide_logs.sh + source "${_IA_DEV_TOOLS}/lib/smart_ide_logs.sh" + smart_ide_logs_begin "$_IA_DEV_TOOLS" "$0" "$*" + smart_ide_logs_register_exit_trap +fi + readonly WATCH_URL="${WATCH_URL:-https://xn--lespetitesleonsdefrdric-89b1db.fr/}" readonly STATE_DIR="${STATE_DIR:-/var/lib/lpldf-https-watch}" readonly STATE_FILE="${STATE_DIR}/last_state"