File: freemind.sh

package info (click to toggle)
freemind 0.9.0%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 12,288 kB
  • ctags: 9,586
  • sloc: java: 53,739; xml: 3,334; sh: 273; haskell: 55; makefile: 22
file content (229 lines) | stat: -rw-r--r-- 6,760 bytes parent folder | download | duplicates (2)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/sh
# 2004-02-13, modified for Debian by deb@zorglub.s.bawue.de
# 2004-06-19, rewritten for Linux/UN*X by deb@zorglub.s.bawue.de
#             (based on Jan Schulz's input)
# 2004-11-28, minor changes for version 0.8.0 by deb@zorglub.s.bawue.de
# 2005-01-08, removed bashims to make script POSIX conform
# 2005-01-16, added usage of FREEMIND_BASE_DIR variable
# 2005-02-18, add -Dfreemind.base.dir to make plugins work, add some ""
#             and enhance debug mode.
# 2005-11-08, adding commons-codec to classpath.
# 2005-11-09, add some dpkg/rpm information and check for Sun/Blackdown VM.
# 2006-10-29, follow links to this script using readlink.
# 2008-02-02, improve Java recognition, add lsb_release, fix -x which being empty
#             add -Dgnu.java.awt.peer.gtk.Graphics=Graphics2D for non-Sun JREs
# 2008-02-03, add debug values script and exit
# 2008-05-20 (fc): -Xmx256M added
# 2008-08-08 (ewl) accept OpenJDK as valid VM to run FreeMind.

# we only want to test the script, not FreeMind itself
if ( echo "${DEBUG}" | grep -qe "script" )
then
	set -x
fi

# debug also java-wrapper
if [ -n "${DEBUG}" ]
then
	DEBUG_WRAPPER=1
	export DEBUG_WRAPPER
fi

########## FUNCTIONS DEFINITIONS #######################################

_debug() {
	if [ -n "${DEBUG}" ]
	then
		echo "DEBUG:   $1" >&2 
		shift
		for text in "$@"
		do
			echo "         ${text}" >&2
		done
	fi
}

_error() {
	echo "ERROR:   $1" >&2
	shift
	for text in "$@"
	do
		echo "         ${text}" >&2
	done
}

findjava() {
	# We try hard to find the proper 'java' command
	if [ -n "${JAVA_CMD}" ] && [ -x "${JAVA_CMD}" ]
	then
		_debug "Using \$JAVA_CMD to find java virtual machine."
	elif [ -n "${JAVA_BINDIR}" ] && [ -x "${JAVA_BINDIR}/java" ]
	then
		JAVA_CMD="${JAVA_BINDIR}/java"
		_debug "Using \$JAVA_BINDIR to find java virtual machine."
	elif [ -n "${JAVA_HOME}" ] && [ -x "${JAVA_HOME}/bin/java" ]
	then
		JAVA_CMD="${JAVA_HOME}/bin/java"
		_debug "Using \$JAVA_HOME to find java virtual machine."
	else
		JAVA_CMD=$(which java)
		if [ -n "${JAVA_CMD}" ] && [ -x "${JAVA_CMD}" ]
		then
			_debug "Using \$PATH to find java virtual machine."
		elif [ -x /usr/bin/java ]
		then
			_debug "Using /usr/bin/java to find java virtual machine."
			JAVA_CMD=/usr/bin/java
		fi
	fi

	# if we were successful, we return 0 else we complain and return 1
	if [ -n "${JAVA_CMD}" ] && [ -x "${JAVA_CMD}" ]
	then
		_debug "Using '$JAVA_CMD' as java virtual machine..."
		if [ -n "${DEBUG}" ]
		then
			"$JAVA_CMD" -version >&2
		fi
		if (! "${JAVA_CMD}" -version 2>&1 | grep -qe 'Java(TM)' \
							-e 'OpenJDK')
		then
			_error "Your Java VM is not a complete implementation," \
			       "=======================================" \
			       "FREEMIND WILL MOST PROBABLY *NOT* WORK," \
			       "=======================================" \
			       "define JAVA_CMD, JAVA_BINDIR, JAVA_HOME or PATH in order" \
			       "to point to such a VM. See the manpage of freemind(1) for details."
			JAVA_TYPE=other
		else
			JAVA_TYPE=sun
		fi
		return 0
	else
		_error "Couldn't find a java virtual machine," \
		       "define JAVA_CMD, JAVA_BINDIR, JAVA_HOME or PATH." \
		       "See the manpage of freemind(1) for details."
		return 1
	fi
}

_source() {
	if [ -f "$1" ]
	then
		_debug "Sourcing '$1'."
		. "$1"
	fi
}

output_debug_info() {
	if [ -z "${DEBUG}" ]
	then
		return 0
	fi
	_debug "Freemind parameters are '${@}'."
	_debug "$(uname -a)"
	if [ -x "$(which lsb_release 2>/dev/null)" ]
	then
		_debug "$(lsb_release -a)"
	else
		_debug "System is not LSB conform, 'lsb_release' does not exist."
	fi
	if [ -x "$(which dpkg 2>/dev/null)" ]
	then
		_debug "The following DEB packages are installed:"
		COLUMNS=132 dpkg -l | grep -i -e freemind >&2
	elif [ -x "$(which rpm 2>/dev/null)" ]
	then
		_debug "The following RPM packages are installed:"
		rpm -qa | grep -i -e freemind >&2
	else
		_debug "Neither dpkg nor rpm is installed."
	fi
}

########## START MAIN PART #############################################

#--------- Put the environment together --------------------------------

_source /etc/freemind/freemindrc
_source ~/.freemind/freemindrc

if [ -r /usr/lib/java-wrappers/java-wrappers.sh ]
then # the Debian method
	. /usr/lib/java-wrappers/java-wrappers.sh
	require_java_runtime java6
else
	findjava
	if [ $? -ne 0 ]
	then
		exit 1
	fi
fi

output_debug_info

if [ -L "$0" ] && [ -x $(which readlink) ]
then # if the script is a link and we have 'readlink' to follow it
	# -m should be faster and link does always resolve, else this script
	# wouldn't be called, would it?
	freefile=$(readlink -mn "$0")
	_debug "Link '$0' resolved to '${freefile}'."
else
	freefile="$0"
fi
freepath=$(dirname "${freefile}")
freepath="${freepath%/bin}" # nothing happens if freemind is not installed
                            # under something/bin

# we try different possibilities to find freemind.jar
for jar in "${FREEMIND_BASE_DIR}" \
	"${freepath}" "${freepath}/share/freemind" "${freepath}/freemind"
do
	if [ -f "${jar}/lib/freemind.jar" ]
	then
		freedir="${jar}"
		_debug "Freemind Directory is '${jar}'."
		break
	fi
done

if [ -z "${freedir}" ]
then
	_error "Couldn't find freemind under '${freepath}'."
	exit 1
fi

if [ ! -f ~/.freemind/patterns.xml ] && [ -f /etc/freemind/patterns.xml ]
then
	if [ ! -d ~/.freemind ]
	then
		_debug "Creating directory ~/.freemind."
		mkdir -p ~/.freemind
	fi
	_debug "Copying patterns.xml to ~/.freemind."
	cp /etc/freemind/patterns.xml ~/.freemind/patterns.xml
fi

#--------- Call (at last) FreeMind -------------------------------------

# The CLASSPATH also lets one specify additional jars, which is good, if
# you want to add a new Look&Feel jar (the motif one is so ugly...).
# 
CLASSPATH="${ADD_JARS}:${CLASSPATH}:${freedir}/lib/freemind.jar:\
/usr/share/java/SimplyHTML.jar:\
/usr/share/java/gnu-regexp.jar:\
/usr/share/java/jibx-run-1.1.6a.jar:\
/usr/share/java/xpp3.jar:\
${freedir}/lib/bindings.jar:\
/usr/share/java/forms.jar:\
${freedir}"
if [ "${JAVA_TYPE}" = "sun" ]
then
	_debug "Calling: '${JAVA_CMD} -Dfreemind.base.dir=${freedir} -cp ${CLASSPATH} freemind.main.FreeMindStarter  $@'."
	( echo "${DEBUG}" | grep -qe "exit" ) && exit 0 # do not start FreeMind
	"${JAVA_CMD}" -Xmx256M -Dfreemind.base.dir="${freedir}" -cp "${CLASSPATH}" freemind.main.FreeMindStarter "$@"
else # non-Sun environments don't work currently.
	_debug "Calling: '${JAVA_CMD} -Dgnu.java.awt.peer.gtk.Graphics=Graphics2D -Dfreemind.base.dir=${freedir} -cp ${CLASSPATH} freemind.main.FreeMindStarter  $@'."
	( echo "${DEBUG}" | grep -qe "exit" ) && exit 0 # do not start FreeMind
	"${JAVA_CMD}" -Xmx256M -Dgnu.java.awt.peer.gtk.Graphics=Graphics2D -Dfreemind.base.dir="${freedir}" -cp "${CLASSPATH}" freemind.main.FreeMindStarter "$@"
fi