1 Commits

Author SHA1 Message Date
Søren Theilgaard
b42bd7e408 Trapping the script
Using these signals:
```
SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM SIGTSTP
```

Fixed #272
2022-02-08 13:11:08 +01:00
4 changed files with 21 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
## v10
- Now we trap the script, so if it is cancelled, we will run cleanupAndExit anyway, and have mounted diskimages unmounted and temporary files and folders removed.
-
## v9

View File

@@ -1,4 +1,9 @@
# MARK: check minimal macOS requirement
# MARK: 3 Arguments
# Start trapping the script
trap_with_arg func_trap SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM SIGTSTP
# check minimal macOS requirement
autoload is-at-least
installedOSversion=$(sw_vers -productVersion)
@@ -125,4 +130,4 @@ valuesfromarguments)
fi
;;
# label descriptions start here
# Mark: label descriptions start here

View File

@@ -1,4 +1,4 @@
# MARK: Functions
# MARK: 2 Functions
cleanupAndExit() { # $1 = exit code, $2 message, $3 level
if [ -n "$dmgmount" ]; then
@@ -29,6 +29,17 @@ cleanupAndExit() { # $1 = exit code, $2 message, $3 level
exit "$1"
}
# Two functions to trap the script
trap_with_arg() {
func="$1" ; shift
for sig ; do
trap "$func $sig" "$sig"
done
}
func_trap() {
cleanupAndExit 255 "Installomator has been terminated with: $1" ERROR
}
runAsUser() {
if [[ $currentUser != "loginwindow" ]]; then
uid=$(id -u "$currentUser")

View File

@@ -1,3 +1,4 @@
# Mark: 4 Main
*)
# unknown label
#printlog "unknown label $label"