44# 2026.03.01
55#
66# Supported environment variables (non-interactive mode / 支持的环境变量,可实现无交互安装):
7+ # noninteractive=true - Use defaults for prompts / 使用默认值跳过交互提示
78# WITHOUTCDN=TRUE - Disable CDN acceleration / 禁用 CDN 加速
89# NEED_DISK_LIMIT=y - Enable container disk size limitation (btrfs) / 启用容器磁盘大小限制 (btrfs);默认: n
910# CONTAINERD_INSTALL_PATH= - containerd data root path / containerd 数据根路径;默认: /var/lib/containerd
10- # CONTAINERD_POOL_SIZE=20 - Storage pool size in GB / 存储池大小(GB),NEED_DISK_LIMIT=y 时必填
11+ # CONTAINERD_POOL_SIZE=20 - Storage pool size in GB / 存储池大小(GB),NEED_DISK_LIMIT=y 时默认: 20
1112# CONTAINERD_LOOP_FILE= - Loop file path / 循环文件路径;默认: /opt/containerd-pool.img
1213#
1314# Example / 示例:
15+ # export noninteractive=true
16+ # bash containerdinstall.sh
1417# NEED_DISK_LIMIT=y CONTAINERD_POOL_SIZE=20 bash containerdinstall.sh
1518# CONTAINERD_INSTALL_PATH=/data/containerd bash containerdinstall.sh
1619
@@ -19,6 +22,21 @@ _green() { echo -e "\033[32m\033[01m$*\033[0m"; }
1922_yellow () { echo -e " \033[33m\033[01m$* \033[0m" ; }
2023_blue () { echo -e " \033[36m\033[01m$* \033[0m" ; }
2124reading () { read -rp " $( _green " $1 " ) " " $2 " ; }
25+ is_noninteractive () {
26+ case " $( printf ' %s' " ${noninteractive:- } " | tr ' [:upper:]' ' [:lower:]' ) " in
27+ true|yes|y|1) return 0 ;;
28+ * ) return 1 ;;
29+ esac
30+ }
31+ is_yes () {
32+ case " $( printf ' %s' " $1 " | tr ' [:upper:]' ' [:lower:]' ) " in
33+ y|yes|true|1) return 0 ;;
34+ * ) return 1 ;;
35+ esac
36+ }
37+ DEFAULT_CONTAINERD_INSTALL_PATH=" /var/lib/containerd"
38+ DEFAULT_CONTAINERD_POOL_SIZE=" 20"
39+ DEFAULT_CONTAINERD_LOOP_FILE=" /opt/containerd-pool.img"
2240export DEBIAN_FRONTEND=noninteractive
2341utf8_locale=$( locale -a 2> /dev/null | grep -i -m 1 -E " UTF-8|utf8" )
2442if [[ -z " $utf8_locale " ]]; then
@@ -995,6 +1013,9 @@ main() {
9951013 if [[ -n " ${NEED_DISK_LIMIT:- } " ]]; then
9961014 need_disk_limit_input=" ${NEED_DISK_LIMIT} "
9971015 _blue " [non-interactive] NEED_DISK_LIMIT=${NEED_DISK_LIMIT} "
1016+ elif is_noninteractive; then
1017+ need_disk_limit_input=" n"
1018+ _blue " [non-interactive] noninteractive=true, NEED_DISK_LIMIT defaulting to n"
9981019 else
9991020 _green " Do you need containerd with container disk size limitation? (Support btrfs snapshotter)"
10001021 _green " 是否需要支持容器硬盘大小限制的 containerd 环境?(使用 btrfs 快照器)"
@@ -1009,18 +1030,21 @@ main() {
10091030 if [[ -n " ${CONTAINERD_INSTALL_PATH:- } " ]]; then
10101031 containerd_install_path=" ${CONTAINERD_INSTALL_PATH} "
10111032 _blue " [non-interactive] CONTAINERD_INSTALL_PATH=${CONTAINERD_INSTALL_PATH} "
1033+ elif is_noninteractive; then
1034+ containerd_install_path=" $DEFAULT_CONTAINERD_INSTALL_PATH "
1035+ _blue " [non-interactive] noninteractive=true, CONTAINERD_INSTALL_PATH defaulting to ${containerd_install_path} "
10121036 else
1013- _green " Where do you want to install containerd? (Enter to default: /var/lib/containerd ):"
1014- reading " containerd 安装路径?(回车则默认:/var/lib/containerd ):" containerd_install_path
1037+ _green " Where do you want to install containerd? (Enter to default: ${DEFAULT_CONTAINERD_INSTALL_PATH} ):"
1038+ reading " containerd 安装路径?(回车则默认:${DEFAULT_CONTAINERD_INSTALL_PATH} ):" containerd_install_path
10151039 if [ -z " $containerd_install_path " ]; then
1016- containerd_install_path=" /var/lib/containerd "
1040+ containerd_install_path=" $DEFAULT_CONTAINERD_INSTALL_PATH "
10171041 fi
10181042 fi
10191043 echo " $containerd_install_path " > /usr/local/bin/containerd_install_path
10201044
10211045 containerd_pool_size=" "
10221046 containerd_loop_file=" "
1023- if [ " $need_disk_limit_input " = " y " ] || [ " $need_disk_limit_input " = " Y " ] ; then
1047+ if is_yes " $need_disk_limit_input " ; then
10241048 echo " true" > /usr/local/bin/containerd_need_disk_limit
10251049 # 存储池大小(支持环境变量 CONTAINERD_POOL_SIZE)
10261050 if [[ -n " ${CONTAINERD_POOL_SIZE:- } " ]]; then
@@ -1031,6 +1055,9 @@ main() {
10311055 _red " Invalid CONTAINERD_POOL_SIZE='${CONTAINERD_POOL_SIZE} ', must be a positive integer."
10321056 exit 1
10331057 fi
1058+ elif is_noninteractive; then
1059+ containerd_pool_size=" $DEFAULT_CONTAINERD_POOL_SIZE "
1060+ _blue " [non-interactive] noninteractive=true, CONTAINERD_POOL_SIZE defaulting to ${containerd_pool_size} "
10341061 else
10351062 while true ; do
10361063 _green " How large a containerd storage pool is needed? (unit: GB, e.g., enter 20 for 20G):"
@@ -1047,11 +1074,14 @@ main() {
10471074 if [[ -n " ${CONTAINERD_LOOP_FILE:- } " ]]; then
10481075 containerd_loop_file=" ${CONTAINERD_LOOP_FILE} "
10491076 _blue " [non-interactive] CONTAINERD_LOOP_FILE=${CONTAINERD_LOOP_FILE} "
1077+ elif is_noninteractive; then
1078+ containerd_loop_file=" $DEFAULT_CONTAINERD_LOOP_FILE "
1079+ _blue " [non-interactive] noninteractive=true, CONTAINERD_LOOP_FILE defaulting to ${containerd_loop_file} "
10501080 else
1051- _green " Where do you want to store the containerd loop file? (Enter to default: /opt/containerd-pool.img ):"
1052- reading " containerd 循环文件存储位置?(回车则默认:/opt/containerd-pool.img ):" containerd_loop_file
1081+ _green " Where do you want to store the containerd loop file? (Enter to default: ${DEFAULT_CONTAINERD_LOOP_FILE} ):"
1082+ reading " containerd 循环文件存储位置?(回车则默认:${DEFAULT_CONTAINERD_LOOP_FILE} ):" containerd_loop_file
10531083 if [ -z " $containerd_loop_file " ]; then
1054- containerd_loop_file=" /opt/containerd-pool.img "
1084+ containerd_loop_file=" $DEFAULT_CONTAINERD_LOOP_FILE "
10551085 fi
10561086 fi
10571087 else
@@ -1128,4 +1158,3 @@ main() {
11281158}
11291159
11301160main " $@ "
1131-
0 commit comments