当前位置:网站首页>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
边栏推荐
- [Code Hoof Set Novice Village 600 Questions] Merge two numbers without passing a character array
- C#中引用类型的变量做为参数在方法调用时加不加 ref 关键字的不同之处
- The article you worked so hard to write may not be your original
- @JsonFormat(pattern="yyyy-MM-dd") time difference problem
- A solution to the server encountered an internal error that prevented it from fulfilling this request [easy to understand]
- Bika LIMS open source LIMS set - use of SENAITE (detection process)
- Dry goods | 10 tips for MySQL add, delete, change query performance optimization
- Chapter Six
- C language parsing json string (json object is converted to string)
- 22年8月推广大使额外奖励规则
猜你喜欢
[Code Hoof Set Novice Village 600 Questions] Merge two numbers without passing a character array
【ACM】2022.7.31训练赛
A high-quality WordPress download site template theme developed abroad
AI automatic code writing plugin Copilot (co-pilot)
Bionic caterpillar robot source code
Design of Fire and Anti-theft System Based on Single Chip GSM
[Intensive reading of the paper] iNeRF
Unity - by casting and cloning method dynamic control under various UGUI create and display
Embedded development has no passion, is it normal?
Federated Learning: Multi-source Knowledge Graph Embedding in Federated Scenarios
随机推荐
uniapp小程序检查、提示更新
cas and spin locks (is lightweight locks spin locks)
Realize serial port receiving data based on STM32 ring queue
Weekly Summary
Niuke.com brush questions (1)
什么是客户画像管理?
嵌入式开发没有激情了,正常吗?
[QNX Hypervisor 2.2用户手册]9.15 suppress
C#中引用类型的变量做为参数在方法调用时加不加 ref 关键字的不同之处
Flex layout in detail
useragent online lookup
手写一个简单的web服务器(B/S架构)
[Open class preview]: Research and application of super-resolution technology in the field of video image quality enhancement
「APIO2010」巡逻 题解
SQL27 View user details of different age groups
Payment module implementation
高等代数_证明_任何矩阵都相似于一个上三角矩阵
LevelSequence source code analysis
Learn about C# anonymous methods
How to import a Golang external package and use it?