#!/bin/sh
#$1 - filepath of the local repo where the tree begins
#$2 - repo id like in settings.xml e.g. myrepo
#$3 - url of the repo eg. http://my-nexus.at:8081/repository/myrepo_releases/
MAVEN_EXECUTABLE="/apache-maven-3.3.9/bin/mvn"
if [ $# -eq 4 ]
then
echo "Search in repo: $1"
find $1 -type f -iname "*.jar" -print0 | while IFS= read -r -d $'\0' line; do
relative_path_name="${line/$1/}"
echo "RelativePathName: $relative_path_name"
IFS='/' read -r -a array <<< "$relative_path_name"
length=${#array[@]}
pos=0;
artifactidends=$((length -1 -2)) #-1 because auf array starts at 0 and length returns the count
versionends=$((length -1 - 1)) #-1 because auf array starts at 0 and length returns the count
version="${array[$versionends]}"
filenameends=$((length -1))
filename="${array[$filenameends]}"
artifactIdVersion=${array[$artifactidends]}"-"$version
## find out classification
classification="${filename/.jar/''}"
classification="${classification/$artifactIdVersion/''}"
if [[ ${classification:0:1} == "-" ]]
then
classification=${classification:1}
fi
groupends=$((length - 3))
group=
for element in "${array[@]}"
do
if [ $pos -lt $groupends ]
then
echo "GroupPart: ${array[$pos]}"
group=$group"."${array[$pos]}
fi
pos=$((pos + 1))
done
group=${group:1}
echo "Group: $group"
if [ $group == "$4" ]
then
echo "$relative_path_name"
echo "ArtifactId: ${array[$artifactidends]}"
echo "Version: $version"
echo "Classification: $classification"
echo "Group: $group"
mavencmd="$MAVEN_EXECUTABLE deploy:deploy-file -DgroupId=$group -DartifactId=${array[$artifactidends]} -Dversion=$version -Dclassifier=$classification -Dpackaging=jar -Dfile=./$relative_path_name -DrepositoryId=$2 -Durl=$3"
echo "MavenCMD: $mavencmd"
eval $mavencmd
echo "upload done"
else
echo "upload not done (group does not match: $group)"
fi
echo -e ""
echo -e ""
done
else
echo "USAGE"
echo -e ""
echo " * Call the command with params:"
echo " ./upload_all_to_nexus.sh localRepoFilepath repoId repoUrl groupToConsider"
echo -e ""
echo " * Example:"
echo " ./upload_all_to_nexus.sh /tmp/not_local_repository/ myrepo http://my-nexus.at:8081/repository/repo my.group"
fi
運行此,我得到: upload_all_to_nexus.sh:14:/首頁/ dhardiker /upload_all_to_nexus.sh:語法錯誤:意外重定向 我會對它進行破解,但是直截了當的剪切粘貼失敗了。 –
我更新了上面的腳本 –