diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-10-29 02:23:17 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-10-29 02:23:17 +0800 |
| commit | 808c626c612b238f6923c3ec2d6a05c5611d87db (patch) | |
| tree | 049edc6114487c2cecc8034c778c50ec0758aaeb /debian-container/lib/profiles.sh | |
| parent | 298dd9150ec8bc92af1bc1685726e1cd98d16b49 (diff) | |
| download | rutils-808c626c612b238f6923c3ec2d6a05c5611d87db.tar.gz rutils-808c626c612b238f6923c3ec2d6a05c5611d87db.tar.xz | |
Add container profiles for persistent network and bind mount configuration.
Signed-off-by: Richard Qin <richard.qin.x@gmail.com>
Diffstat (limited to 'debian-container/lib/profiles.sh')
| -rw-r--r-- | debian-container/lib/profiles.sh | 50 |
1 files changed, 50 insertions, 0 deletions
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" +} |
