Browse Source

Work without `bc` (fixes issue 3566)

When installing the JRE, show a pulsating progress bar if possible (gnome) else just show a "Please wait..." rather than showing nothing. (Fixes issue 1742)

Change-Id: Icd1aac2972371880362d2938ff350af4182dba36
Reviewed-on: http://gerrit.dmdirc.com/561
Automatic-Compile: Chris Smith <chris@dmdirc.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.3b1
Shane Mc Cormack 14 years ago
parent
commit
0f0afd95d1
3 changed files with 77 additions and 20 deletions
  1. 7
    3
      installer/linux/getjre.sh
  2. 13
    6
      installer/linux/installjre.sh
  3. 57
    11
      installer/linux/progressbar.sh

+ 7
- 3
installer/linux/getjre.sh View File

69
 	length=`${CURL} -# -I ${URL} 2>&1 | grep "Content-Length:"| awk '{print $2}'`
69
 	length=`${CURL} -# -I ${URL} 2>&1 | grep "Content-Length:"| awk '{print $2}'`
70
 fi;
70
 fi;
71
 
71
 
72
-# Convert the length from Bytes to something user-friendly
73
-if [ ${actualLength} -ge 1048576 ]; then
72
+# Convert the length from Bytes to something user-friendly is possible.
73
+BC=`which bc`
74
+if [ "${BC}" = "" ]; then
75
+	niceLength=${actualLength}"B"
76
+elif [ ${actualLength} -ge 1048576 ]; then
74
 	niceLength=`echo "scale=2; ${actualLength}/1048576" | bc`"MB"
77
 	niceLength=`echo "scale=2; ${actualLength}/1048576" | bc`"MB"
75
 elif [ ${actualLength} -ge 1024 ]; then
78
 elif [ ${actualLength} -ge 1024 ]; then
76
 	niceLength=`echo "scale=2; ${actualLength}/1024" | bc`"KB"
79
 	niceLength=`echo "scale=2; ${actualLength}/1024" | bc`"KB"
77
 else
80
 else
78
-	niceLength=`echo "scale=2; ${actualLength}/1024" | bc`"B"
81
+	niceLength=`echo "scale=2; ${actualLength}" | bc`"B"
79
 fi;
82
 fi;
80
 
83
 
81
 if [ "${actualLength}" = "6" ]; then
84
 if [ "${actualLength}" = "6" ]; then
132
 			exit 1;
135
 			exit 1;
133
 		fi;
136
 		fi;
134
 	done;
137
 	done;
138
+	/bin/sh ${PWD}/progressbar.sh --watchdog ${progressbarpid}
135
 	wgetpid=""
139
 	wgetpid=""
136
 	if [ "${ISFREEBSD}" != "" -o "${ISAINFO}" != "" ]; then
140
 	if [ "${ISFREEBSD}" != "" -o "${ISAINFO}" != "" ]; then
137
 		echo "Killing progressbar"
141
 		echo "Killing progressbar"

+ 13
- 6
installer/linux/installjre.sh View File

161
 			STARTLINE=${STARTLINE%%:*}
161
 			STARTLINE=${STARTLINE%%:*}
162
 			# Location of license end
162
 			# Location of license end
163
 			ENDLINE=`grep ${GREPOPTS} "Do you agree to the above license terms?" jre.bin`
163
 			ENDLINE=`grep ${GREPOPTS} "Do you agree to the above license terms?" jre.bin`
164
-			ENDLINE=$((${ENDLINE%%:*} - 4))
164
+			ENDLINE=$((${ENDLINE%%:*} - 2))
165
 			# Location of checksum start
165
 			# Location of checksum start
166
 			CSSTARTLINE=`grep ${GREPOPTS} "^if \[ -x /usr/bin/sum \]; then$" jre.bin`
166
 			CSSTARTLINE=`grep ${GREPOPTS} "^if \[ -x /usr/bin/sum \]; then$" jre.bin`
167
 			CSSTARTLINE=${CSSTARTLINE%%:*}
167
 			CSSTARTLINE=${CSSTARTLINE%%:*}
176
 			tail ${TAILOPTS}$((${ENDLINE})) jre.bin | head -n $((${CSSTARTLINE} -1 - ${ENDLINE})) >> jre.bin.tmp
176
 			tail ${TAILOPTS}$((${ENDLINE})) jre.bin | head -n $((${CSSTARTLINE} -1 - ${ENDLINE})) >> jre.bin.tmp
177
 			echo "tail \${tail_args} +${SCENDLINE} \"\$0\" > \$outname" >> jre.bin.tmp
177
 			echo "tail \${tail_args} +${SCENDLINE} \"\$0\" > \$outname" >> jre.bin.tmp
178
 			tail ${TAILOPTS}$((${CSENDLINE})) jre.bin >> jre.bin.tmp
178
 			tail ${TAILOPTS}$((${CSENDLINE})) jre.bin >> jre.bin.tmp
179
-		
180
-			yes | sh jre.bin.tmp
181
-			rm -Rf jre.bin.tmp
179
+
180
+			PIPE=`mktemp installprogresspipe.XXXXXXXXXXXXXX`
181
+			/bin/sh ${PWD}/progressbar.sh --pulsate "Installing JRE. Please wait.." 100 ${PIPE} &
182
+			sleep 1;
183
+			echo "-1" > ${PIPE}
184
+			# This is supposed to write to the pipe as it does stuff, but it appears
185
+			# not to work properly.
186
+			yes | sh jre.bin.tmp | egrep --line-buffered -i "(extracting|inflating):" > ${PIPE};
187
+			echo "quit" > ${PIPE}
188
+			# rm -Rf jre.bin.tmp
182
 		fi;
189
 		fi;
183
 		
190
 		
184
 		mv ${JREJAVAHOME} ${installdir}
191
 		mv ${JREJAVAHOME} ${installdir}
185
-		
192
+
186
 		if [ "0" = "${UID}" ]; then
193
 		if [ "0" = "${UID}" ]; then
187
 			# Add to global path.
194
 			# Add to global path.
188
 			if [ -e "/usr/bin/java" ]; then
195
 			if [ -e "/usr/bin/java" ]; then
229
 else
236
 else
230
 	errordialog "Java Install" "You must agree to the license before java can be installed"
237
 	errordialog "Java Install" "You must agree to the license before java can be installed"
231
 fi;
238
 fi;
232
-exit 1;
239
+exit 1;

+ 57
- 11
installer/linux/progressbar.sh View File

65
 QDBUS=`which qdbus`
65
 QDBUS=`which qdbus`
66
 DBUSSEND=`which dbus-send`
66
 DBUSSEND=`which dbus-send`
67
 DCOP=`which dcop`
67
 DCOP=`which dcop`
68
+BC=`which bc`
68
 KDETYPE=""
69
 KDETYPE=""
69
 if [ "${ISKDE}" != "" -o "${ZENITY}" = "" ]; then
70
 if [ "${ISKDE}" != "" -o "${ZENITY}" = "" ]; then
70
 	# Check to see if we have the dcop or dbus binaries needed..
71
 	# Check to see if we have the dcop or dbus binaries needed..
99
 	exit 1;
100
 	exit 1;
100
 fi;
101
 fi;
101
 
102
 
103
+if [ "${1}" = "--pulsate" ]; then
104
+	shift;
105
+	PULSATE="1"
106
+else
107
+	PULSATE="0"
108
+fi;
109
+
102
 CAPTION=${1}
110
 CAPTION=${1}
103
 FILESIZE=${2}
111
 FILESIZE=${2}
104
-WGETPID=${3}
112
+WGETPID=${4}
105
 progresswindow=""
113
 progresswindow=""
106
 TYPE=""
114
 TYPE=""
107
 PIPE="progresspipe_${$}"
115
 PIPE="progresspipe_${$}"
125
 				break;
133
 				break;
126
 			fi;
134
 			fi;
127
 		fi;
135
 		fi;
136
+		
128
 		input=`cat "${PIPE}" | tail ${TAILOPTS}1`
137
 		input=`cat "${PIPE}" | tail ${TAILOPTS}1`
129
 		if [ "${input}" = "quit" ]; then
138
 		if [ "${input}" = "quit" ]; then
130
 			break;
139
 			break;
131
 		elif [ "${input}" != "" ]; then
140
 		elif [ "${input}" != "" ]; then
132
 			data=${input}
141
 			data=${input}
133
 			input=""
142
 			input=""
134
-			res=`echo "scale=4 ; (${data}/${FILESIZE})*100" | bc`
135
-			val=${res%%.*}
136
-			if [ "${val}" = "" ]; then
137
-				val=0
143
+			if [ "${PULSATE}" = "1" ]; then
144
+				val=-1
145
+				
146
+				if [ "${data}" != "-1" ]; then
147
+					if [ "${TYPE}" = "KDE" ]; then
148
+						if [ "${KDETYPE}" = "dcop" ]; then
149
+							${DCOP} ${progresswindow} setLabelText "${data}"
150
+						elif [ "${KDETYPE}" = "qdbus" ]; then
151
+							${QDBUS} ${progresswindow} org.kde.kdialog.ProgressDialog.setLabelText "${data}"
152
+						elif [ "${KDETYPE}" = "dbussend" ]; then
153
+							${DBUSSEND} --print-reply --dest=${progresswindow} org.kde.kdialog.ProgressDialog.setLabelText "string:\'${data}\'" > /dev/null
154
+						fi;
155
+					elif [ "${TYPE}" = "GNOME" ]; then
156
+						echo "${data}" | sed 's/^/# /g'
157
+					else
158
+						echo "${data}"
159
+					fi;
160
+				fi;
161
+				
162
+			else
163
+				if [ "${BC}" != "" ]; then
164
+					res=`echo "scale=4 ; (${data}/${FILESIZE})*100" | bc`;
165
+				else
166
+					# Note, this will return 0 or 100, nothing else, better than spamming
167
+					# errors and never closing tho.
168
+					res=`echo $(( (${data}/${FILESIZE})*100 ))`;
169
+				fi;
170
+				val=${res%%.*}
171
+				if [ "${val}" = "" ]; then
172
+					val=0
173
+				fi;
138
 			fi;
174
 			fi;
139
 			if [ "${TYPE}" = "KDE" ]; then
175
 			if [ "${TYPE}" = "KDE" ]; then
140
 				if [ "${KDETYPE}" = "dcop" ]; then
176
 				if [ "${KDETYPE}" = "dcop" ]; then
161
 					echo "-> "${val}"%"
197
 					echo "-> "${val}"%"
162
 				fi;
198
 				fi;
163
 			fi;
199
 			fi;
200
+			echo "Val: ${val}";
164
 			if [ "${val}" = "100" ]; then
201
 			if [ "${val}" = "100" ]; then
165
 				retval="0"
202
 				retval="0"
166
 				CONTINUE="0"
203
 				CONTINUE="0"
206
 	fi;
243
 	fi;
207
 	echo "Exiting with value: $retval"
244
 	echo "Exiting with value: $retval"
208
 	if [ "${WGETPID}" != "" ]; then
245
 	if [ "${WGETPID}" != "" ]; then
209
-		echo "Attempting to kill wget"
246
+		echo "Attempting to kill wget (${WGETPID})"
210
 		kill -9 ${WGETPID}
247
 		kill -9 ${WGETPID}
211
 	fi;
248
 	fi;
212
 	
249
 	
244
 if [ "" != "${KDIALOG}" -a "" != "${DISPLAY}" -a "" = "${ISGNOME}" -a "${USEKDIALOG}" = "1" ]; then
281
 if [ "" != "${KDIALOG}" -a "" != "${DISPLAY}" -a "" = "${ISGNOME}" -a "${USEKDIALOG}" = "1" ]; then
245
 	echo "Progress dialog on Display: ${DISPLAY}"
282
 	echo "Progress dialog on Display: ${DISPLAY}"
246
 	progresswindow=`${KDIALOG} --title "DMDirc: ${CAPTION}" --progressbar "${CAPTION}" 100`
283
 	progresswindow=`${KDIALOG} --title "DMDirc: ${CAPTION}" --progressbar "${CAPTION}" 100`
284
+	if [ "${PULSATE}" = "1" ]; then
285
+		SHOWCANCEL="false"
286
+	else
287
+		SHOWCANCEL="true"
288
+	fi;
247
 	if [ "${KDETYPE}" = "dcop" ]; then
289
 	if [ "${KDETYPE}" = "dcop" ]; then
248
 		${DCOP} ${progresswindow} setAutoClose true
290
 		${DCOP} ${progresswindow} setAutoClose true
249
-		${DCOP} ${progresswindow} showCancelButton true
291
+		${DCOP} ${progresswindow} showCancelButton ${SHOWCANCEL}
250
 	elif [ "${KDETYPE}" = "qdbus" ]; then
292
 	elif [ "${KDETYPE}" = "qdbus" ]; then
251
 		${QDBUS} ${progresswindow} org.freedesktop.DBus.Properties.Set org.kde.kdialog.ProgressDialog autoClose true
293
 		${QDBUS} ${progresswindow} org.freedesktop.DBus.Properties.Set org.kde.kdialog.ProgressDialog autoClose true
252
-		${QDBUS} ${progresswindow} org.kde.kdialog.ProgressDialog.showCancelButton true
294
+		${QDBUS} ${progresswindow} org.kde.kdialog.ProgressDialog.showCancelButton ${SHOWCANCEL}
253
 	elif [ "${KDETYPE}" = "dbussend" ]; then
295
 	elif [ "${KDETYPE}" = "dbussend" ]; then
254
-		${DBUSSEND} --print-reply --dest=${progresswindow} org.kde.kdialog.ProgressDialog.showCancelButton boolean:true >/dev/null
296
+		${DBUSSEND} --print-reply --dest=${progresswindow} org.kde.kdialog.ProgressDialog.showCancelButton boolean:${SHOWCANCEL} >/dev/null
255
 		${DBUSSEND} --print-reply --dest=${progresswindow} org.freedesktop.DBus.Properties.Set string:'org.kde.kdialog.ProgressDialog' string:'autoClose' variant:boolean:true > /dev/null
297
 		${DBUSSEND} --print-reply --dest=${progresswindow} org.freedesktop.DBus.Properties.Set string:'org.kde.kdialog.ProgressDialog' string:'autoClose' variant:boolean:true > /dev/null
256
 	fi;
298
 	fi;
257
 	TYPE="KDE"
299
 	TYPE="KDE"
258
 	readprogress
300
 	readprogress
259
 	CONTINUE="0"
301
 	CONTINUE="0"
260
 	echo "Progress Bar Complete"
302
 	echo "Progress Bar Complete"
261
-elif [ "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
303
+elif [ "" ! "${ZENITY}" -a "" != "${DISPLAY}" ]; then
262
 	# Else, if zenity exists and we have a display
304
 	# Else, if zenity exists and we have a display
263
 	echo "Progress dialog on Display: ${DISPLAY}"
305
 	echo "Progress dialog on Display: ${DISPLAY}"
264
 	TYPE="GNOME"
306
 	TYPE="GNOME"
265
-	readprogress | ${ZENITY} --progress --auto-close --auto-kill --title "DMDirc: ${CAPTION}" --text "${CAPTION}"
307
+	if [ "${PULSATE}" = "1" ]; then
308
+		readprogress | ${ZENITY} --progress --pulsate --auto-close --title "DMDirc: ${CAPTION}" --text "${CAPTION}"
309
+	else
310
+		readprogress | ${ZENITY} --progress --auto-close --auto-kill --title "DMDirc: ${CAPTION}" --text "${CAPTION}"
311
+	fi;
266
 	CONTINUE="0"
312
 	CONTINUE="0"
267
 	echo "Progress Bar Complete"
313
 	echo "Progress Bar Complete"
268
 else
314
 else

Loading…
Cancel
Save