Last active
October 30, 2016 22:55
-
-
Save scompt/e0002bb90cc0ccc2ed265ae4c9470b05 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# Based on https://github.com/JFrogDev/project-examples/blob/master/bash-example/deploy-folder-by-checksum.sh | |
export repo_url= | |
export tgt_repo= | |
export user= | |
export pass= | |
export dir="$1" | |
if [ ! -x "`which shasum`" ]; then echo "You need to have the 'sha1sum' command in your path."; exit 1; fi | |
if [ ! -x "`which parallel`" ]; then echo "This would go a lot fast if you had 'parallel' in your path."; fi | |
doit() { | |
RELATIVE_PATH="$(echo "$1" | awk -F 'm2repository' '{print $2}')"; | |
sha1=$(shasum -a 1 "$1") | |
sha1="${sha1:0:40}" | |
sha256=$(shasum -a 256 "$1") | |
sha256="${sha256:0:64}" | |
status=$(curl -k -u $user:$pass -X PUT -H "X-Checksum-Deploy:true" -H "X-Checksum-Sha1:$sha1" -H "X-Checksum-Sha256:$sha256" --write-out %{http_code} --silent --output /dev/null "${repo_url}/${tgt_repo}/${RELATIVE_PATH}") | |
if [ ${status} -eq 404 ] | |
then | |
# No checksum found - deploy + content | |
curl -k -u $user:$pass -X PUT -H "X-Checksum-Sha1:$sha1" -H "X-Checksum-Sha256:$sha256" -T "$1" "${repo_url}/${tgt_repo}/${RELATIVE_PATH}" --silent --output /dev/null | |
echo -n 'x' | |
else | |
echo -n '.' | |
fi | |
} | |
export -f doit | |
tmpdir=$(mktemp -d) | |
trap 'rm -rf "$tmpdir"' EXIT INT TERM HUP | |
find $ANDROID_HOME -type d -name m2repository -print0 | xargs -0 -I{.} find {.} -type f -name "*.jar" -or -name "*.aar" | sort > $tmpdir/input | |
if [ -x "`which parallel`" ] | |
then | |
parallel -P 20 doit < $tmpdir/input | |
else | |
for i in `cat $tmpdir/input` | |
do | |
doit $i | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment