[44459] | 1 | ; $Id: VBoxGuestAdditionsExternal.nsh 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
| 2 | ;; @file
|
---|
[69354] | 3 | ; VBoxGuestAdditionExternal.nsh - Utility function for invoking external applications.
|
---|
[44459] | 4 | ;
|
---|
| 5 |
|
---|
| 6 | ;
|
---|
[98103] | 7 | ; Copyright (C) 2013-2023 Oracle and/or its affiliates.
|
---|
[44459] | 8 | ;
|
---|
[96407] | 9 | ; This file is part of VirtualBox base platform packages, as
|
---|
| 10 | ; available from https://www.virtualbox.org.
|
---|
[44459] | 11 | ;
|
---|
[96407] | 12 | ; This program is free software; you can redistribute it and/or
|
---|
| 13 | ; modify it under the terms of the GNU General Public License
|
---|
| 14 | ; as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | ; License.
|
---|
| 16 | ;
|
---|
| 17 | ; This program is distributed in the hope that it will be useful, but
|
---|
| 18 | ; WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | ; General Public License for more details.
|
---|
| 21 | ;
|
---|
| 22 | ; You should have received a copy of the GNU General Public License
|
---|
| 23 | ; along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | ;
|
---|
| 25 | ; SPDX-License-Identifier: GPL-3.0-only
|
---|
| 26 | ;
|
---|
[44459] | 27 |
|
---|
[96686] | 28 | ;;
|
---|
| 29 | ; Macro for executing external applications.
|
---|
[44459] | 30 | ;
|
---|
[96686] | 31 | ; Uses the nsExec plugin in different styles, depending on whether this
|
---|
| 32 | ; installer runs in silent mode or not. If the external program reports an exit
|
---|
| 33 | ; code other than 0 the installer will be aborted.
|
---|
[44459] | 34 | ;
|
---|
[96687] | 35 | ; @param ${cmdline} Command line (full qualified and quoted).
|
---|
| 36 | ; @param ${options} Either 'non-zero-exitcode=log' or 'non-zero-exitcode=abort'.
|
---|
| 37 | ; Controls how to handle non-zero exit codes, in the latter
|
---|
| 38 | ; case they will trigger an installation abort, while in the
|
---|
| 39 | ; form only a warning in the log file.
|
---|
[44459] | 40 | ;
|
---|
[96687] | 41 | !macro _cmdExecute cmdline options
|
---|
[96686] | 42 | ; Save $0 & $1
|
---|
[44459] | 43 | Push $0
|
---|
| 44 | Push $1
|
---|
[44484] | 45 |
|
---|
[96687] | 46 | ; Check that the options are valid.
|
---|
| 47 | ${IfNot} ${options} != "exitcode=0"
|
---|
| 48 | ${AndIfNot} ${options} != "ignore-exitcode"
|
---|
| 49 | Abort "Internal error in _cmdExecute: options=${options} cmdline=${cmdline}"
|
---|
| 50 | ${EndIf}
|
---|
| 51 |
|
---|
[96686] | 52 | ;
|
---|
| 53 | ; Execute the command, putting the exit code in $0 when done.
|
---|
| 54 | ;
|
---|
[44459] | 55 | ${LogVerbose} "Executing: ${cmdline}"
|
---|
[96686] | 56 | ${If} ${Silent}
|
---|
| 57 | nsExec::ExecToStack "${cmdline}"
|
---|
| 58 | Pop $0 ; Return value (exit code)
|
---|
| 59 | Pop $1 ; Stdout/stderr output (up to ${NSIS_MAX_STRLEN})
|
---|
| 60 | ${LogVerbose} "$1"
|
---|
| 61 | ${Else}
|
---|
[44484] | 62 | nsExec::ExecToLog "${cmdline}"
|
---|
[44459] | 63 | Pop $0 ; Return value (exit code)
|
---|
[96686] | 64 | ${EndIf}
|
---|
[44484] | 65 |
|
---|
| 66 | ${LogVerbose} "Execution returned exit code: $0"
|
---|
| 67 |
|
---|
[96686] | 68 | ;
|
---|
| 69 | ; Check if it failed and take action according to the 2nd argument.
|
---|
| 70 | ;
|
---|
| 71 | ${If} $0 <> 0
|
---|
[96687] | 72 | ${If} ${options} == "exitcode=0"
|
---|
[96686] | 73 | ${LogVerbose} "Error excuting $\"${cmdline}$\" (exit code: $0) -- aborting installation"
|
---|
| 74 | Abort "Error excuting $\"${cmdline}$\" (exit code: $0) -- aborting installation"
|
---|
| 75 | ${Else}
|
---|
| 76 | ${LogVerbose} "Warning: Executing $\"${cmdline}$\" returned with exit code $0"
|
---|
| 77 | ${EndIf}
|
---|
[44459] | 78 | ${EndIf}
|
---|
[44484] | 79 |
|
---|
[96686] | 80 | ; Restore $0 and $1.
|
---|
[44459] | 81 | Pop $1
|
---|
| 82 | Pop $0
|
---|
| 83 | !macroend
|
---|
| 84 | !define CmdExecute "!insertmacro _cmdExecute"
|
---|