-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup-latest-release.sh
executable file
·98 lines (75 loc) · 2.55 KB
/
setup-latest-release.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
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
#
# Simple self-contained un-/install script for creating multiple commands from a single jar bundle
# cmdToClass is the 'dataset' of shell command to java class mappings
# As root, commands will be created under /usr/local/share/$pkgName/bin and then symlinked to /usr/local/bin
# Uninstalling removes any command from /usr/local/bin that also exists in /usr/local/share/$pkgName/bin
# For non-root users the folders are ~/Downloads/$pkgName and ~/bin
#
# Usage:
# Installation is run by providing no additional argument:
# ./setup.sh
# To uninstall run
# ./setup.sh uninstall
#
set -e
arg="$1"
pkgName="rdf-processing-toolkit"
gitApiUrl="https://api.github.com/repos/SmartDataAnalytics/RdfProcessingToolkit/releases/latest"
downloadPattern="download/.*-with-dependencies.jar"
declare -a cmdToClass
cmdToClass[0]="sparql-integrate sparqlintegrate"
cmdToClass[1]="ngs"
if [ "$USER" = "root" ]; then
jarFolder="/usr/local/share/$pkgName"
binFolder="/usr/local/bin"
else
jarFolder="$HOME/Downloads/$pkgName"
binFolder="$HOME/bin"
fi
# tmpBinFolder must be relative to jarFolder
tmpBinFolder="$jarFolder/bin"
# Safety check to prevent accidental deletetion of unrelated files
# Don't change code below
if [ -z "$pkgName" ]; then
echo "Package name must not be empty"
exit 1
fi
# On uninstall, delete all files in the binFolder that are symlinks to the tmpBinFolder
if [ "$arg" = "uninstall" ]; then
echo "Uninstalling: $pkgName"
if [ -d "$tmpBinFolder" ]; then
for item in `ls -A "$tmpBinFolder"`; do
cmd="$binFolder/$item"
echo "Uninstalling command: $cmd"
rm -f "$cmd"
done
fi
echo "Removing package folder: $jarFolder"
rm -rf "$jarFolder"
elif [ -z "$arg" ]; then
echo "Installing: $pkgName"
mkdir -p "$binFolder"
downloadUrl=`curl -s "$gitApiUrl" | grep "$downloadPattern" | cut -d : -f 2,3 | tr -d ' "'`
jarFileName=`basename "$downloadUrl"`
mkdir -p "$tmpBinFolder"
echo "Downloading: $downloadUrl"
(cd "$jarFolder" && wget -c "$downloadUrl")
jarPath="$jarFolder/$jarFileName"
for item in "${cmdToClass[@]}"
do
IFS=" " read -r -a arr <<< "${item}"
cmd="${arr[0]}"
class="${arr[1]-$cmd}"
tmpCmdPath="$tmpBinFolder/$cmd"
cmdPath="$binFolder/$cmd"
echo "Setting up command: $cmdPath"
echo -e "#!/bin/bash\njava \$JAVA_OPTS -cp $jarPath $class \"\$@\"" > "$tmpCmdPath"
chmod +x "$tmpCmdPath"
ln -s "$tmpCmdPath" "$cmdPath"
done
else
echo "Invalid argument: $arg"
echo "Run '$0' without argument to install $pkgName or '$0 uninstall' to uninstall it"
exit 1
fi