Skip to content

Commit 5e50971

Browse files
committed
fix:支持环境变量无交互安装
1 parent 24ff97b commit 5e50971

4 files changed

Lines changed: 75 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
2026.03.10
44

5+
- 支持无CDN加速模式,增加环境变量检测
6+
7+
2026.03.10
8+
59
- 支持通过 `WITHOUTCDN=TRUE` 完全禁用 CDN 加速地址探测与使用
610

711
2026.03.01

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
## 更新
66

7-
2026.03.10
7+
2026.04.06
88

9-
- 支持无CDN加速模式,增加环境变量检测
9+
- 支持环境变量无交互安装
1010

1111
[更新日志](CHANGELOG.md)
1212

dockeruninstall.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# https://github.com/oneclickvirt/docker
44
# 2026.03.01
55
# 完整卸载 Docker 环境及所有容器
6+
# 支持的环境变量(一键非交互卸载):
7+
# CONFIRM=yes - 跳过卸载确认提示,直接执行卸载
68

79
_red() { echo -e "\033[31m\033[01m$@\033[0m"; }
810
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
@@ -21,10 +23,14 @@ echo " 包含:所有运行中/停止的容器、所有镜像、"
2123
echo " Docker 网络配置、systemd 服务、Docker 二进制及数据目录"
2224
echo " 操作不可逆!"
2325
echo "======================================================"
24-
read -rp "$(_yellow "确认卸载?输入 yes 继续,其他任意键退出: ")" confirm
25-
if [[ "$confirm" != "yes" ]]; then
26-
_green "已取消"
27-
exit 0
26+
if [[ "${CONFIRM^^}" == "YES" ]]; then
27+
_yellow "CONFIRM=YES detected, skipping confirmation prompt"
28+
else
29+
read -rp "$(_yellow "确认卸载?输入 yes 继续,其他任意键退出: ")" confirm
30+
if [[ "$confirm" != "yes" ]]; then
31+
_green "已取消"
32+
exit 0
33+
fi
2834
fi
2935

3036
# ======== 1. 停止并删除所有容器 ========

scripts/dockerinstall.sh

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ without_cdn="false"
3030
if [[ "${WITHOUTCDN^^}" == "TRUE" ]]; then
3131
without_cdn="true"
3232
fi
33+
# 支持的环境变量(一键非交互安装):
34+
# WITHOUTCDN=true - 禁用 CDN 加速
35+
# CN=true - 强制使用中国镜像源
36+
# CN=false - 强制不使用中国镜像源(跳过检测)
37+
# IPV6_MAXIMUM_SUBSET=y/n - 是否使用 IPv6 最大子网范围(SLAAC 场景)
38+
# NEED_DISK_LIMIT=y/n - 是否启用容器磁盘大小限制(btrfs)
39+
# DOCKER_INSTALL_PATH=... - Docker 数据目录(默认 /var/lib/docker)
40+
# DOCKER_POOL_SIZE=20 - Docker 存储池大小(单位 GB,需 NEED_DISK_LIMIT=y)
41+
# DOCKER_LOOP_FILE=... - Docker loop 文件路径(默认 /opt/docker-pool.img)
3342

3443
temp_file_apt_fix="/tmp/apt_fix.txt"
3544
REGEX=("debian" "ubuntu" "centos|red hat|kernel|oracle linux|alma|rocky" "'amazon linux'" "fedora" "arch" "alpine")
@@ -445,6 +454,14 @@ get_system_arch() {
445454

446455
check_china() {
447456
_yellow "IP area being detected ......"
457+
if [[ "${CN^^}" == "TRUE" ]]; then
458+
_yellow "CN=TRUE detected, using Chinese mirrors"
459+
CN=true
460+
return
461+
elif [[ "${CN^^}" == "FALSE" ]]; then
462+
_yellow "CN=FALSE detected, skipping Chinese mirrors"
463+
return
464+
fi
448465
if [[ -z "${CN}" ]]; then
449466
if [[ $(curl -m 6 -s https://ipapi.co/json | grep 'China') != "" ]]; then
450467
_yellow "根据ipapi.co提供的信息,当前IP可能在中国"
@@ -857,7 +874,15 @@ if [[ -n "$ipv6_address" ]]; then
857874
_blue "It is detected that IPV6 addresses are most likely to be dynamically assigned by SLAAC, and if there is no subsequent need to assign separate IPV6 addresses to VMs/containers, the following option is best selected n"
858875
_green "检测到IPV6地址大概率由SLAAC动态分配,若后续不需要分配独立的IPV6地址给虚拟机/容器,则下面选项最好选 n, 选择 y 有概率导致宿主机丢失网络"
859876
_blue "Is the maximum subnet range feasible with IPV6 used?([n]/y)"
860-
reading "是否使用IPV6可行的最大子网范围?([n]/y)" select_maximum_subset
877+
if [[ "${IPV6_MAXIMUM_SUBSET^^}" == "Y" || "${IPV6_MAXIMUM_SUBSET^^}" == "TRUE" ]]; then
878+
_yellow "IPV6_MAXIMUM_SUBSET=${IPV6_MAXIMUM_SUBSET} detected, using maximum IPv6 subnet"
879+
select_maximum_subset="y"
880+
elif [[ "${IPV6_MAXIMUM_SUBSET^^}" == "N" || "${IPV6_MAXIMUM_SUBSET^^}" == "FALSE" ]]; then
881+
_yellow "IPV6_MAXIMUM_SUBSET=${IPV6_MAXIMUM_SUBSET} detected, skipping maximum IPv6 subnet"
882+
select_maximum_subset="n"
883+
else
884+
reading "是否使用IPV6可行的最大子网范围?([n]/y)" select_maximum_subset
885+
fi
861886
if [ "$select_maximum_subset" = "y" ] || [ "$select_maximum_subset" = "Y" ]; then
862887
echo "true" >/usr/local/bin/docker_maximum_subset
863888
else
@@ -900,26 +925,46 @@ _blue "If you choose 'y', you can limit the disk space for each container"
900925
_blue "If you choose 'n', standard Docker installation without disk limits"
901926
_blue "如果选择 'y',可以为每个容器限制磁盘空间"
902927
_blue "如果选择 'n',则为标准Docker安装,无磁盘限制"
903-
reading "Do you need container disk size limitation? ([n]/y): " need_disk_limit
928+
if [[ -n "${NEED_DISK_LIMIT}" ]]; then
929+
_yellow "NEED_DISK_LIMIT=${NEED_DISK_LIMIT} detected, skipping prompt"
930+
need_disk_limit="${NEED_DISK_LIMIT}"
931+
else
932+
reading "Do you need container disk size limitation? ([n]/y): " need_disk_limit
933+
fi
904934
_green "Where do you want to install Docker? (Enter to default: /var/lib/docker):"
905-
reading "Docker安装路径?(回车则默认:/var/lib/docker):" docker_install_path
935+
if [[ -n "${DOCKER_INSTALL_PATH}" ]]; then
936+
_yellow "DOCKER_INSTALL_PATH=${DOCKER_INSTALL_PATH} detected, skipping prompt"
937+
docker_install_path="${DOCKER_INSTALL_PATH}"
938+
else
939+
reading "Docker安装路径?(回车则默认:/var/lib/docker):" docker_install_path
940+
fi
906941
if [ -z "$docker_install_path" ]; then
907942
docker_install_path="/var/lib/docker"
908943
fi
909944
if [ "$need_disk_limit" = "y" ] || [ "$need_disk_limit" = "Y" ]; then
910945
echo "true" > /usr/local/bin/docker_need_disk_limit
911-
while true; do
912-
_green "How large a Docker storage pool is needed? (unit: GB, e.g., enter 20 for 20G):"
913-
reading "需要多大的Docker存储池?(单位GB,例如输入20表示20G):" docker_pool_size
914-
if [[ "$docker_pool_size" =~ ^[1-9][0-9]*$ ]]; then
915-
break
916-
else
917-
_yellow "Invalid input, please enter a positive integer."
918-
_yellow "输入无效,请输入一个正整数。"
919-
fi
920-
done
946+
if [[ -n "${DOCKER_POOL_SIZE}" ]] && [[ "${DOCKER_POOL_SIZE}" =~ ^[1-9][0-9]*$ ]]; then
947+
_yellow "DOCKER_POOL_SIZE=${DOCKER_POOL_SIZE} detected, skipping prompt"
948+
docker_pool_size="${DOCKER_POOL_SIZE}"
949+
else
950+
while true; do
951+
_green "How large a Docker storage pool is needed? (unit: GB, e.g., enter 20 for 20G):"
952+
reading "需要多大的Docker存储池?(单位GB,例如输入20表示20G):" docker_pool_size
953+
if [[ "$docker_pool_size" =~ ^[1-9][0-9]*$ ]]; then
954+
break
955+
else
956+
_yellow "Invalid input, please enter a positive integer."
957+
_yellow "输入无效,请输入一个正整数。"
958+
fi
959+
done
960+
fi
921961
_green "Where do you want to store the Docker loop file? (Enter to default: /opt/docker-pool.img):"
922-
reading "Docker循环文件存储位置?(回车则默认:/opt/docker-pool.img):" docker_loop_file
962+
if [[ -n "${DOCKER_LOOP_FILE}" ]]; then
963+
_yellow "DOCKER_LOOP_FILE=${DOCKER_LOOP_FILE} detected, skipping prompt"
964+
docker_loop_file="${DOCKER_LOOP_FILE}"
965+
else
966+
reading "Docker循环文件存储位置?(回车则默认:/opt/docker-pool.img):" docker_loop_file
967+
fi
923968
if [ -z "$docker_loop_file" ]; then
924969
docker_loop_file="/opt/docker-pool.img"
925970
fi

0 commit comments

Comments
 (0)