microsoft/hve-core
Publicmirrored from https://github.com/microsoft/hve-coreAvailable
.github/skills/installer/hve-core-installer/scripts/detect-environment.sh
38lines · modecode
| 1 | #!/usr/bin/env bash |
| 2 | # Copyright (c) Microsoft Corporation. |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | # Detects the current development environment for HVE-Core installation. |
| 5 | # Outputs key-value pairs: ENV_TYPE, IS_CODESPACES, IS_DEVCONTAINER, |
| 6 | # HAS_DEVCONTAINER_JSON, HAS_WORKSPACE_FILE, IS_HVE_CORE_REPO. |
| 7 | set -euo pipefail |
| 8 | |
| 9 | # Detect environment type |
| 10 | env_type="local" |
| 11 | is_codespaces=false |
| 12 | is_devcontainer=false |
| 13 | |
| 14 | if [ "${CODESPACES:-}" = "true" ]; then |
| 15 | env_type="codespaces" |
| 16 | is_codespaces=true |
| 17 | is_devcontainer=true |
| 18 | elif [ -f "/.dockerenv" ] || [ "${REMOTE_CONTAINERS:-}" = "true" ]; then |
| 19 | env_type="devcontainer" |
| 20 | is_devcontainer=true |
| 21 | fi |
| 22 | |
| 23 | has_devcontainer_json=false |
| 24 | [ -f ".devcontainer/devcontainer.json" ] && has_devcontainer_json=true |
| 25 | |
| 26 | has_workspace_file=false |
| 27 | [ -n "$(find . -maxdepth 1 -name '*.code-workspace' -print -quit 2>/dev/null)" ] && has_workspace_file=true |
| 28 | |
| 29 | is_hve_core_repo=false |
| 30 | repo_root=$(git rev-parse --show-toplevel 2>/dev/null || true) |
| 31 | [ -n "$repo_root" ] && [ "$(basename "$repo_root")" = "hve-core" ] && is_hve_core_repo=true |
| 32 | |
| 33 | echo "ENV_TYPE=$env_type" |
| 34 | echo "IS_CODESPACES=$is_codespaces" |
| 35 | echo "IS_DEVCONTAINER=$is_devcontainer" |
| 36 | echo "HAS_DEVCONTAINER_JSON=$has_devcontainer_json" |
| 37 | echo "HAS_WORKSPACE_FILE=$has_workspace_file" |
| 38 | echo "IS_HVE_CORE_REPO=$is_hve_core_repo" |
| 39 | |