当前位置:网站首页>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




边栏推荐
- How to identify fake reptiles?
- Binary tree non-recursive traversal
- [QNX Hypervisor 2.2用户手册]9.16 system
- I don't know what to do with sync issues
- Pytest first experience
- useragent online lookup
- 周总结
- [Code Hoof Set Novice Village 600 Questions] Merge two numbers without passing a character array
- Douyin fetches video list based on keywords API
- One thing to say, is outsourcing company worth it?
猜你喜欢

A high-quality WordPress download site template theme developed abroad
![[Code Hoof Set Novice Village 600 Questions] Merge two numbers without passing a character array](/img/4d/038e6cd6ecad19934122cff89f4d76.png)
[Code Hoof Set Novice Village 600 Questions] Merge two numbers without passing a character array

如何减少软件设计和实现之间鸿沟

Flex layout in detail

21. Support Vector Machine - Introduction to Kernel Functions

Memblaze released the first enterprise-grade SSD based on long-lasting particles. What is the new value behind it?

程序进程和线程(线程的并发与并行)以及线程的基本创建和使用

Go1.18 upgrade function - Fuzz test from scratch in Go language
SQL27 View user details of different age groups

新产品如何进行网络推广?
随机推荐
20. Support vector machine - knowledge of mathematical principles
Realize serial port receiving data based on STM32 ring queue
How to get useragent
Transfer Learning - Domain Adaptation
A high-quality WordPress download site template theme developed abroad
Bionic caterpillar robot source code
ICML2022 | 深入研究置换敏感的图神经网络
「APIO2010」巡逻 题解
spark reports an error OutOfMemory "recommended collection"
Write a database document management tool based on WPF repeating the wheel (1)
输入输出优化
uniapp小程序检查、提示更新
Go mode tidy reports an error go warning “all” matched no packages
Several methods for deleting specified elements in Golang slices
"APIO2010" Patrol Problem Solution
基于单片机GSM的防火防盗系统的设计
[Intensive reading of the paper] iNeRF
Drawing process of hand-drawn map of scenic spots
Shell常用脚本:Nexus批量上传本地仓库增强版脚本(强烈推荐)
SQL注入 Less46(order by后的注入+rand()布尔盲注)