From 9eda3ac981087c619780b9566dcd669deaa377b7 Mon Sep 17 00:00:00 2001 From: Martin <1403951401@qq.com> Date: Mon, 13 Jan 2025 21:12:49 +0800 Subject: [PATCH] =?UTF-8?q?[+]=20=E5=8E=86=E5=8F=B2=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++++-- docker-compose.yaml | 6 +++++- init-all.sh | 26 +++++++++++++++++++++----- init-apt.sh | 6 ++++-- init-docker.sh | 15 ++++++++++++--- init-git.sh | 6 ++++-- init-npm.sh | 5 ++++- init-pip.sh | 4 +++- 8 files changed, 58 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 93419c8..1b95885 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,11 @@ docker compose run ubuntu bash #### APT 镜像源配置测试 ```bash -docker compose run debian ./init-apt.sh +docker compose run debian ./init-all.sh ``` ```bash -docker compose run ubuntu ./init-apt.sh +docker compose run ubuntu ./init-all.sh +``` +```bash +docker compose run ubuntu-2204 ./init-all.sh ``` \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 41d8268..b2a40b6 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -13,4 +13,8 @@ services: ubuntu: <<: *app-config - image: docker.martin98.com/library/ubuntu:latest \ No newline at end of file + image: docker.martin98.com/library/ubuntu:latest + + ubuntu-2204: + <<: *app-config + image: docker.martin98.com/library/ubuntu:22.04 \ No newline at end of file diff --git a/init-all.sh b/init-all.sh index 3a0ea27..8643d52 100644 --- a/init-all.sh +++ b/init-all.sh @@ -1,12 +1,28 @@ #!/bin/bash +download_and_run() { + local filename="$1" + local url="https://git.martin98.com/MartinFarm/init/raw/branch/main/$1" + + if [ ! -f "$filename" ]; then + echo "文件 $filename 不存在,正在下载..." + curl -sSL "$url" -o "$filename" + if [ $? -ne 0 ]; then + echo "下载失败,请检查网络连接或URL是否正确。" + exit 1 + fi + fi + bash "$filename" +} + + # apt + ntp -curl -sSL https://git.martin98.com/MartinFarm/init/raw/branch/main/init-apt.sh | bash +download_and_run "init-apt.sh" # docker-ce -curl -sSL https://git.martin98.com/MartinFarm/init/raw/branch/main/init-docker.sh | bash +download_and_run "init-docker.sh" # npm -curl -sSL https://git.martin98.com/MartinFarm/init/raw/branch/main/init-npm.sh | bash +download_and_run "init-npm.sh" # pip -curl -sSL https://git.martin98.com/MartinFarm/init/raw/branch/main/init-pip.sh | bash +download_and_run "init-pip.sh" # git -curl -sSL https://git.martin98.com/MartinFarm/init/raw/branch/main/init-git.sh | bash \ No newline at end of file +download_and_run "init-git.sh" \ No newline at end of file diff --git a/init-apt.sh b/init-apt.sh index 97e5ad3..3375080 100644 --- a/init-apt.sh +++ b/init-apt.sh @@ -1,5 +1,7 @@ #!/bin/bash +APT_OPTIONS="-o Acquire::https::mirrors.martin98.com::Verify-Peer=false -o Acquire::https::mirrors.martin98.com::Verify-Host=false" + type=$(cat /etc/*release | grep ^ID= | cut -d= -f2) release=$(cat /etc/*release | grep VERSION_CODENAME | cut -d= -f2) components=$([ "${type}" = "debian" ] && echo "main contrib non-free non-free-firmware" || ([ "${type}" = "ubuntu" ] && echo "main restricted universe multiverse")) @@ -31,9 +33,9 @@ else exit 1 fi +echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections # 更新证书 -APT_OPTIONS="-o Acquire::https::mirrors.martin98.com::Verify-Peer=false -o Acquire::https::mirrors.martin98.com::Verify-Host=false" -apt update $APT_OPTIONS && apt install $APT_OPTIONS -y ca-certificates && update-ca-certificates +apt update $APT_OPTIONS && apt install $APT_OPTIONS -y ca-certificates curl && update-ca-certificates apt update && apt upgrade -y diff --git a/init-docker.sh b/init-docker.sh index 795a69d..2bb98a4 100644 --- a/init-docker.sh +++ b/init-docker.sh @@ -3,10 +3,19 @@ command_exists() { command -v "$@" > /dev/null 2>&1 } +is_wsl() { + case "$(uname -r)" in + *microsoft* ) true ;; # WSL 2 + *Microsoft* ) true ;; # WSL 1 + * ) false;; + esac +} -if command_exists docker; then - echo "docker 已安装.... 跳过" - ( set -x; sleep 5 ) +if is_wsl; then + echo "检测到 WSL 环境,建议使用 Docker Desktop." + exit 0 +elif command_exists docker; then + echo "Docker 已安装.... 跳过安装" else curl -sSL https://git.martin98.com/MartinFarm/init/raw/branch/main/docker-install.sh | sh fi diff --git a/init-git.sh b/init-git.sh index cfe833e..bb1aeb1 100644 --- a/init-git.sh +++ b/init-git.sh @@ -1,8 +1,10 @@ #!/bin/bash # 检查 git 是否安装 -if command -v pip &> /dev/null; then +if command -v git > /dev/null 2>&1; then echo "git 已安装,正在配置镜像源..." git config --global url."https://git-proxy.hk.martin98.com/".insteadOf "https://" echo "镜像源配置完成。" -fi \ No newline at end of file +else + echo "git 不存在,跳过..." +fi diff --git a/init-npm.sh b/init-npm.sh index f023d23..c983d4a 100644 --- a/init-npm.sh +++ b/init-npm.sh @@ -1,8 +1,11 @@ #!/bin/bash # 检查 npm 是否安装 -if command -v npm &> /dev/null; then + +if command -v npm > /dev/null 2>&1; then echo "npm 已安装,正在配置镜像源..." npm config set registry https://mirrors.martin98.com/repository/npm-group/ echo "镜像源配置完成。" +else + echo "npm 不存在,跳过..." fi \ No newline at end of file diff --git a/init-pip.sh b/init-pip.sh index 19e96ee..0b5a887 100644 --- a/init-pip.sh +++ b/init-pip.sh @@ -1,8 +1,10 @@ #!/bin/bash # 检查 pip 是否安装 -if command -v pip &> /dev/null; then +if command -v pip > /dev/null 2>&1; then echo "pip 已安装,正在配置镜像源..." pip config set global.index-url https://mirrors.martin98.com/repository/pypi-group/simple echo "镜像源配置完成。" +else + echo "pip 不存在,跳过..." fi \ No newline at end of file