From 64738f328ad8dadad5d7fdc4a34418c1ae95aaab Mon Sep 17 00:00:00 2001 From: newrain001 Date: Fri, 19 Apr 2024 19:12:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'os/get-repo.sh'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- os/get-repo.sh | 172 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 133 insertions(+), 39 deletions(-) diff --git a/os/get-repo.sh b/os/get-repo.sh index b021daa..c499923 100644 --- a/os/get-repo.sh +++ b/os/get-repo.sh @@ -2,63 +2,157 @@ # 配置nexus 客户端 +local_repo=${repo:=10.36.181.67} +repo_type=1 # 1 阿里云 0 本地 -bar=" -==================================\n - Nexus 客户端配置 \n - 1. 配置yum源 \n - 2. 配置docker镜像仓库 \n - 3. 配置pip源 \n - 4. 【未启用】配置npm源 \n - 5. 【未启用】配置maven源 \n - 6. 配置阿里云源 \n - q. 退出 \n -=================================" -echo -e $bar -read -p "请选择配置项: " num -if [[ $num -eq 1 ]];then +check_resolv(){ + grep "$1" /etc/hosts &>/dev/null || return 0 +} +check_local(){ + ping -w 2 -c 1 $local_repo &>/dev/null + if [ $? -eq 0 ];then + read -p "已检测到本地仓库,是否继续配置?[yes/no]" yn + if [ $yn = "y" ] || [ $yn = "yes" ] || [ $yn = "YES" ];then + repo_type=0 + fi + fi +} + +yum_repo(){ cd /etc/yum.repos.d/ && \ dirname=$(mktemp -d repo-XXXXX) mv *.repo $dirname 2>/dev/null - echo "开始下载资源,请等待" - for i in nexus-Centos-Base.repo nexus-epel.repo nexus-mysql.repo nexus-docker-ce.repo nexus-kubernetes.repo - do - curl -s -o $i "https://gitea.beyourself.org.cn/newrain001/download/raw/branch/master/repo/$i" - echo "yum 源 $i 配置完成" - sleep 0.5 - done + if [ $repo_type -eq 0 ];then + check_resolv yum.cloud.repo && echo "$local_repo yum.cloud.repo " >> /etc/hosts + echo "开始下载资源,请等待" + for i in nexus-Centos-Base.repo nexus-epel.repo nexus-mysql.repo nexus-docker-ce.repo nexus-kubernetes.repo + do + curl -s -o $i "https://gitea.beyourself.org.cn/newrain001/download/raw/branch/master/repo/$i" + echo "yum 源 $i 配置完成" + done + elif [ $repo_type -eq 1 ];then + curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo + curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo + echo "阿里云源配置完成" + fi echo "开始创建缓存" yum clean all && \ yum makecache && \ echo "缓存创建完成" -elif [[ $num -eq 2 ]];then +} + +docker_repo(){ if [ ! -d "/etc/docker/" ]; then mkdir /etc/docker fi - curl -o /etc/docker/daemon.json https://gitea.beyourself.org.cn/newrain001/download/raw/branch/master/repo/nexus-daemon.json - echo "daemon.json 配置完成" -elif [[ $num -eq 3 ]];then + if [ $repo_type -eq 0 ];then + check_resolv docker.cloud.repo && echo "$local_repo docker.cloud.repo " >> /etc/hosts + curl -o /etc/docker/daemon.json https://gitea.beyourself.org.cn/newrain001/download/raw/branch/master/repo/nexus-daemon.json + elif [ $repo_type -eq 1 ];then + cat > /etc/docker/daemon.json <> /etc/hosts + curl -o $HOME/.pip/pip.conf https://gitea.beyourself.org.cn/newrain001/download/raw/branch/master/repo/nexus-pip.conf + elif [ $repo_type -eq 1 ];then + cat > $HOME/.pip/pip.conf <> /etc/hosts + curl -o $HOME/.npmrc https://gitea.beyourself.org.cn/newrain001/download/raw/branch/master/repo/.npmrc + elif [ $repo_type -eq 1 ];then + cat > $HOME/.npmrc <> /etc/hosts + curl https://gitea.beyourself.org.cn/newrain001/download/raw/branch/master/repo/settings.xml + elif [ $repo_type -eq 1 ];then + cat < + aliyunmaven + * + 阿里云公共仓库 + https://maven.aliyun.com/repository/public + +EOF + fi +} + + + +check_local +if [ $repo_type -eq 1 ];then +bar=" +代码地址:https://gitea.beyourself.org.cn/newrain001/shell-project/src/branch/master/os/get-repo.sh +==================================\n + 阿里云源配置 \n + 1. 配置阿里云yum源 \n + 2. 配置阿里云镜像加速器 \n + 3. 配置阿里云pip源 \n + 4. 配置阿里云npm源 \n + 5. 配置阿里云maven源 \n + q. 退出 \n +==================================\n" +else +bar=" +代码地址:https://gitea.beyourself.org.cn/newrain001/shell-project/src/branch/master/os/get-repo.sh +==================================\n + 本地源配置 \n + 1. 配置本地yum源 \n + 2. 配置本地镜像加速器 \n + 3. 配置本地pip源 \n + 4. 配置本地npm源 \n + 5. 配置本地maven源 \n + q. 退出 \n +==================================\n" +fi +echo -e $bar +read -p "请选择配置项: " num +if [[ $num -eq 1 ]];then + yum_repo +elif [[ $num -eq 2 ]];then + docker_repo +elif [[ $num -eq 3 ]];then + pip_repo elif [[ $num -eq 4 ]];then - echo "暂不支持" + npm_repo elif [[ $num -eq 5 ]];then - echo "暂不支持" -elif [[ $num -eq 6 ]];then - cd /etc/yum.repos.d/ && \ - dirname=$(mktemp -d repo-XXXXX) - mv *.repo $dirname 2>/dev/null - curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo - curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo - echo "阿里云源配置完成" - echo "开始创建缓存" - yum clean all && \ - yum makecache && \ - echo "缓存创建完成" + maven_repo elif [[ $num == "q" ]];then exit 0 else