mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-12 23:13:48 -05:00
add _safeExit_
This commit is contained in:
@@ -333,3 +333,29 @@ _setPATH_() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_safeExit_() {
|
||||||
|
# DESC: Cleanup and exit from a script
|
||||||
|
# ARGS: $1 (optional) - Exit code (defaults to 0)
|
||||||
|
# OUTS: None
|
||||||
|
|
||||||
|
if [[ -d "${script_lock-}" ]]; then
|
||||||
|
if command rm -rf "${script_lock}"; then
|
||||||
|
debug "Removing script lock"
|
||||||
|
else
|
||||||
|
warning "Script lock could not be removed. Try manually deleting ${tan}'${lock_dir}'${red}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "${tmpDir-}" && -d "${tmpDir-}" ]]; then
|
||||||
|
if [[ ${1-} == 1 && -n "$(ls "${tmpDir}")" ]]; then
|
||||||
|
command rm -r "${tmpDir}"
|
||||||
|
else
|
||||||
|
command rm -r "${tmpDir}"
|
||||||
|
debug "Removing temp directory"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
trap - INT TERM EXIT
|
||||||
|
exit ${1:-0}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user