2 # ==============================================================================
3 # portsreinstall library script
4 # - Temporary directory and signal trapping -
5 # Copyright (C) 2013 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 [ "x${DATABASE_IS_OBSOLETE}" = xyes ] || return 0
19 message_echo "WARNING: The Ports tree was updated after construction of the temporary database for ${APPNAME}." >&2
20 message_echo "You should consider executing " >&2
21 message_echo " ${APPNAME} clean" >&2
22 message_echo "to reset the temporary database unless you have special purposes." >&2
25 # ============= Creation of temporary work directories =============
28 trap 'errno=$?; temp_warn_obsolete_temp_db; temp_warn_obsolete_temp_db () { :; }; temp_terminate_process; 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 "(Error exit by $errno)" >&2; exit $errno' 0 1 2 3 9 15 17 18
29 { until TMPDIR=`mktemp -dq /tmp/"${APPNAME}".XXXXXXXX` ; do : ; done ; }
30 chgrp "`id -gn`" "${TMPDIR}"
33 # ============= Set the signal trap to be friendly for invoking a new version =============
34 temp_trap_for_invoking_new_version ()
36 [ x`cat "${DBDIR}/.lock" 2> /dev/null` = x$$ ] && rm -f "${DBDIR}/.lock"
37 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
40 # ============= Set the message telling the current stage =============
41 temp_set_msg_current_stage ()
43 echo "$*" > ${TMPDIR}/TEMP::MSG_CURRENT_STAGE
46 # ============= Get the message telling the current stage =============
47 temp_get_msg_current_stage ()
49 cat "${TMPDIR}/TEMP::MSG_CURRENT_STAGE" 2> /dev/null || :