diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-10-28 23:13:09 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-10-28 23:13:09 +0800 |
| commit | e7236907dfe3e9130d532d5e8a7f2b17af13df1c (patch) | |
| tree | 3548beab69f96ad5d669152b248d0ab15769dafe /debian-container/lib/common.sh | |
| parent | 36cf23ae3ba7295ca4021258681996fbbba9b14d (diff) | |
| download | rutils-e7236907dfe3e9130d532d5e8a7f2b17af13df1c.tar.gz rutils-e7236907dfe3e9130d532d5e8a7f2b17af13df1c.tar.xz | |
Refactor Debian container script into modular components with configurable paths and documentation.
Signed-off-by: Richard Qin <richard.qin.x@gmail.com>
Diffstat (limited to 'debian-container/lib/common.sh')
| -rw-r--r-- | debian-container/lib/common.sh | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/debian-container/lib/common.sh b/debian-container/lib/common.sh new file mode 100644 index 0000000..1fd08b0 --- /dev/null +++ b/debian-container/lib/common.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-3.0-or-later +# Copyright (C) 2026 by Richard Qin + +dc_die() { + echo "$*" >&2 + exit 1 +} + +dc_require_root() { + [[ ${EUID} -eq 0 ]] || dc_die '请使用 sudo 执行此脚本。' +} + +dc_require_commands() { + local tool + for tool in "$@"; do + command -v "$tool" >/dev/null || dc_die "缺少工具:$tool" + done +} + +dc_acquire_lock() { + mkdir -p "$(dirname -- "$DC_LOCK_FILE")" + exec 9>"$DC_LOCK_FILE" + flock -n 9 || dc_die 'Debian 容器已经在运行或正在初始化。' +} + +dc_usage() { + cat <<EOF +用法:sudo bash $DC_SCRIPT <命令> + +命令: + init 创建 Debian 容器镜像 + enter 进入容器 + delete 删除容器镜像 + +环境变量: + DEBIAN_IMAGE 镜像路径(默认:当前目录/rootfs.ext4) + DEBIAN_ROOT 挂载目录(默认:当前目录/debian-root) + DEBIAN_LOCK_FILE 锁文件路径 +EOF +} + |
