Last active
April 15, 2021 10:55
-
-
Save jan-swiecki/1882ff8f8d779c5fa178565cde0131a1 to your computer and use it in GitHub Desktop.
Maven mvn setup JFrog password
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# go to ~/.m2 or other folder and run ./setup.sh according to below help | |
if [ -z "$3" ]; then | |
cat <<EOF | |
usage: ./setup.sh <jfrog_username> <jfrog_password> <artifactory_url> | |
example: ./setup.sh my_username my_password https://myjfrogaccount.jfrog.io/artifactory/mymavenrepositroyname | |
EOF | |
exit | |
fi | |
jfrog_username="$1" | |
jfrog_password="$2" | |
artifactory_url="$3" | |
if [ -f "settings-security.xml" -o -f "settings.xml" ]; then | |
echo "error: settings-security.xml or settings.xml already exists" >&2 | |
exit 1 | |
fi | |
master_password=`mvn --encrypt-master-password "$(cat /dev/urandom | tr -dc '[:alnum:]' | fold -w "32" | head -n 1)"` | |
cat <<EOF > settings-security.xml | |
<settingsSecurity> | |
<master>$(mvn --encrypt-master-password "$master_password")</master> | |
</settingsSecurity> | |
EOF | |
echo "settings-security.xml saved:" | |
cat settings-security.xml | sed 's#^# #g' | |
echo | |
jfrog_encrypted_password="$(mvn -Dsettings.security=settings-security.xml --encrypt-password "$jfrog_password")" | |
echo "jfrog_encrypted_password = ${jfrog_encrypted_password}" | |
echo | |
cat <<EOF > settings.xml | |
<?xml version="1.0" encoding="UTF-8"?> | |
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<servers> | |
<server> | |
<username>${jfrog_username}</username> | |
<password>${jfrog_encrypted_password}</password> | |
<id>central</id> | |
</server> | |
<server> | |
<username>${jfrog_username}</username> | |
<password>${jfrog_encrypted_password}</password> | |
<id>snapshots</id> | |
</server> | |
</servers> | |
<profiles> | |
<profile> | |
<repositories> | |
<repository> | |
<snapshots> | |
<enabled>false</enabled> | |
</snapshots> | |
<id>central</id> | |
<name>maven</name> | |
<url>${artifactory_url}</url> | |
</repository> | |
<repository> | |
<snapshots /> | |
<id>snapshots</id> | |
<name>maven</name> | |
<url>${artifactory_url}</url> | |
</repository> | |
</repositories> | |
<pluginRepositories> | |
<pluginRepository> | |
<snapshots> | |
<enabled>false</enabled> | |
</snapshots> | |
<id>central</id> | |
<name>maven</name> | |
<url>${artifactory_url}</url> | |
</pluginRepository> | |
<pluginRepository> | |
<snapshots /> | |
<id>snapshots</id> | |
<name>maven</name> | |
<url>${artifactory_url}</url> | |
</pluginRepository> | |
</pluginRepositories> | |
<id>artifactory</id> | |
</profile> | |
</profiles> | |
<activeProfiles> | |
<activeProfile>artifactory</activeProfile> | |
</activeProfiles> | |
</settings> | |
EOF | |
echo "settings.xml saved" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment