#!/usr/bin/bash # 配置nexus 客户端 local_repo=${repo:=10.36.181.67} repo_type=1 # 1 阿里云 0 本地 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 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 "缓存创建完成" } docker_repo(){ if [ ! -d "/etc/docker/" ]; then mkdir /etc/docker fi 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 npm_repo elif [[ $num -eq 5 ]];then maven_repo elif [[ $num == "q" ]];then exit 0 else echo "输入有误,请重新输入" fi