-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-jar
More file actions
executable file
·51 lines (41 loc) · 1.09 KB
/
install-jar
File metadata and controls
executable file
·51 lines (41 loc) · 1.09 KB
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
#!/usr/bin/bash
# Create an executable script that wraps a JAR file so that it can be invoked
# like any other binary. Some primitive checks are applied to avoid accidentally
# overriding existing files.
TARGET=$HOME/.local/share/java
if [ $# -lt 1 ]
then
echo Usage:
echo " $0 <JAR file to be installed>"
exit 1
fi
if [ ! -f $1 ]
then
echo JAR file not found. Abort.
exit 2
fi
# Create target directory if it does not exist.
mkdir -p $TARGET
# Check if a JAR with the same name already exists in the target directory.
JAR_NAME=$(basename $1)
if [ -f $TARGET/$JAR_NAME ]
then
echo $JAR_NAME already exists in target directory. Abort.
exit 3
fi
# Check if a file that has the same name as the launch script already exists.
SCRIPT_NAME=$HOME/bin/$(basename $1 .jar)
if [ -f $SCRIPT_NAME ]
then
echo $SCRIPT_NAME already exists. Abort.
exit 4
fi
# Copy JAR
echo Installing $JAR_NAME in $TARGET
cp $1 $TARGET/$JAR_NAME
# Create launch script
SCRIPT_CODE="#!/usr/bin/bash
java -jar $TARGET/$JAR_NAME \$@"
echo "$SCRIPT_CODE" > $SCRIPT_NAME
chmod +x $SCRIPT_NAME
echo Done.