diff options
Diffstat (limited to 'debian-container/lib/common.sh')
| -rw-r--r-- | debian-container/lib/common.sh | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/debian-container/lib/common.sh b/debian-container/lib/common.sh index 19bbd78..12a318b 100644 --- a/debian-container/lib/common.sh +++ b/debian-container/lib/common.sh @@ -24,23 +24,45 @@ dc_acquire_lock() { flock -n 9 || dc_die 'Debian 容器已经在运行或正在初始化。' } +dc_select_instance() { + local name=$1 + + [[ "$name" =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ ]] || dc_die "实例名称无效:$name" + DC_INSTANCE=$name + DC_INSTANCE_DIR="$DC_INSTANCES/$DC_INSTANCE" + DC_IMAGE="$DC_INSTANCE_DIR/rootfs.ext4" + DC_ROOT="$DC_INSTANCE_DIR/root" +} + +dc_list() { + local path + + [[ -d "$DC_INSTANCES" ]] || return 0 + for path in "$DC_INSTANCES"/*; do + [[ -d "$path" ]] || continue + basename -- "$path" + done +} + dc_usage() { cat <<EOF 用法:sudo bash $DC_SCRIPT <命令> 命令: base-create [路径] 下载一次并创建 debootstrap 软件包 tarball - init [选项] 创建 Debian 容器镜像 - enter 进入容器 - delete 删除容器镜像 + init NAME [选项] 创建指定名称的容器镜像 + enter NAME 进入指定容器 + exec NAME -- CMD 在指定容器中执行命令 + status NAME 查看指定容器状态 + list 列出所有容器 + delete NAME 删除指定容器 init 选项: --tarball PATH 从本地 tarball 初始化,跳过软件包下载 环境变量: - DEBIAN_IMAGE 镜像路径(默认:当前目录/rootfs.ext4) - DEBIAN_ROOT 挂载目录(默认:当前目录/debian-root) - DEBIAN_LOCK_FILE 锁文件路径 + DEBIAN_INSTANCES 实例目录(默认:当前目录/instances) + DEBIAN_LOCK_FILE 锁文件路径(默认:/run/lock/debian-container.lock) DEBIAN_TARBALL 基础 tarball(默认:当前目录/debian-base.tar.gz) DEBIAN_SUITE Debian 版本(默认:stable) DEBIAN_MIRROR Debian 镜像地址 |
