From 808c626c612b238f6923c3ec2d6a05c5611d87db Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Thu, 29 Oct 2026 02:23:17 +0800 Subject: Add container profiles for persistent network and bind mount configuration. Signed-off-by: Richard Qin --- debian-container/lib/profiles.sh | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 debian-container/lib/profiles.sh (limited to 'debian-container/lib/profiles.sh') diff --git a/debian-container/lib/profiles.sh b/debian-container/lib/profiles.sh new file mode 100644 index 0000000..77deee7 --- /dev/null +++ b/debian-container/lib/profiles.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-3.0-or-later +# Copyright (C) 2026 by Richard Qin + +DC_PROFILE_FILE= +DC_PROFILE_NETWORK= + +dc_profile_parse() { + local file=$1 + local line + local key + local value + + while IFS= read -r line || [[ -n "$line" ]]; do + [[ -z "$line" || "$line" == \#* ]] && continue + [[ "$line" == *=* ]] || dc_die "profile 配置格式无效:$line" + key=${line%%=*} + value=${line#*=} + case "$key" in + network) + DC_PROFILE_NETWORK=$value + ;; + mount) + dc_bind_add "$value" + ;; + *) + dc_die "profile 配置项无效:$key" + ;; + esac + done < "$file" +} + +dc_profile_load() { + DC_BIND_SPECS=() + DC_BIND_SOURCES=() + DC_BIND_TARGETS=() + DC_BIND_MODES=() + DC_PROFILE_FILE="$DC_INSTANCE_DIR/config" + DC_PROFILE_NETWORK=$DC_NETWORK_MODE + + if [[ -f "$DC_PROFILE_FILE" ]]; then + dc_profile_parse "$DC_PROFILE_FILE" + fi +} + +dc_profile_write_default() { + local network_mode=$1 + + printf 'network=%s\n' "$network_mode" > "$DC_PROFILE_FILE" +} -- cgit v1.2.3