annotate package-files/osx/JavaApplicationStub @ 61:fd93b545db4d

Ooops, forgot these.
author David Barts <n5jrn@me.com>
date Sun, 03 Apr 2022 16:58:01 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
1 #!/bin/bash
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
2
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
3 # This is based on Tobias Fischer's universalJavaApplicationStub:
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
4 # https://github.com/tofi86/universalJavaApplicationStub
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
5 #
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
6 # Therefore this part of JpegWasher is covered by the same MIT license
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
7 # that his code is:
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
8 #
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
9 # The MIT License (MIT)
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
10 #
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
11 # Copyright (c) 2014-2020 Tobias Fischer
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
12 #
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
13 # Permission is hereby granted, free of charge, to any person obtaining a copy
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
14 # of this software and associated documentation files (the "Software"), to deal
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
15 # in the Software without restriction, including without limitation the rights
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
16 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
17 # copies of the Software, and to permit persons to whom the Software is
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
18 # furnished to do so, subject to the following conditions:
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
19 #
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
20 # The above copyright notice and this permission notice shall be included in all
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
21 # copies or substantial portions of the Software.
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
22 #
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
23 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
24 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
25 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
26 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
27 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
28 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
29 # SOFTWARE.
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
30
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
31 # Establish our application names
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
32 appname="@app.name@"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
33 appdom="@app.domain@"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
34
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
35 # Make a place for our logs to go
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
36 appsupp="$HOME/Library/Application Support/$appdom"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
37 logfile="$appsupp/launcher.log"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
38
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
39 function die {
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
40 osascript -e "tell application \"System Events\" to display dialog \"${1}\" with title \"Fatal Error\" buttons {\" OK \"} default button 1"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
41 exit ${2:-1}
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
42 }
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
43
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
44 # Initialize files and dirs, bail if we can't.
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
45 if [ ! -d "$appsupp" ]
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
46 then
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
47 if ! mkdir -p "$appsupp"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
48 then
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
49 die "Unable to create folder '$appsupp'" 2
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
50 fi
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
51 fi
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
52 > "$logfile"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
53 if [ $? -ne 0 ]
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
54 then
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
55 die "Unable to create file '$logfile'" 2
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
56 fi
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
57
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
58 function stub_logger {
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
59 echo "$(date +%c) - $1" >> "$logfile"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
60 }
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
61
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
62 # Was originally just for debugging, but I think this could be useful
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
63 # for later troubleshooting "in the wild."
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
64 stub_logger "execution begins"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
65 {
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
66 echo "****** BEGIN ARGUMENT AND ENVIRONMENT DUMP *******"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
67 echo "Arguments:" "$0" "$@"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
68 echo "Directory:" $(pwd)
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
69 env
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
70 echo "******* END ARGUMENT AND ENVIRONMENT DUMP ********"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
71 } >> "$logfile"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
72
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
73 # Change to the application root directory, two up from where this script
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
74 # (which should contain an absolute path) is.
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
75 mydir="${0%/*}"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
76 cd "$mydir/../.." || die "Unable to cd '$mydir/../..'"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
77
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
78 # Determine where Java is, bail if we can't.
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
79 if [ -n "$JAVA_HOME" ]
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
80 then
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
81 if [ ! -d "$JAVA_HOME" ]
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
82 then
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
83 die "'$JAVA_HOME' does not exist"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
84 fi
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
85 else
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
86 export JAVA_HOME="$(/usr/libexec/java_home)"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
87 if [ $? -ne 0 -o ! -d "$JAVA_HOME" ]
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
88 then
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
89 die "Unable to locate Java."
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
90 fi
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
91 fi
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
92
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
93 java="$JAVA_HOME/bin/java"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
94 if [ ! -x "$java" ]
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
95 then
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
96 die "'$java' not found or not executable"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
97 fi
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
98
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
99 function plist_get {
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
100 /usr/libexec/PlistBuddy -c "print $1" Contents/Info.plist 2> /dev/null
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
101 }
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
102 function must_get {
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
103 plist_get "$@" || die "Info.plist key '$1' not found."
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
104 }
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
105
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
106 # Load some parameters from Contents/Info.plist
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
107 estat=0
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
108 CFBundleName=$(must_get ':CFBundleName')
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
109 CFBundleIconFile=$(must_get ':CFBundleIconFile')
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
110 JVMMainClassName=$(must_get ':JVMMainClassName')
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
111 JVMClassPath=$(must_get ':JVMClassPath')
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
112 JVMVersion=$(must_get ':JVMVersion')
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
113
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
114 # Sanity check our JVM version
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
115 if [[ "$JVMVersion" == *+ ]]
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
116 then
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
117 op='>'
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
118 JVMVersion="${JVMVersion%+}"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
119 else
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
120 op='='
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
121 fi
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
122 version=$("$java" -version 2>&1 | awk '/version/{print $3}' | sed -E -e 's/"//g' -e 's/-ea//g')
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
123 if [ ! "$version" "$op" "$JVMVersion" ]
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
124 then
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
125 die "'$java' too old"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
126 fi
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
127
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
128 # Load the JVMOptions array (if found)
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
129 JVMOptions=()
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
130 let i=0
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
131 while true
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
132 do
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
133 j="$(plist_get :JVMOptions:$i)"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
134 if [ -z "$j" ]
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
135 then
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
136 break
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
137 fi
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
138 JVMOptions+=("$j")
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
139 let i+=1
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
140 done
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
141
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
142 # Fatal error if we cannot change to HOME or HOME not defined
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
143 approot="$(pwd)"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
144 if [ -z "$HOME" ]
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
145 then
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
146 die "HOME not defined!"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
147 fi
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
148 cd "$HOME" || die "Unable to cd '$HOME'"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
149
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
150 # And off we go!
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
151 jcmd=( "$JAVA_HOME/bin/java" -cp "$approot/$JVMClassPath"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
152 -Xdock:icon="$approot/Contents/Resources/$CFBundleIconFile"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
153 -Xdock:name="$CFBundleName" "${JVMOptions[@]}" "$JVMMainClassName" )
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
154
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
155 stub_logger "Executing: ${jcmd[*]}"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
156 exec "${jcmd[@]}"
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
157
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
158 # This shouldn't happen...
fd93b545db4d Ooops, forgot these.
David Barts <n5jrn@me.com>
parents:
diff changeset
159 die "Could not launch Java."