Files

50 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -Eeuo pipefail
runtime_directory="${1:-/srv/ai-soulmate/runtime/external-tools-production-20260416}"
profile_directory="${2:-/srv/ai-soulmate/runtime/u1-profiles}"
source_profile="$runtime_directory/bin/squashfs-root/resources/profiles/Snapmaker/process/0.20 Standard @Snapmaker (0.4 nozzle).json"
target_profile="$profile_directory/u1-compatible-generic-process.json"
if ! command -v python3 >/dev/null 2>&1; then
printf 'Required command is unavailable: python3\n' >&2
exit 1
fi
if [[ ! -f "$source_profile" ]]; then
printf 'Generic Snapmaker process profile not found: %s\n' "$source_profile" >&2
exit 1
fi
install -d -m 0750 "$profile_directory"
temporary_profile="$(mktemp "$profile_directory/.u1-compatible-generic-process.XXXXXX")"
trap 'rm -f "$temporary_profile"' EXIT
python3 - "$source_profile" "$temporary_profile" <<'PY'
import json
import sys
source_path, target_path = sys.argv[1:]
with open(source_path, encoding="utf-8") as source_file:
profile = json.load(source_file)
if profile.get("type") != "process":
raise SystemExit("source profile is not a process profile")
profile.pop("inherits", None)
profile["name"] = "0.20 Standard @Snapmaker U1 (local compatibility)"
profile["setting_id"] = "LOCAL_U1_COMPAT_GENERIC"
profile["compatible_printers"] = ["Snapmaker U1 (0.4 nozzle)"]
profile.pop("compatible_printers_condition", None)
with open(target_path, "w", encoding="utf-8") as target_file:
json.dump(profile, target_file, ensure_ascii=False, indent=2)
target_file.write("\n")
PY
chmod 0640 "$temporary_profile"
mv -f "$temporary_profile" "$target_profile"
trap - EXIT
printf 'U1 local process profile prepared: %s\n' "$target_profile"
sha256sum "$target_profile"