Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d27792975e
|
||
|
|
c23308f78e
|
@@ -579,18 +579,26 @@ QString UpdateManager::stagedInstallScript() {
|
|||||||
// Install command: the action runs in a child `sh` (so it may be a compound
|
// Install command: the action runs in a child `sh` (so it may be a compound
|
||||||
// command and expands the exported paths), through sudo when a password was
|
// command and expands the exported paths), through sudo when a password was
|
||||||
// provided or the target directory is not writable.
|
// provided or the target directory is not writable.
|
||||||
|
//
|
||||||
|
// The paths are handed to the child through `env` because sudo resets the
|
||||||
|
// environment (env_reset, the default): the exports from the prologue would be
|
||||||
|
// dropped and the install script would run `mkdir -p ""` on a system-wide
|
||||||
|
// install (/usr/bin and the like). They are expanded by the unprivileged shell
|
||||||
|
// that still has them, since the action itself is single-quoted.
|
||||||
QString UpdateManager::installCommand(const QString& quotedPassword,
|
QString UpdateManager::installCommand(const QString& quotedPassword,
|
||||||
const QString& action) const {
|
const QString& action) const {
|
||||||
const QString quotedAction = quoteShell(action);
|
const QString quotedAction = quoteShell(action);
|
||||||
|
const QString passThrough = QStringLiteral(
|
||||||
|
"env BIN_DIR=\"$BIN_DIR\" STAGE=\"$STAGE\" APP_VERSION=\"$APP_VERSION\"");
|
||||||
if (!quotedPassword.isEmpty()) {
|
if (!quotedPassword.isEmpty()) {
|
||||||
// NOTE: single %s — QString::arg() only substitutes %1..%99.
|
// NOTE: single %s — QString::arg() only substitutes %1..%99.
|
||||||
return QStringLiteral("printf '%s\\n' %1 | sudo -S sh -c %2 2>&1\n")
|
return QStringLiteral("printf '%s\\n' %1 | sudo -S %2 sh -c %3 2>&1\n")
|
||||||
.arg(quotedPassword, quotedAction);
|
.arg(quotedPassword, passThrough, quotedAction);
|
||||||
}
|
}
|
||||||
if (QFileInfo(binDir()).isWritable()) {
|
if (QFileInfo(binDir()).isWritable()) {
|
||||||
return QStringLiteral("sh -c %1 2>&1\n").arg(quotedAction);
|
return QStringLiteral("sh -c %1 2>&1\n").arg(quotedAction);
|
||||||
}
|
}
|
||||||
return QStringLiteral("sudo sh -c %1 2>&1\n").arg(quotedAction);
|
return QStringLiteral("sudo %1 sh -c %2 2>&1\n").arg(passThrough, quotedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString UpdateManager::quotedBinDir() const {
|
QString UpdateManager::quotedBinDir() const {
|
||||||
|
|||||||
Reference in new issue
Block a user