当前位置:网站首页>Shell common scripts: Nexus batch upload local warehouse enhanced version script (strongly recommended)
Shell common scripts: Nexus batch upload local warehouse enhanced version script (strongly recommended)
2022-07-31 22:51:00 【Uh-huh**】
文章目录
脚本内容
增加内容:
- The message prompt is more user-friendly
- Verify that the local repository exists
- Verify that the remote repository is connected to the network
- There is a file confirmation operation before uploading
- Displays the total number of files to be uploaded,The repository ends the script without any files to be uploaded
enhanceMavenImport.sh
#!/bin/bash
# author: LinRuChang
# date: 2022-07-27 04:15:00
# desc: nexus上传脚本
# use
# 第一种:sh enhanceMavenImport.sh -l The absolute path of the local warehouse directory -u nexus账号 -p nexus密码 -r remote private libraryURL地址
# sh enhanceMavenImport.sh绝对路径 -l /www/server/maven/repository2 -u admin -p admin123 -r http://192.168.19.107:8082/repository/lrc
#
# 第二种:Put this script in your local repository directory,然后执行即可- 【Remember that the path relationship between the local repository directory and the script is a parent-child relationship,Non-grandchildren, etc】
# sh enhanceMavenImport.sh绝对路径 -u nexus账号 -p nexus密码 -r remote private libraryURL地址
if [[ $1 == 'help' || $1 == '--help' ]]; then
echo "用法: sh $(readlink -f $0) -l The absolute path of the local repository -u nexus账号 -p nexus密码 -r 远程仓库URL地址 "
exit 0
fi
while getopts ":l:r:u:p:" opt; do
case $opt in
l) LOCAL_REP_DIR="$OPTARG"
;;
r) REPO_URL="$OPTARG"
;;
u) USERNAME="$OPTARG"
;;
p) PASSWORD="$OPTARG"
;;
esac
done
# 如果不传-l本地仓库路径,The local repository path of the directory where the current script is located
if [[ -z ${LOCAL_REP_DIR} ]]; then
#LOCAL_REP_DIR=$(pwd)
LOCAL_REP_DIR=$(readlink -f $0 | xargs dirname)
fi
echo "================入参============================="
LOCAL_REP_DIR=$( ( echo ${
LOCAL_REP_DIR} | grep '.*\(/\)$' &>/dev/null ) && echo ${LOCAL_REP_DIR} || echo ${LOCAL_REP_DIR}'/' )
echo "The address of the local warehouse to be uploaded:${LOCAL_REP_DIR}"
echo "Nexus账号:${USERNAME}"
echo "Nexus密码:${PASSWORD}"
REPO_URL=$( ( echo ${
REPO_URL} | grep '.*\(/\)$' &>/dev/null ) && echo ${REPO_URL} || echo ${REPO_URL}'/' )
echo "远程仓库URL地址:${REPO_URL}"
echo "============================================="
if [[ ${USERNAME} && ${PASSWORD} && ${REPO_URL} && -d ${LOCAL_REP_DIR} ]]; then
echo "The input parameter is not empty and the check is passed!!!"
else
echo "错误:可能Nexus的账号u、密码p、远程仓库地址rInformation is missing,Or a local repository directoryl不存在,请检查"
echo "用法: sh $(readlink -f $0) -l The absolute path of the local repository -u nexus账号 -p nexus密码 -r 远程仓库URL地址 "
exit 1;
fi
echo -e "\n================Detects remote directory address network connectivity, 请耐心等待============================="
if [[ $(curl -X PUT -w '%{http_code}' ${
REPO_URL} 2>/dev/null) == '401' ]]; then
echo "远程仓库【${REPO_URL}】访问通"
else
echo "错误:远程仓库【${REPO_URL}】访问不通, 请检查"
exit 1;
fi
echo -e "\n================A list of files to be uploaded is displayed============================="
# 进入本地仓库,Start retrieving files to upload
cd ${LOCAL_REP_DIR}
# 1. Exclude the script itself、以及含archetype-catalog、maven-metadata-deployment、maven-metadata-deploymentcharacter path to the file
# 2. The final filtered files are shaved off the front./字符
# 3. Begin one file callcurl上传
# 特殊字符/Adding the upper escape character becomes \/
LOCAL_REP_DIR_ESCAPE=$(echo "${LOCAL_REP_DIR}" | sed 's/\//\\\//g')
# The files to be uploaded in the current directory
findUploadFiles=$(find . -type f -not -path "./$0" -not -name '*.sh' -not -regex "\(.*archetype-catalog.*\|.*maven-metadata-deployment.*\)\|.*maven-metadata-local.*")
findUploadFilesCount=$(echo "${findUploadFiles}" | sed '/^s*$/d' | wc -l)
if [ ${findUploadFilesCount} -gt 0 ]; then
#uploadFiles=$(find . -type f -not -path "./$0" -not -name '*.sh' -not -regex "\(.*archetype-catalog.*\|.*maven-metadata-deployment.*\)\|.*maven-metadata-local.*" | sed "s|^\./||")
uploadFiles=$( echo -e "${findUploadFiles}" | sed "s|^\./||")
fi
echo "$( [ ${
findUploadFilesCount} -gt 0 ] && ( echo "${uploadFiles}" | sed 's/^/'"${LOCAL_REP_DIR_ESCAPE}"'&/g') || echo '' )"
echo "文件个数:${findUploadFilesCount}"
if [ ${findUploadFilesCount} -eq 0 ]; then
echo -e "\nThere are no uploadable files in the local repository,脚本结束"
exit 0
fi
while [ true ]; do
echo -e '\nPlease check if the above file path is what you need to upload?【OK to upload by pressingy、Cancel upload by pressing n】'
read ensureUpload
if [ $ensureUpload ] && [ $(echo $ensureUpload | tr [a-z] [A-Z]) == "Y" ]; then
echo -e "\n================A list of uploaded files is displayed============================="
currentUploadedCount=0
#echo "${uploadFiles}" | sed "s|^\./||" | xargs -I '{}' sh -c 'echo 已上传文件: '"${LOCAL_REP_DIR}"'{};echo "========="'
echo "${uploadFiles}" | sed "s|^\./||" | xargs -I '{}' sh -c "curl -u '$USERNAME:$PASSWORD' -X PUT -v -T {} ${REPO_URL}/{} &>/dev/null ; echo '已上传文件: ${LOCAL_REP_DIR}{}'"
echo 'The local repository file upload is complete,脚本结束'
break
elif [ $ensureUpload ] && [ $(echo $ensureUpload | tr [a-z] [A-Z]) == "N" ]; then
echo "Cancel uploading local repository files,脚本结束"
break
else
echo -e "错误:[${ensureUpload}]非法字符,Please enter the corresponding content according to the prompts"
fi
done
用法1 - 指定本地仓库
# 帮助文档
sh enhanceMavenImport.sh help
sh enhanceMavenImport.sh --help
# 指定本地仓库路径
sh enhanceMavenImport.sh -l /www/server/maven/repository2 -u admin -p admin123 -r http://192.168.19.107:8082/repository/lrc





Really perform the uploading successful operation

用法2 - Do not specify a local repository,The directory where the script is located is the local repository
# 帮助文档
sh enhanceMavenImport.sh help
sh enhanceMavenImport.sh --help
# Do not specify the local repository path,Take the directory where the current script is located as the repository path
# 切记:The path relationship between the local repository and the script is a parent-child relationship
sh enhanceMavenImport.sh -u admin -p admin123 -r http://192.168.19.107:8082/repository/lrc




边栏推荐
- 什么是客户画像管理?
- @JsonFormat(pattern=“yyyy-MM-dd“)时间差问题
- [QNX Hypervisor 2.2用户手册]9.16 system
- 无状态与有状态的区别
- @JsonFormat(pattern="yyyy-MM-dd") time difference problem
- PHP三元(三目)运算符
- [Intensive reading of the paper] iNeRF
- Daily--Kali opens SSH (detailed tutorial)
- The uniapp applet checks and prompts for updates
- [QNX Hypervisor 2.2 User Manual]9.16 system
猜你喜欢

IDA PRO中汇编结构体识别

Go1.18 upgrade function - Fuzz test from scratch in Go language

Handwritten a simple web server (B/S architecture)

(26) About menu of the top menu of Blender source code analysis

flowable workflow all business concepts

Judging decimal points and rounding of decimal operations in Golang

21. Support Vector Machine - Introduction to Kernel Functions

Embedded development has no passion, is it normal?

网易云信圈组上线实时互动频道,「破冰」弱关系社交

Recognize anomalies (you will understand after reading this)
随机推荐
【Acwing】第62场周赛 题解
How to reduce the gap between software design and implementation
Efficient Concurrency: A Detailed Explanation of Synchornized's Lock Optimization
支付模块实现
Unity-通过预制件和克隆方法动态实现各个UGUI下控件的创建和显示
#yyds干货盘点# 面试必刷TOP101:链表中环的入口结点
PHP三元(三目)运算符
SQL注入 Less42(POST型堆叠注入)
新产品如何进行网络推广?
[Intensive reading of the paper] iNeRF
周总结
"SDOI2016" Journey Problem Solution
ThreadLocal
Components of TypeScript
21. Support Vector Machine - Introduction to Kernel Functions
How to import a Golang external package and use it?
Bionic caterpillar robot source code
Golang must know the Go Mod command
uniapp小程序检查、提示更新
Document management and tools in the development process