feat: split update config into update.env
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
set -euo pipefail
|
||||
|
||||
ENV_FILE="${ENV_FILE:-/etc/skd/env}"
|
||||
UPDATE_ENV_FILE="${UPDATE_ENV_FILE:-/etc/skd/update.env}"
|
||||
SERVICE_URL="${SKD_UPDATE_SERVICE_URL:-}"
|
||||
PROJECT_ID="${SKD_UPDATE_PROJECT_ID:-}"
|
||||
TOKEN_FILE="${SKD_UPDATE_TOKEN_FILE:-}"
|
||||
@ -20,7 +21,8 @@ Options:
|
||||
--client-id ID Client ID (default: hostname)
|
||||
--software-id ID Software ID (default: safe-kiddo)
|
||||
--output PATH Write token to PATH (default: SKD_UPDATE_TOKEN_FILE if set)
|
||||
--env-file PATH Read env file (default: /etc/skd/env)
|
||||
--env-file PATH Read core env file (default: /etc/skd/env)
|
||||
--update-env PATH Read update env file (default: /etc/skd/update.env)
|
||||
-h, --help Show this help
|
||||
EOF
|
||||
}
|
||||
@ -34,6 +36,7 @@ while [[ $# -gt 0 ]]; do
|
||||
--enroll-token) ENROLL_TOKEN="$2"; shift 2 ;;
|
||||
--output) OUTPUT_PATH="$2"; shift 2 ;;
|
||||
--env-file) ENV_FILE="$2"; shift 2 ;;
|
||||
--update-env) UPDATE_ENV_FILE="$2"; shift 2 ;;
|
||||
-h|--help) usage; exit 0 ;;
|
||||
*) echo "Unknown option: $1" >&2; usage; exit 1 ;;
|
||||
esac
|
||||
@ -41,26 +44,26 @@ done
|
||||
|
||||
read_env_value() {
|
||||
local key="$1"
|
||||
python3 - <<'PY' "${ENV_FILE}" "${key}"
|
||||
python3 - <<'PY' "${ENV_FILE}" "${UPDATE_ENV_FILE}" "${key}"
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
path = Path(sys.argv[1])
|
||||
key = sys.argv[2]
|
||||
if not path.exists():
|
||||
sys.exit(0)
|
||||
|
||||
for raw in path.read_text(encoding="utf-8").splitlines():
|
||||
line = raw.strip()
|
||||
if not line or line.startswith("#"):
|
||||
env_paths = [Path(sys.argv[1]), Path(sys.argv[2])]
|
||||
key = sys.argv[3]
|
||||
for path in env_paths:
|
||||
if not path.exists():
|
||||
continue
|
||||
if not line.startswith(f"{key}="):
|
||||
continue
|
||||
value = line.split("=", 1)[1].strip()
|
||||
if (value.startswith('"') and value.endswith('"')) or (value.startswith("'") and value.endswith("'")):
|
||||
value = value[1:-1]
|
||||
print(value)
|
||||
sys.exit(0)
|
||||
for raw in path.read_text(encoding="utf-8").splitlines():
|
||||
line = raw.strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
if not line.startswith(f"{key}="):
|
||||
continue
|
||||
value = line.split("=", 1)[1].strip()
|
||||
if (value.startswith('"') and value.endswith('"')) or (value.startswith("'") and value.endswith("'")):
|
||||
value = value[1:-1]
|
||||
print(value)
|
||||
sys.exit(0)
|
||||
PY
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user