2 # ==============================================================================
3 # portsreinstall library script
4 # - Temporary directory and signal trapping -
5 # Copyright (C) 2013-2018 Mamoru Sakaue, MwGhennndo, All Rights Reserved.
6 # This software is distributed under the 2-Clause BSD License.
7 # ==============================================================================
9 # ============= Variables =============
10 TMPDIR=/tmp # Temporary directory
12 # ============= Default additional operation in a trap process =============
13 temp_terminate_process () { :; }
15 # ============= Warn when the temporary database is obsolete =============
16 temp_warn_obsolete_temp_db () { :; }
18 # ============= Creation of temporary work directories =============
21 trap 'errno=$?; temp_warn_obsolete_temp_db >&2 || :; temp_warn_obsolete_temp_db () { :; }; temp_terminate_process $errno >&2 || :; temp_terminate_process () { :; }; rm -rf "${TMPDIR}" 2> /dev/null; [ -n "${DBDIR}" -a x`cat "${DBDIR}/.lock" 2> /dev/null` = x$$ ] && rm -f "${DBDIR}/.lock"; [ $errno -gt 0 -a $errno -ne 130 ] && message_echo "(Exit code: $errno)" >&2; exit $errno' 0 1 2 3 9 15 17 18
22 { until TMPDIR=`mktemp -dq /tmp/"${APPNAME}".XXXXXXXX` ; do : ; done ; }
23 chgrp "`id -gn`" "${TMPDIR}"
26 # ============= Set the signal trap to be friendly for invoking a new version =============
27 temp_trap_for_invoking_new_version ()
29 [ x`cat "${DBDIR}/.lock" 2> /dev/null` = x$$ ] && rm -f "${DBDIR}/.lock"
30 trap 'errno=$?; rm -rf "${TMPDIR}" 2> /dev/null; [ $errno -gt 0 -a $errno -ne 130 ] && echo "(Error exit by $errno)" >&2; exit $errno' 0 1 2 3 9 15 17 18
33 # ============= Set the message telling the current stage =============
34 temp_set_msg_current_stage ()
36 echo "$*" > ${TMPDIR}/TEMP::MSG_CURRENT_STAGE
39 # ============= Get the message telling the current stage =============
40 temp_get_msg_current_stage ()
42 cat "${TMPDIR}/TEMP::MSG_CURRENT_STAGE" 2> /dev/null || :
45 # ============= Reset the termination messages to the common one =============
46 temp_reset_termination_messages_common ()
48 temp_terminate_process ()
52 temp_terminate_process_common "$errno"