-
Notifications
You must be signed in to change notification settings - Fork 73
/
updateDependencies.sh
executable file
·87 lines (75 loc) · 2.06 KB
/
updateDependencies.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
NON_INTERACTIVE_OPTION=$1
DEPENDENCY=$2
check_installed() {
if ! type "$1" > /dev/null; then
echo "Please ensure you have $1 installed."
exit 1
fi
}
function sedi() {
if sed --version 2> /dev/null | grep -q 'GNU' ; then
# GNU sed does not like a second argument for -i
sed -i "$@"
else
# but macOS (FreeBSD) sed needs it
sed -i '' "$@"
fi
}
check_installed curl
# check if xmllint is installed
if type xmllint > /dev/null; then
USE_XMLLINT=1 #true
else
echo "warning: xmllint is not installed - will try with 'grep' as a fallback..."
USE_XMLLINT=0 #false
fi
declare -A repos=(
[flatgraph]=https://repo1.maven.org/maven2/io/joern/flatgraph-core_3
)
function latest_version {
local NAME=$1
local REPO_URL=${repos[$NAME]}
local MVN_META_URL=$REPO_URL/maven-metadata.xml
local CURL_PARAMS="--silent --show-error $MVN_META_URL"
if (( $USE_XMLLINT ))
then
curl $CURL_PARAMS | xmllint --xpath "/metadata/versioning/latest/text()" -
else
curl $CURL_PARAMS | grep '<latest>' | sed 's/[ ]*<latest>\([0-9.]*\)<\/latest>/\1/'
fi
}
function update {
local NAME=$1
if [[ -z "${repos[$NAME]}" ]]; then
echo "error: no repo url defined for $NAME"
exit 1;
fi
local VERSION=$(latest_version $NAME)
local SEARCH="val ${NAME}Version\([ ]*\)= .*"
local OLD_VERSION=$(grep "$SEARCH" build.sbt | sed 's/.*"\(.*\)"/\1/')
if [ "$VERSION" == "$OLD_VERSION" ]
then
echo "$NAME: unchanged ($VERSION)"
else
local REPLACE="val ${NAME}Version\1= \"$VERSION\""
if [ "$NON_INTERACTIVE_OPTION" == "--non-interactive" ]
then
echo "non-interactive mode, auto-updating $NAME: $OLD_VERSION -> $VERSION"
sedi "s/$SEARCH/$REPLACE/" build.sbt
else
echo "update $NAME: $OLD_VERSION -> $VERSION? [Y/n]"
read ANSWER
if [ -z $ANSWER ] || [ "y" == $ANSWER ] || [ "Y" == $ANSWER ]
then
sedi "s/$SEARCH/$REPLACE/" build.sbt
fi
fi
fi
}
if [ "$DEPENDENCY" == "" ]; then
update flatgraph
else
DEPENDENCY="${DEPENDENCY#--only=}"
update $DEPENDENCY
fi