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
11 TEMP_IN_TRAP=no # Whether to be in a error trap process
13 # ============= Default additional operation in a trap process =============
14 temp_terminate_process () { :; }
16 # ============= Warn when the temporary database is obsolete =============
17 temp_warn_obsolete_temp_db () { :; }
19 # ============= Creation of temporary work directories: Trap operation =============
20 temp_trap_init__opetration ()
26 temp_warn_obsolete_temp_db >&2 || :
27 temp_warn_obsolete_temp_db () { :; }
28 temp_terminate_process $errno >&2 || :
29 temp_terminate_process () { :; }
30 rm -rf "${TMPDIR}" 2> /dev/null
31 [ -n "${DBDIR}" -a x`cat "${DBDIR}/.lock" 2> /dev/null` = x$$ ] && rm -f "${DBDIR}/.lock"
32 [ $errno -gt 0 -a $errno -ne 130 -a $opt_batch_mode = no -a $opt_no_opening_message = no ] && echo "(Exit code: $errno)" >&2
36 # ============= Creation of temporary work directories =============
39 trap 'temp_trap_init__opetration $?' 0 1 2 3 9 15 17 18
40 { until TMPDIR=`mktemp -dq /tmp/"${APPNAME}".XXXXXXXX` ; do : ; done ; }
41 chgrp "`id -gn`" "${TMPDIR}"
44 # ============= Set the signal trap to be friendly for invoking a new version: Trap operation =============
45 temp_trap_for_invoking_new_version__opetration ()
50 rm -rf "${TMPDIR}" 2> /dev/null
51 [ $errno -gt 0 -a $errno -ne 130 -a $opt_batch_mode = no -a $opt_no_opening_message = no ] && echo "(Exit code: $errno)" >&2
55 # ============= Set the signal trap to be friendly for invoking a new version =============
56 temp_trap_for_invoking_new_version ()
58 [ x`cat "${DBDIR}/.lock" 2> /dev/null` = x$$ ] && rm -f "${DBDIR}/.lock"
59 trap 'temp_trap_for_invoking_new_version__opetration $?' 0 1 2 3 9 15 17 18
62 # ============= Set the message telling the current stage =============
63 temp_set_msg_current_stage ()
65 echo "$*" > ${TMPDIR}/TEMP::MSG_CURRENT_STAGE
68 # ============= Get the message telling the current stage =============
69 temp_get_msg_current_stage ()
71 cat "${TMPDIR}/TEMP::MSG_CURRENT_STAGE" 2> /dev/null || :
74 # ============= Reset the termination messages to the common one =============
75 temp_reset_termination_messages_common ()
77 temp_terminate_process ()
81 temp_terminate_process_common "$errno"