Changeset View
Changeset View
Standalone View
Standalone View
src/settings/services/servicemenuinstaller/servicemenuinstaller.cpp
Show First 20 Lines • Show All 151 Lines • ▼ Show 20 Line(s) | 151 | { | |||
---|---|---|---|---|---|
152 | QDirIterator it(dir, QStringList{basename}, QDir::Files, QDirIterator::Subdirectories); | 152 | QDirIterator it(dir, QStringList{basename}, QDir::Files, QDirIterator::Subdirectories); | ||
153 | while (it.hasNext()) { | 153 | while (it.hasNext()) { | ||
154 | return QFileInfo(it.next()).canonicalFilePath(); | 154 | return QFileInfo(it.next()).canonicalFilePath(); | ||
155 | } | 155 | } | ||
156 | 156 | | |||
157 | return QString(); | 157 | return QString(); | ||
158 | } | 158 | } | ||
159 | 159 | | |||
160 | bool runInstallerScriptOnce(const QString &path, const QStringList &args, const QString &dir) | 160 | bool runInstallerScriptOnce(const QString &path, const QStringList &args) | ||
161 | { | 161 | { | ||
162 | QProcess process; | 162 | QProcess process; | ||
163 | process.setWorkingDirectory(dir); | 163 | process.setWorkingDirectory(QFileInfo(path).absolutePath()); | ||
164 | | ||||
164 | process.start(path, args, QIODevice::NotOpen); | 165 | process.start(path, args, QIODevice::NotOpen); | ||
165 | if (!process.waitForStarted()) { | 166 | if (!process.waitForStarted()) { | ||
166 | fail(i18n("Failed to run installer script %1", path)); | 167 | fail(i18n("Failed to run installer script %1", path)); | ||
167 | } | 168 | } | ||
168 | 169 | | |||
169 | // Wait until installer exits, without timeout | 170 | // Wait until installer exits, without timeout | ||
170 | if (!process.waitForFinished(-1)) { | 171 | if (!process.waitForFinished(-1)) { | ||
171 | qWarning() << "Failed to wait on installer:" << process.program() << process.arguments().join(" "); | 172 | qWarning() << "Failed to wait on installer:" << process.program() << process.arguments().join(" "); | ||
172 | return false; | 173 | return false; | ||
173 | } | 174 | } | ||
174 | 175 | | |||
175 | if (process.exitStatus() != QProcess::NormalExit || process.exitCode() != 0) { | 176 | if (process.exitStatus() != QProcess::NormalExit || process.exitCode() != 0) { | ||
176 | qWarning() << "Installer script exited with error:" << process.program() << process.arguments().join(" "); | 177 | qWarning() << "Installer script exited with error:" << process.program() << process.arguments().join(" "); | ||
177 | return false; | 178 | return false; | ||
178 | } | 179 | } | ||
179 | 180 | | |||
180 | return true; | 181 | return true; | ||
181 | } | 182 | } | ||
182 | 183 | | |||
183 | // If hasArgVariants is true, run "path". | 184 | // If hasArgVariants is true, run "path". | ||
184 | // If hasArgVariants is false, run "path argVariants[i]" until successful. | 185 | // If hasArgVariants is false, run "path argVariants[i]" until successful. | ||
185 | bool runInstallerScript(const QString &path, bool hasArgVariants, const QStringList &argVariants, const QString &dir, | 186 | bool runInstallerScript(const QString &path, bool hasArgVariants, const QStringList &argVariants, QString &errorText) | ||
186 | QString &errorText) | | |||
187 | { | 187 | { | ||
188 | QFile file(path); | 188 | QFile file(path); | ||
189 | if (!file.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner)) { | 189 | if (!file.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner)) { | ||
190 | errorText = i18n("Failed to set permissions on %1: %2", path, file.errorString()); | 190 | errorText = i18n("Failed to set permissions on %1: %2", path, file.errorString()); | ||
191 | return false; | 191 | return false; | ||
192 | } | 192 | } | ||
193 | 193 | | |||
194 | qInfo() << "[servicemenuinstaller]: Trying to run installer/uninstaller" << path; | 194 | qInfo() << "[servicemenuinstaller]: Trying to run installer/uninstaller" << path; | ||
195 | if (hasArgVariants) { | 195 | if (hasArgVariants) { | ||
196 | for (const auto &arg : argVariants) { | 196 | for (const auto &arg : argVariants) { | ||
197 | if (runInstallerScriptOnce(path, QStringList{arg}, dir)) { | 197 | if (runInstallerScriptOnce(path, QStringList{arg})) { | ||
198 | return true; | 198 | return true; | ||
199 | } | 199 | } | ||
200 | } | 200 | } | ||
201 | } else { | 201 | } else { | ||
202 | if (runInstallerScriptOnce(path, QStringList{}, dir)) { | 202 | if (runInstallerScriptOnce(path, QStringList{})) { | ||
203 | return true; | 203 | return true; | ||
204 | } | 204 | } | ||
205 | } | 205 | } | ||
206 | 206 | | |||
207 | errorText = i18nc( | 207 | errorText = i18nc( | ||
208 | "%1 = comma separated list of arguments", | 208 | "%1 = comma separated list of arguments", | ||
209 | "Installer script %1 failed, tried arguments \"%1\".", path, argVariants.join(i18nc("Separator between arguments", "\", \""))); | 209 | "Installer script %1 failed, tried arguments \"%1\".", path, argVariants.join(i18nc("Separator between arguments", "\", \""))); | ||
210 | return false; | 210 | return false; | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 255 | for (const auto &basename : qAsConst(basenames1)) { | |||
256 | const auto path = findRecursive(dir, basename); | 256 | const auto path = findRecursive(dir, basename); | ||
257 | if (!path.isEmpty()) { | 257 | if (!path.isEmpty()) { | ||
258 | installItPath = path; | 258 | installItPath = path; | ||
259 | break; | 259 | break; | ||
260 | } | 260 | } | ||
261 | } | 261 | } | ||
262 | 262 | | |||
263 | if (!installItPath.isEmpty()) { | 263 | if (!installItPath.isEmpty()) { | ||
264 | return runInstallerScript(installItPath, false, QStringList{}, dir, errorText); | 264 | return runInstallerScript(installItPath, false, QStringList{}, errorText); | ||
265 | } | 265 | } | ||
266 | 266 | | |||
267 | // If "install-it" is missing, try "install" | 267 | // If "install-it" is missing, try "install" | ||
268 | QString installerPath; | 268 | QString installerPath; | ||
269 | const auto basenames2 = QStringList{"installKDE4.sh", "installKDE4", "install.sh", "install"}; | 269 | const auto basenames2 = QStringList{"installKDE4.sh", "installKDE4", "install.sh", "install"}; | ||
270 | for (const auto &basename : qAsConst(basenames2)) { | 270 | for (const auto &basename : qAsConst(basenames2)) { | ||
271 | const auto path = findRecursive(dir, basename); | 271 | const auto path = findRecursive(dir, basename); | ||
272 | if (!path.isEmpty()) { | 272 | if (!path.isEmpty()) { | ||
273 | installerPath = path; | 273 | installerPath = path; | ||
274 | break; | 274 | break; | ||
275 | } | 275 | } | ||
276 | } | 276 | } | ||
277 | 277 | | |||
278 | if (!installerPath.isEmpty()) { | 278 | if (!installerPath.isEmpty()) { | ||
279 | return runInstallerScript(installerPath, true, QStringList{"--local", "--local-install", "--install"}, dir, errorText); | 279 | return runInstallerScript(installerPath, true, QStringList{"--local", "--local-install", "--install"}, errorText); | ||
280 | } | 280 | } | ||
281 | 281 | | |||
282 | fail(i18n("Failed to find an installation script in %1", dir)); | 282 | fail(i18n("Failed to find an installation script in %1", dir)); | ||
283 | } | 283 | } | ||
284 | 284 | | |||
285 | return true; | 285 | return true; | ||
286 | } | 286 | } | ||
287 | 287 | | |||
Show All 18 Lines | 305 | for (const auto &basename : qAsConst(basenames1)) { | |||
306 | const auto path = findRecursive(dir, basename); | 306 | const auto path = findRecursive(dir, basename); | ||
307 | if (!path.isEmpty()) { | 307 | if (!path.isEmpty()) { | ||
308 | deinstallPath = path; | 308 | deinstallPath = path; | ||
309 | break; | 309 | break; | ||
310 | } | 310 | } | ||
311 | } | 311 | } | ||
312 | 312 | | |||
313 | if (!deinstallPath.isEmpty()) { | 313 | if (!deinstallPath.isEmpty()) { | ||
314 | bool ok = runInstallerScript(deinstallPath, false, QStringList{}, dir, errorText); | 314 | bool ok = runInstallerScript(deinstallPath, false, QStringList{}, errorText); | ||
315 | if (!ok) { | 315 | if (!ok) { | ||
316 | return ok; | 316 | return ok; | ||
317 | } | 317 | } | ||
318 | } else { | 318 | } else { | ||
319 | // If "deinstall" is missing, try "install --uninstall" | 319 | // If "deinstall" is missing, try "install --uninstall" | ||
320 | 320 | | |||
321 | QString installerPath; | 321 | QString installerPath; | ||
322 | const auto basenames2 = QStringList{"install-it.sh", "install-it", "installKDE4.sh", | 322 | const auto basenames2 = QStringList{"install-it.sh", "install-it", "installKDE4.sh", | ||
323 | "installKDE4", "install.sh", "install"}; | 323 | "installKDE4", "install.sh", "install"}; | ||
324 | for (const auto &basename : qAsConst(basenames2)) { | 324 | for (const auto &basename : qAsConst(basenames2)) { | ||
325 | const auto path = findRecursive(dir, basename); | 325 | const auto path = findRecursive(dir, basename); | ||
326 | if (!path.isEmpty()) { | 326 | if (!path.isEmpty()) { | ||
327 | installerPath = path; | 327 | installerPath = path; | ||
328 | break; | 328 | break; | ||
329 | } | 329 | } | ||
330 | } | 330 | } | ||
331 | 331 | | |||
332 | if (!installerPath.isEmpty()) { | 332 | if (!installerPath.isEmpty()) { | ||
333 | bool ok = runInstallerScript( | 333 | bool ok = runInstallerScript( | ||
334 | installerPath, true, QStringList{"--remove", "--delete", "--uninstall", "--deinstall"}, dir, errorText); | 334 | installerPath, true, QStringList{"--remove", "--delete", "--uninstall", "--deinstall"}, errorText); | ||
335 | if (!ok) { | 335 | if (!ok) { | ||
336 | return ok; | 336 | return ok; | ||
337 | } | 337 | } | ||
338 | } else { | 338 | } else { | ||
339 | fail(i18n("Failed to find an uninstallation script in %1", dir)); | 339 | fail(i18n("Failed to find an uninstallation script in %1", dir)); | ||
340 | } | 340 | } | ||
341 | } | 341 | } | ||
342 | 342 | | |||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |