当前位置:网站首页>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
边栏推荐
- Binary tree non-recursive traversal
- SQL注入 Less42(POST型堆叠注入)
- Bionic caterpillar robot source code
- Weekly Summary
- I don't know what to do with sync issues
- 登录业务实现(单点登录+微信扫码+短信服务)
- #yyds dry goods inventory# Interview must brush TOP101: the entry node of the ring in the linked list
- 新产品如何进行网络推广?
- ECCV 2022 Huake & ETH propose OSFormer, the first one-stage Transformer framework for camouflaging instance segmentation!The code is open source!...
- C程序设计-方法与实践(清华大学出版社)习题解析
猜你喜欢
Dry goods | 10 tips for MySQL add, delete, change query performance optimization
【Acwing】The 62nd Weekly Game Solution
Go mode tidy reports an error go warning “all” matched no packages
ECCV 2022 Huake & ETH propose OSFormer, the first one-stage Transformer framework for camouflaging instance segmentation!The code is open source!...
A high-quality WordPress download site template theme developed abroad
I don't know what to do with sync issues
AI automatic code writing plugin Copilot (co-pilot)
景区手绘地图的绘制流程
Interview assault 69: TCP reliable?Why is that?
Unity - by casting and cloning method dynamic control under various UGUI create and display
随机推荐
iNeuOS industrial Internet operating system, equipment operation and maintenance business and "low-code" form development tools
Unity - LineRenderer show a line
[QNX Hypervisor 2.2 User Manual]9.14 set
Go mode tidy reports an error go warning “all” matched no packages
Golang - from entry to abandonment
21. Support Vector Machine - Introduction to Kernel Functions
(26) About menu of the top menu of Blender source code analysis
Components of TypeScript
Weekly Summary
Handwritten a simple web server (B/S architecture)
Golang must know the Go Mod command
Recognize anomalies (you will understand after reading this)
Embedded development has no passion, is it normal?
MySQL数据库‘反斜杠\’ ,‘单引号‘’,‘双引号“’,‘null’无法存储
MATLAB program design and application 2.4 Common internal functions of MATLAB
Judging decimal points and rounding of decimal operations in Golang
linux view redis version command (linux view mysql version number)
[QNX Hypervisor 2.2用户手册]9.16 system
基于单片机GSM的防火防盗系统的设计
数据分析(一)——matplotlib