Skip to content

Commit

Permalink
Added installer
Browse files Browse the repository at this point in the history
  • Loading branch information
Aklakan committed Apr 21, 2020
1 parent 139fc32 commit 7e32c82
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dcat-suite-bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.aksw.dcat-suite</groupId>
<artifactId>dcat-suite-parent</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
</parent>

<!-- scm section needs to be duplicated on child module for github-release-plugin;
Expand Down
7 changes: 7 additions & 0 deletions dcat-suite-cli/src/main/java/dcat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import org.aksw.dcat_suite.cli.main.MainCliDcatSuite;

public class dcat {
public static void main(String[] args) throws Exception {
MainCliDcatSuite.main(args);
}
}
95 changes: 95 additions & 0 deletions setup-latest-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/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="dcat-suite"
gitApiUrl="https://api.github.com/repos/SmartDataAnalytics/dcat-suite/releases/latest"
downloadPattern="download/.*-with-dependencies.jar"

declare -a cmdToClass
cmdToClass[0]="dcat"

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"

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

0 comments on commit 7e32c82

Please sign in to comment.