feat(deploy): add shadowing guard and evidence-based legacy env migration
This commit is contained in:
+51
-9
@@ -196,9 +196,9 @@ if [ "$FORCE_REFRESH" -eq 1 ] || ! check_assets_present "."; then
|
|||||||
echo "update.sh" >> "$MANIFEST_FILE"
|
echo "update.sh" >> "$MANIFEST_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$STAGE_DIR/.env.example" ] && [ ! -e ".env.example" ]; then
|
if [ -f "$STAGE_DIR/.mam.env.example" ] && [ ! -e ".mam.env.example" ]; then
|
||||||
cp "$STAGE_DIR/.env.example" . || { echo "❌ Error: Failed to copy .env.example" >&2; exit 1; }
|
cp "$STAGE_DIR/.mam.env.example" . || { echo "❌ Error: Failed to copy .mam.env.example" >&2; exit 1; }
|
||||||
echo ".env.example" >> "$MANIFEST_FILE"
|
echo ".mam.env.example" >> "$MANIFEST_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ship the user manual into the target's .agents/ (consistent with install_mam.sh)
|
# Ship the user manual into the target's .agents/ (consistent with install_mam.sh)
|
||||||
@@ -275,9 +275,47 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# --- 5. Generate Environment Template ---
|
# --- 5. Generate Environment Template ---
|
||||||
ENV_FILE=".env"
|
ENV_FILE=".mam.env"
|
||||||
ENV_EXAMPLE=".env.example"
|
ENV_EXAMPLE=".mam.env.example"
|
||||||
if [ ! -f "$ENV_FILE" ]; then
|
|
||||||
|
# M-2: Evidence-based legacy env migration helper
|
||||||
|
migrate_legacy_env() {
|
||||||
|
local manifest=".mam/install_manifest.txt"
|
||||||
|
[ -f ".mam.env" ] && return 0
|
||||||
|
[ -f ".env" ] || return 0
|
||||||
|
if [ "${MAM_LEGACY_ENV_OWNED:-0}" = "1" ] || { [ -f "$manifest" ] && grep -Fqx ".env" "$manifest" 2>/dev/null; }; then
|
||||||
|
mv -f ".env" ".mam.env"
|
||||||
|
chmod 0600 ".mam.env" 2>/dev/null || true
|
||||||
|
if [ -f "$manifest" ]; then
|
||||||
|
if grep -Fqx ".env" "$manifest" 2>/dev/null; then
|
||||||
|
python3 -c '
|
||||||
|
import sys
|
||||||
|
path = sys.argv[1]
|
||||||
|
with open(path, "r") as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
with open(path, "w") as f:
|
||||||
|
for line in lines:
|
||||||
|
if line.strip() == ".env":
|
||||||
|
f.write(".mam.env\n")
|
||||||
|
else:
|
||||||
|
f.write(line)
|
||||||
|
' "$manifest" 2>/dev/null || true
|
||||||
|
else
|
||||||
|
echo ".mam.env" >> "$manifest"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "ℹ️ Legacy MAM config migrated: .env -> .mam.env"
|
||||||
|
else
|
||||||
|
echo "ℹ️ Existing .env left untouched (ownership unproven)."
|
||||||
|
echo " MAM will read it via the deprecated fallback."
|
||||||
|
echo " To migrate explicitly: deploy/generate-env.sh --migrate-legacy"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
migrate_legacy_env
|
||||||
|
|
||||||
|
# M-1: Shadowing prevention guard — only create new default config if no legacy env or update tmp exists
|
||||||
|
if [ ! -f "$ENV_FILE" ] && [ ! -f ".env" ] && [ ! -f ".env.update-tmp" ]; then
|
||||||
if [ -f "$ENV_EXAMPLE" ]; then
|
if [ -f "$ENV_EXAMPLE" ]; then
|
||||||
echo "📝 Creating configuration from $ENV_EXAMPLE..."
|
echo "📝 Creating configuration from $ENV_EXAMPLE..."
|
||||||
cp "$ENV_EXAMPLE" "$ENV_FILE"
|
cp "$ENV_EXAMPLE" "$ENV_FILE"
|
||||||
@@ -297,14 +335,18 @@ MQTT_CLIENT_ID_PREFIX=mam-agent
|
|||||||
HERDR_SERVER_NAME=default
|
HERDR_SERVER_NAME=default
|
||||||
EOF
|
EOF
|
||||||
chmod 0600 "$ENV_FILE"
|
chmod 0600 "$ENV_FILE"
|
||||||
echo "✅ Config file .env initialized with chmod 0600."
|
echo "✅ Config file .mam.env initialized with chmod 0600."
|
||||||
|
|
||||||
# Record the newly created .env in the manifest
|
# Record the newly created .mam.env in the manifest
|
||||||
mkdir -p .mam
|
mkdir -p .mam
|
||||||
touch .mam/install_manifest.txt
|
touch .mam/install_manifest.txt
|
||||||
echo "$ENV_FILE" >> .mam/install_manifest.txt
|
echo "$ENV_FILE" >> .mam/install_manifest.txt
|
||||||
else
|
else
|
||||||
echo "ℹ️ $ENV_FILE already exists. Skipping config override."
|
if [ -f "$ENV_FILE" ]; then
|
||||||
|
echo "ℹ️ $ENV_FILE already exists. Skipping config override."
|
||||||
|
else
|
||||||
|
echo "ℹ️ Legacy environment detected. Preserved without shadowing."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "===================================================================="
|
echo "===================================================================="
|
||||||
|
|||||||
@@ -119,9 +119,9 @@ rsync -a --exclude='.git/' --exclude='/reports/' --exclude='*.log' --exclude='__
|
|||||||
log_ok "Deployed Rules and Skills under target's .agents/"
|
log_ok "Deployed Rules and Skills under target's .agents/"
|
||||||
|
|
||||||
# Copy config templates and generate scripts (M-2)
|
# Copy config templates and generate scripts (M-2)
|
||||||
if [ -f "$SRC_DIR/.env.example" ]; then
|
if [ -f "$SRC_DIR/.mam.env.example" ]; then
|
||||||
cp "$SRC_DIR/.env.example" "$TARGET_DIR/.env.example"
|
cp "$SRC_DIR/.mam.env.example" "$TARGET_DIR/.mam.env.example"
|
||||||
log_ok "Copied .env.example configuration template"
|
log_ok "Copied .mam.env.example configuration template"
|
||||||
fi
|
fi
|
||||||
if [ -f "$SRC_DIR/deploy/generate-env.sh" ]; then
|
if [ -f "$SRC_DIR/deploy/generate-env.sh" ]; then
|
||||||
mkdir -p "$TARGET_DIR/scripts"
|
mkdir -p "$TARGET_DIR/scripts"
|
||||||
|
|||||||
Reference in New Issue
Block a user