Skip to content

Instantly share code, notes, and snippets.

@morandat
Created March 29, 2013 18:01
Show Gist options
  • Save morandat/5272449 to your computer and use it in GitHub Desktop.
Save morandat/5272449 to your computer and use it in GitHub Desktop.
#!/bin/sh
INSETTINGS=$HOME/.m2/settings.xml.in
SETTINGS=$HOME/.m2/settings.xml
[ "$RELEASE" ] && GOAL=release:perform
[ "$GOAL" ] || GOAL=deploy
error () {
echo $*
exit 1
}
[ -f pom.xml ] || error "no pom file"
which xpath >/dev/null 2>&1 || error "xpath is missing"
xpath pom.xml //project/version 2>/dev/null | grep SNAPSHOT >/dev/null && where=snapshotRepository || where=repository
if [ "$where" = "snapshotRepository" ] ; then
id=`xpath pom.xml //distributionManagement/$where/id 2>/dev/null | sed 's:<id>\(.*\)</id>:\1:'`
[ -z "$id" ] && where=repository
fi
id=`xpath pom.xml //distributionManagement/$where/id 2>/dev/null | sed 's:<id>\(.*\)</id>:\1:'`
grep "%USER:$id%" $INSETTINGS > /dev/null && askuser=1
grep "%PASSWORD:$id%" $INSETTINGS > /dev/null && askpassword=1
[ "$askuser" ] && echo "username ($id) :" && read -s user
[ "$askpassword" ] && echo "password ($id) :" && read -s pass
sed -e "s/%USER:$id%/$user/" -e "s/%PASSWORD:$id%/$pass/" $INSETTINGS > $SETTINGS
mvn $GOAL $*
cp -f $INSETTINGS $SETTINGS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment