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,13 +69,16 @@ elif [ "${CURL}" != "" ]; then
69 69
 	length=`${CURL} -# -I ${URL} 2>&1 | grep "Content-Length:"| awk '{print $2}'`
70 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 77
 	niceLength=`echo "scale=2; ${actualLength}/1048576" | bc`"MB"
75 78
 elif [ ${actualLength} -ge 1024 ]; then
76 79
 	niceLength=`echo "scale=2; ${actualLength}/1024" | bc`"KB"
77 80
 else
78
-	niceLength=`echo "scale=2; ${actualLength}/1024" | bc`"B"
81
+	niceLength=`echo "scale=2; ${actualLength}" | bc`"B"
79 82
 fi;
80 83
 
81 84
 if [ "${actualLength}" = "6" ]; then
@@ -132,6 +135,7 @@ if [ $result -eq 0 ]; then
132 135
 			exit 1;
133 136
 		fi;
134 137
 	done;
138
+	/bin/sh ${PWD}/progressbar.sh --watchdog ${progressbarpid}
135 139
 	wgetpid=""
136 140
 	if [ "${ISFREEBSD}" != "" -o "${ISAINFO}" != "" ]; then
137 141
 		echo "Killing progressbar"

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

@@ -161,7 +161,7 @@ if [ $? -eq 0 ]; then
161 161
 			STARTLINE=${STARTLINE%%:*}
162 162
 			# Location of license end
163 163
 			ENDLINE=`grep ${GREPOPTS} "Do you agree to the above license terms?" jre.bin`
164
-			ENDLINE=$((${ENDLINE%%:*} - 4))
164
+			ENDLINE=$((${ENDLINE%%:*} - 2))
165 165
 			# Location of checksum start
166 166
 			CSSTARTLINE=`grep ${GREPOPTS} "^if \[ -x /usr/bin/sum \]; then$" jre.bin`
167 167
 			CSSTARTLINE=${CSSTARTLINE%%:*}
@@ -176,13 +176,20 @@ if [ $? -eq 0 ]; then
176 176
 			tail ${TAILOPTS}$((${ENDLINE})) jre.bin | head -n $((${CSSTARTLINE} -1 - ${ENDLINE})) >> jre.bin.tmp
177 177
 			echo "tail \${tail_args} +${SCENDLINE} \"\$0\" > \$outname" >> jre.bin.tmp
178 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 189
 		fi;
183 190
 		
184 191
 		mv ${JREJAVAHOME} ${installdir}
185
-		
192
+
186 193
 		if [ "0" = "${UID}" ]; then
187 194
 			# Add to global path.
188 195
 			if [ -e "/usr/bin/java" ]; then
@@ -229,4 +236,4 @@ if [ $? -eq 0 ]; then
229 236
 else
230 237
 	errordialog "Java Install" "You must agree to the license before java can be installed"
231 238
 fi;
232
-exit 1;
239
+exit 1;

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

@@ -65,6 +65,7 @@ USEKDIALOG="0";
65 65
 QDBUS=`which qdbus`
66 66
 DBUSSEND=`which dbus-send`
67 67
 DCOP=`which dcop`
68
+BC=`which bc`
68 69
 KDETYPE=""
69 70
 if [ "${ISKDE}" != "" -o "${ZENITY}" = "" ]; then
70 71
 	# Check to see if we have the dcop or dbus binaries needed..
@@ -99,9 +100,16 @@ if [ "${1}" = "--watchdog" ]; then
99 100
 	exit 1;
100 101
 fi;
101 102
 
103
+if [ "${1}" = "--pulsate" ]; then
104
+	shift;
105
+	PULSATE="1"
106
+else
107
+	PULSATE="0"
108
+fi;
109
+
102 110
 CAPTION=${1}
103 111
 FILESIZE=${2}
104
-WGETPID=${3}
112
+WGETPID=${4}
105 113
 progresswindow=""
106 114
 TYPE=""
107 115
 PIPE="progresspipe_${$}"
@@ -125,16 +133,44 @@ readprogress() {
125 133
 				break;
126 134
 			fi;
127 135
 		fi;
136
+		
128 137
 		input=`cat "${PIPE}" | tail ${TAILOPTS}1`
129 138
 		if [ "${input}" = "quit" ]; then
130 139
 			break;
131 140
 		elif [ "${input}" != "" ]; then
132 141
 			data=${input}
133 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 174
 			fi;
139 175
 			if [ "${TYPE}" = "KDE" ]; then
140 176
 				if [ "${KDETYPE}" = "dcop" ]; then
@@ -161,6 +197,7 @@ readprogress() {
161 197
 					echo "-> "${val}"%"
162 198
 				fi;
163 199
 			fi;
200
+			echo "Val: ${val}";
164 201
 			if [ "${val}" = "100" ]; then
165 202
 				retval="0"
166 203
 				CONTINUE="0"
@@ -206,7 +243,7 @@ closeProgress() {
206 243
 	fi;
207 244
 	echo "Exiting with value: $retval"
208 245
 	if [ "${WGETPID}" != "" ]; then
209
-		echo "Attempting to kill wget"
246
+		echo "Attempting to kill wget (${WGETPID})"
210 247
 		kill -9 ${WGETPID}
211 248
 	fi;
212 249
 	
@@ -244,25 +281,34 @@ trap 'closeProgress' INT TERM EXIT
244 281
 if [ "" != "${KDIALOG}" -a "" != "${DISPLAY}" -a "" = "${ISGNOME}" -a "${USEKDIALOG}" = "1" ]; then
245 282
 	echo "Progress dialog on Display: ${DISPLAY}"
246 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 289
 	if [ "${KDETYPE}" = "dcop" ]; then
248 290
 		${DCOP} ${progresswindow} setAutoClose true
249
-		${DCOP} ${progresswindow} showCancelButton true
291
+		${DCOP} ${progresswindow} showCancelButton ${SHOWCANCEL}
250 292
 	elif [ "${KDETYPE}" = "qdbus" ]; then
251 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 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 297
 		${DBUSSEND} --print-reply --dest=${progresswindow} org.freedesktop.DBus.Properties.Set string:'org.kde.kdialog.ProgressDialog' string:'autoClose' variant:boolean:true > /dev/null
256 298
 	fi;
257 299
 	TYPE="KDE"
258 300
 	readprogress
259 301
 	CONTINUE="0"
260 302
 	echo "Progress Bar Complete"
261
-elif [ "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
303
+elif [ "" ! "${ZENITY}" -a "" != "${DISPLAY}" ]; then
262 304
 	# Else, if zenity exists and we have a display
263 305
 	echo "Progress dialog on Display: ${DISPLAY}"
264 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 312
 	CONTINUE="0"
267 313
 	echo "Progress Bar Complete"
268 314
 else

Loading…
Cancel
Save