Blame Scripts/CentOS-Art/Functions/cli_terminateScriptExecution.sh

9b5ad9
#!/bin/bash
9b5ad9
#
9b5ad9
# cli_terminateScriptExecution.sh -- This function standardizes the
9b5ad9
# actions that must be realized just before leaving the script
9b5ad9
# execution (e.g., cleaning temporal files).  This function is the one
9b5ad9
# called when interruption signals like EXIT, SIGHUP, SIGINT and
9b5ad9
# SIGTERM are detected.
9b5ad9
#
2fe9b7
# Copyright (C) 2009, 2010, 2011 The CentOS Project
9b5ad9
#
9b5ad9
# This program is free software; you can redistribute it and/or modify
9b5ad9
# it under the terms of the GNU General Public License as published by
9b5ad9
# the Free Software Foundation; either version 2 of the License, or (at
9b5ad9
# your option) any later version.
9b5ad9
#
9b5ad9
# This program is distributed in the hope that it will be useful, but
9b5ad9
# WITHOUT ANY WARRANTY; without even the implied warranty of
9b5ad9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
9b5ad9
# General Public License for more details.
9b5ad9
#
9b5ad9
# You should have received a copy of the GNU General Public License
9b5ad9
# along with this program; if not, write to the Free Software
9b5ad9
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
9b5ad9
#
9b5ad9
# ----------------------------------------------------------------------
9b5ad9
# $Id$
9b5ad9
# ----------------------------------------------------------------------
9b5ad9
9b5ad9
function cli_terminateScriptExecution {
9b5ad9
9b5ad9
    # Build list of temporal files related to this script execution.
9b5ad9
    # Remember that inside `/tmp' directory there are files and
9b5ad9
    # directories you might have no access to (due permission
9b5ad9
    # restrictions), so command cli_getFilesList to look for files in
9b5ad9
    # the first level of files that you are owner of.  Otherwise,
9b5ad9
    # undesired `permission denied' messages might be output.
9b5ad9
    local FILES=$(cli_getFilesList ${CLI_TEMPDIR} \
9b5ad9
        --pattern="${CLI_PROGRAM}-${CLI_PROGRAM_ID}-.+" \
9b5ad9
        --maxdepth="1" --uid="$(id -u)")
9b5ad9
9b5ad9
    # Remove list of temporal files related to this script execution,
9b5ad9
    # if any of course. Remember that some of the temporal files can
9b5ad9
    # be directories, too.
9b5ad9
    if [[ $FILES != '' ]];then
f9f63c
        rm -rf $FILES
9b5ad9
    fi
9b5ad9
f9f63c
    # Terminate script correctly.
f9f63c
    exit 0
f9f63c
9b5ad9
}