Browse Source

Linux launcher can now update itself.


git-svn-id: http://svn.dmdirc.com/trunk@3063 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Shane Mc Cormack 16 years ago
parent
commit
298cddffcb
1 changed files with 146 additions and 18 deletions
  1. 146
    18
      launcher/linux/DMDirc.sh

+ 146
- 18
launcher/linux/DMDirc.sh View File

@@ -23,6 +23,8 @@
23 23
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 24
 # SOFTWARE.
25 25
 
26
+LAUNCHERVERSION="1"
27
+
26 28
 params="${@}"
27 29
 
28 30
 # Check for some CLI params
@@ -37,6 +39,12 @@ while test -n "$1"; do
37 39
 	shift
38 40
 done
39 41
 
42
+ISKDE=`pidof -x -s kdeinit`
43
+KDIALOG=`which kdialog`
44
+KSUDO=`which kdesudo`
45
+ISGNOME=`pidof -x -s gnome-panel`
46
+ZENITY=`which zenity`
47
+GSUDO=`which gksudo`
40 48
 errordialog() {
41 49
 	# Send message to console.
42 50
 	echo ""
@@ -46,11 +54,6 @@ errordialog() {
46 54
 	echo "${2}"
47 55
 	echo "-----------------------------------------------------------------------"
48 56
 
49
-	# Now try to use the GUI Dialogs.
50
-	ISKDE=`pidof -x -s kdeinit`
51
-	KDIALOG=`which kdialog`
52
-	ISGNOME=`pidof -x -s gnome-panel`
53
-	ZENITY=`which zenity`
54 57
 	if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
55 58
 		echo "Dialog on Display: ${DISPLAY}"
56 59
 		${KDIALOG} --title "DMDirc: ${1}" --error "${1}\n\n${2}"
@@ -60,31 +63,156 @@ errordialog() {
60 63
 	fi
61 64
 }
62 65
 
63
-jar=`dirname $0`/DMDirc.jar
66
+messagedialog() {
67
+	# Send message to console.
68
+	echo ""
69
+	echo "-----------------------------------------------------------------------"
70
+	echo "Info: ${1}"
71
+	echo "-----------------------------------------------------------------------"
72
+	echo "${2}"
73
+	echo "-----------------------------------------------------------------------"
74
+
75
+	if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
76
+		echo "Dialog on Display: ${DISPLAY}"
77
+		${KDIALOG} --title "DMDirc: ${1}" --msgbox "${1}\n\n${2}"
78
+	elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
79
+		echo "Dialog on Display: ${DISPLAY}"
80
+		${ZENITY} --info --title "DMDirc: ${1}" --text "${1}\n\n${2}"
81
+	fi
82
+}
64 83
 
84
+jar=`dirname $0`/DMDirc.jar
85
+launcherUpdater=${profiledir}/updateLauncher.sh
65 86
 echo "---------------------"
66 87
 echo "DMDirc - Open Source IRC Client"
88
+echo "Launcher Version: ${LAUNCHERVERSION}"
67 89
 echo "Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes"
68 90
 echo "---------------------"
69
-echo -n "Checking for updates in ${profiledir} - ";
91
+
92
+echo -n "Checking for launcher updates in ${profiledir} - ";
93
+if [ -e "${profiledir}/.launcher.sh.ignore" ]; then
94
+	rm -Rf "${profiledir}/.launcher.sh.ignore"
95
+	echo "Ignoring!";
96
+elif [ -e "${profiledir}/.launcher.sh" ]; then
97
+	echo "Found!";
98
+	echo "Attempting to update..";
99
+
100
+	cat <<EOF> ${launcherUpdater}
101
+		cd `dirname $0`
102
+		errordialog() {
103
+			# Send message to console.
104
+			echo ""
105
+			echo "-----------------------------------------------------------------------"
106
+			echo "Error: \${1}"
107
+			echo "-----------------------------------------------------------------------"
108
+			echo "\${2}"
109
+			echo "-----------------------------------------------------------------------"
110
+
111
+			if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
112
+				echo "Dialog on Display: ${DISPLAY}"
113
+				${KDIALOG} --title "DMDirc: \${1}" --error "\${1}\n\n\${2}"
114
+			elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
115
+				echo "Dialog on Display: ${DISPLAY}"
116
+				${ZENITY} --error --title "DMDirc: \${1}" --text "\${1}\n\n\${2}"
117
+			fi
118
+		}
119
+
120
+		messagedialog() {
121
+			# Send message to console.
122
+			echo ""
123
+			echo "-----------------------------------------------------------------------"
124
+			echo "Info: \${1}"
125
+			echo "----------------------------------------------------------------------"
126
+			echo "\${2}"
127
+			echo "-----------------------------------------------------------------------"
128
+
129
+			if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
130
+				echo "Dialog on Display: ${DISPLAY}"
131
+				${KDIALOG} --title "DMDirc: \${1}" --msgbox "\${1}\n\n\${2}"
132
+			elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
133
+				echo "Dialog on Display: ${DISPLAY}"
134
+				${ZENITY} --info --title "DMDirc: \${1}" --text "\${1}\n\n\${2}"
135
+			fi
136
+		}
137
+
138
+		mv -fv ${profiledir}/.launcher.sh ${0}
139
+		if [ ! -e "${profiledir}/.launcher.sh" ]; then
140
+			echo "Launcher Update successful."
141
+			messagedialog "Launcher Update" "Launcher Update successful"
142
+		else
143
+			if [ "${UID}" = "" ]; then
144
+				UID=`id -u`;
145
+			fi
146
+			if [ "0" != "${UID}" ]; then
147
+				if [ "" != "${ISKDE}" -a "" != "${KSUDO}" -a "" != "${DISPLAY}" ]; then
148
+					echo "Password dialog on ${DISPLAY}"
149
+					${KSUDO} --comment "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.launcher.sh" "${0}"
150
+				elif [ "" != "${ISGNOME}" -a "" != "${GSUDO}" -a "" != "${DISPLAY}" ]; then
151
+					echo "Password dialog on ${DISPLAY}"
152
+					${GSUDO} -k --message "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.launcher.sh" "${0}"
153
+				else
154
+					echo "DMDirc Client Updater requires root access to modify the global installation"
155
+					sudo mv -fv "${profiledir}/.launcher.sh" "${0}"
156
+				fi;
157
+			fi
158
+			if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
159
+				echo "Update successful."
160
+				messagedialog "Launcher Update" "Launcher Update successful"
161
+			else
162
+				echo "Launcher failed."
163
+				errordialog "Launcher Update" "Launcher Update failed, using old version"
164
+				touch ${profiledir}/.launcher.sh.ignore
165
+			fi;
166
+		fi;
167
+		sh ${0} ${params}
168
+EOF
169
+	chmod a+x ${launcherUpdater}
170
+	${launcherUpdater}
171
+	exit 0;
172
+else
173
+	echo "Not found.";
174
+fi;
175
+
176
+if [ -e "${launcherUpdater}" ]; then
177
+	rm -Rf "${launcherUpdater}"
178
+fi;
179
+
180
+echo -n "Checking for client updates in ${profiledir} - ";
70 181
 if [ -e "${profiledir}/.DMDirc.jar" ]; then
71 182
 	echo "Found!";
72 183
 	echo "Attempting to update..";
73 184
 	mv -fv ${profiledir}/.DMDirc.jar ${jar}
74
-	if [ $? -eq 0 ]; then
185
+	if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
75 186
 		echo "Update successful."
187
+		messagedialog "Client Update" "Client Update successful"
76 188
 	else
77
-		echo "Update failed."
189
+		if [ "${UID}" = "" ]; then
190
+			UID=`id -u`;
191
+		fi
192
+		if [ "0" != "${UID}" ]; then
193
+			if [ "" != "${ISKDE}" -a "" != "${KSUDO}" -a "" != "${DISPLAY}" ]; then
194
+				echo "Password dialog on ${DISPLAY}"
195
+				${KSUDO} --comment "DMDirc Client Updater requires root access to modify the global installation" mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
196
+			elif [ "" != "${ISGNOME}" -a "" != "${GSUDO}" -a "" != "${DISPLAY}" ]; then
197
+				echo "Password dialog on ${DISPLAY}"
198
+				${GSUDO} -k --message "DMDirc Client Updater requires root access to modify the global installation" mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
199
+			else
200
+				echo "DMDirc Client Updater requires root access to modify the global installation"
201
+				sudo mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
202
+			fi;
203
+		fi
204
+		if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
205
+			echo "Update successful."
206
+			messagedialog "Client Update" "Client Update successful"
207
+		else
208
+			echo "Update failed."
209
+			errordialog "Client Update" "Client Update failed, using old version"
210
+		fi;
78 211
 	fi
79 212
 else
80 213
 	echo "Not found.";
81 214
 fi;
82 215
 
83
-# Add local jre to path if it exists
84
-if [ -e ~/jre ]; then
85
-	export PATH=~/jre/bin:"${PATH}"
86
-fi;
87
-
88 216
 echo -n "Looking for java - ";
89 217
 JAVA=`which java`
90 218
 
@@ -117,12 +245,12 @@ if [ -e "${jar}" ]; then
117 245
 		errordialog "Unable to launch dmdirc!" "${ERROR}";
118 246
 		exit 1;
119 247
 	fi
120
-	
248
+
121 249
 	# Now we can run the client for real, this allows stderr/stdout output
122 250
 	# to be seen, and the shell script exits with the correct exit code.
123
-	${JAVA} -ea -jar ${jar} ${params}
251
+	${JAVA} -ea -jar ${jar} -l linux-${LAUNCHERVERSION} ${params}
124 252
 	exit $?;
125
-else 
253
+else
126 254
 	echo "Failed.";
127 255
 	errordialog "Unable to launch dmdirc!" "No jar file found";
128
-fi
256
+fi

Loading…
Cancel
Save