source: main/trunk/release-kits/shared/mac/Wrapper.app/Contents/MacOS/greenstone

Last change on this file was 37672, checked in by anupama, 12 months ago

Making mac DMG's MacOS/greenstone script do what the linux wrapper.cpp script does in terms of handling command-line flags minus h/help or minus-minus help to display usage, minus extract and minux textonly, not just the default behaviour of trying to launch the graphical version of the Mac installer.

  • Property svn:executable set to *
File size: 4.7 KB
Line 
1#!/bin/bash
2
3BINDIR="`dirname "$0"`"
4cd "$BINDIR/.."
5BASEDIR="`pwd`"
6
7displayUsage() {
8 echo "Usage: $0 [OPTIONS]"
9 echo "OPTIONS: "
10 echo " -h, -help Display this usage message"
11 echo " -textonly Do a non-graphical command line installation"
12 echo " -extract Extract the jar file, this can then be run manually (such as with custom Java options as arguments to the installer jar file)."
13}
14
15# install_mode can be:
16# Default behaviour (graphical installer, forced to textonly mode in non-graphical environment
17# manual setting to Textonly mode
18# Extract mode to extract jar file
19install_mode="default"
20
21
22if [ "x$1" != "x" ]; then
23 if [ "$1" == "-h" ] || [ "$1" == "-help" ] || [ "$1" == "--help" ] ; then
24 displayUsage
25 exit 0
26 elif [ "$1" == "-textonly" ] || [ "$1" == "-text" ] || [ "$1" == "text" ] ; then
27 install_mode="textonly"
28 elif [ "$1" == "-extract" ] || [ "$1" == "--extract" ] || [ "$1" == "-x" ] ; then
29 install_mode="extract"
30 else
31 displayUsage
32 exit 0
33 fi
34fi
35
36
37# Debugging with a msg box. Need double quotes around msg for $var expansion
38#osascript -e "tell app \"System Events\" to display alert \"bindir is: $BINDIR\" as warning giving up after 10"
39
40## But this doesn't work:
41# http://stackoverflow.com/questions/23923017/osascript-using-bash-variable-with-a-space
42#osascript -e "display notification \"$BINDIR\""
43#osascript -e 'display notification "'"$BINDIR"'"'
44
45# extract the JRE into /tmp and use its java to run the GS jar installer
46# the /tmp/jre folder will be moved into GS3/packages by the GS3 installer
47
48if [[ -e "$BASEDIR/Resources/Java/jre_bin" ]]; then
49 cp "$BASEDIR/Resources/Java/jre_bin" /tmp/. && chmod +x "/tmp/jre_bin" && "/tmp/jre_bin" -o"/tmp" #&& rm "/tmp/jre_bin"
50
51 if [[ -e "/tmp/jre.tar" ]]; then
52 rm /tmp/jre_bin
53 # get the GS jar installer's name and run it with a dock icon (http://stackoverflow.com/questions/6006173/how-do-you-change-the-dock-icon-of-a-java-program)
54 cd "$BASEDIR/Resources/Java/"
55 gs_installer=`ls Greenstone-*-MacOS-intel.jar`
56 export JRE_HOME=/tmp/jre
57 export PATH=$JRE_HOME/bin:$PATH
58 #tar -xvf /tmp/jre.tar -C /tmp && rm /tmp/jre.tar && "/tmp/jre/bin/java" -jar -Xdock:icon="$BASEDIR/Resources/icon.icns" "$gs_installer"
59
60 tar -xvf /tmp/jre.tar -C /tmp && rm /tmp/jre.tar
61
62 if [ "$install_mode" = "extract" ] ; then
63 # no need to extract: installer jar file already available in mac app
64 echo ""
65 echo "(Extracting jar file on mac is superfluous: the jar file is already ready for use at $gs_installer)"
66 echo "You can now run '/tmp/jre/bin/java -jar \"$BASEDIR/Resources/Java/$gs_installer\" text'"
67 echo " to run the installer from the command line."
68 echo "Once you're finished with the installer, you can run \"rm -rf /tmp/jre\" to get rid of the temporary Java Runtime."
69 echo "Note: if the installer fails to run due to insufficient memory, try preceding the -jar with -Xmx300M in the above command."
70 echo ""
71 elif [ "$install_mode" = "textonly" ] ; then
72 "/tmp/jre/bin/java" -Xmx300M -jar "$gs_installer" "text"
73 else # "$install_mode" = "default", run the usual graphical GS3 mac installer
74 # which already falls back to textonly mode if no graphical environment available
75 "/tmp/jre/bin/java" -jar -Xdock:icon="$BASEDIR/Resources/icon.icns" "$gs_installer"
76 fi
77
78 # if after running the installer, the user cancelled installation, then the jre would still be in tmp, remove it to
79 if [ "$install_mode" != "extract" ] ; then
80 if [[ -e "/tmp/jre" ]]; then
81 rm -rf /tmp/jre
82 fi
83 fi
84 else
85 # Issues extracting the jre.tar into /tmp (maybe we couldn't even copy it there) - display error message
86 # see: https://developer.apple.com/library/mac/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW11
87 osascript -e "tell app \"System Events\" to display alert \"Unable to unpack jre into /tmp folder\" as warning giving up after 10"
88 # exit
89 fi
90else
91 # try using a system java to run the installer, as there is no bundled jre_bin for 32 bit Mac OS since these already came with java installed
92 " -h, -help Display this usage message"
93
94 # get the GS jar installer's name and run it with a dock icon (http://stackoverflow.com/questions/6006173/how-do-you-change-the-dock-icon-of-a-java-program)
95 cd "$BASEDIR/Resources/Java/"
96 gs_installer=`ls Greenstone-*-MacOS-intel.jar`
97
98 # on a mac, the system java is returned by running /usr/libexec/java_home
99 # use this to run the greenstone installer
100 `/usr/libexec/java_home`/bin/java -jar -Xdock:icon="$BASEDIR/Resources/icon.icns" "$gs_installer"
101fi
Note: See TracBrowser for help on using the repository browser.