|
@@ -58,22 +58,22 @@ update_package_manager() {
|
|
|
elif [[ "$OS" == *"CentOS"* ]] || [[ "$OS" == *"Red Hat"* ]] || [[ "$OS" == *"Rocky"* ]] || [[ "$OS" == *"AlmaLinux"* ]]; then
|
|
|
if command -v dnf &> /dev/null; then
|
|
|
dnf update -y
|
|
|
- dnf install -y curl wget
|
|
|
+ dnf install -y curl wget jq
|
|
|
else
|
|
|
yum update -y
|
|
|
- yum install -y curl wget
|
|
|
+ yum install -y curl wget jq
|
|
|
fi
|
|
|
else
|
|
|
print_message "使用通用方式安装curl和wget..."
|
|
|
# 尝试通用方式安装
|
|
|
if command -v apt &> /dev/null; then
|
|
|
- apt update && apt install -y curl wget
|
|
|
+ apt update && apt install -y curl wget jq
|
|
|
elif command -v dnf &> /dev/null; then
|
|
|
- dnf install -y curl wget
|
|
|
+ dnf install -y curl wget jq
|
|
|
elif command -v yum &> /dev/null; then
|
|
|
- yum install -y curl wget
|
|
|
+ yum install -y curl wget jq
|
|
|
elif command -v zypper &> /dev/null; then
|
|
|
- zypper install -y curl wget
|
|
|
+ zypper install -y curl wget jq
|
|
|
else
|
|
|
print_warning "无法自动安装curl和wget,请手动安装"
|
|
|
fi
|
|
@@ -141,8 +141,49 @@ install_docker_compose() {
|
|
|
ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose
|
|
|
}
|
|
|
|
|
|
+# 写入JSON配置文件的函数(更安全)
|
|
|
+write_json_config() {
|
|
|
+ local file_path="$1"
|
|
|
+ local json_content="$2"
|
|
|
+
|
|
|
+ mkdir -p "$(dirname "$file_path")"
|
|
|
+
|
|
|
+ if command -v jq &> /dev/null; then
|
|
|
+ if echo "$json_content" | jq . > /dev/null 2>&1; then
|
|
|
+ print_message "JSON格式验证通过"
|
|
|
+ else
|
|
|
+ print_error "JSON格式无效"
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+
|
|
|
+ echo "$json_content" | tee "$file_path" > /dev/null
|
|
|
+
|
|
|
+ if [ $? -eq 0 ]; then
|
|
|
+ print_message "成功写入JSON配置文件: $file_path"
|
|
|
+ else
|
|
|
+ print_error "写入JSON配置文件失败: $file_path"
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
# 验证安装
|
|
|
verify_installation() {
|
|
|
+ # 修改国内的docker源
|
|
|
+ local docker_daemon_config='{
|
|
|
+ "registry-mirrors": [
|
|
|
+ "https://docker.1panel.live",
|
|
|
+ "https://docker.1ms.run",
|
|
|
+ "https://docker.m.daocloud.io",
|
|
|
+ "https://registry.cn-hangzhou.aliyuncs.com"
|
|
|
+ ]
|
|
|
+ }'
|
|
|
+
|
|
|
+ write_json_config "/etc/docker/daemon.json" "$docker_daemon_config"
|
|
|
+
|
|
|
+ systemctl daemon-reload
|
|
|
+ systemctl restart docker
|
|
|
+
|
|
|
print_message "验证安装..."
|
|
|
|
|
|
if command -v docker &> /dev/null; then
|