mirror of
https://github.com/mtan93/Installomator.git
synced 2026-03-08 05:31:53 +00:00
Trapping the script
Using these signals: ``` SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM SIGTSTP ``` Fixed #272
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
## v10
|
## 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
|
## v9
|
||||||
|
|||||||
@@ -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
|
autoload is-at-least
|
||||||
|
|
||||||
installedOSversion=$(sw_vers -productVersion)
|
installedOSversion=$(sw_vers -productVersion)
|
||||||
@@ -125,4 +130,4 @@ valuesfromarguments)
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# label descriptions start here
|
# Mark: label descriptions start here
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# MARK: Functions
|
# MARK: 2 Functions
|
||||||
|
|
||||||
cleanupAndExit() { # $1 = exit code, $2 message, $3 level
|
cleanupAndExit() { # $1 = exit code, $2 message, $3 level
|
||||||
if [ -n "$dmgmount" ]; then
|
if [ -n "$dmgmount" ]; then
|
||||||
@@ -29,6 +29,17 @@ cleanupAndExit() { # $1 = exit code, $2 message, $3 level
|
|||||||
exit "$1"
|
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() {
|
runAsUser() {
|
||||||
if [[ $currentUser != "loginwindow" ]]; then
|
if [[ $currentUser != "loginwindow" ]]; then
|
||||||
uid=$(id -u "$currentUser")
|
uid=$(id -u "$currentUser")
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
# Mark: 4 Main
|
||||||
*)
|
*)
|
||||||
# unknown label
|
# unknown label
|
||||||
#printlog "unknown label $label"
|
#printlog "unknown label $label"
|
||||||
|
|||||||
Reference in New Issue
Block a user