Blame Scripts/Bash/Functions/Verify/verify_doLinkCheck.sh

08abde
#!/bin/bash
08abde
#
08abde
# verify_doLinkCheck.sh -- This function receives a list of required
08abde
# symbolic links and verifies them. This function enforces relation
08abde
# between link names and their targets (previously defined in
08abde
# verify_doLinks.sh function).
08abde
#
72c8a5
# Copyright (C) 2009-2011  Alain Reguera Delgado
08abde
# 
7cd8e9
# This program is free software; you can redistribute it and/or
7cd8e9
# modify it under the terms of the GNU General Public License as
7cd8e9
# published by the Free Software Foundation; either version 2 of the
7cd8e9
# License, or (at your option) any later version.
08abde
# 
08abde
# This program is distributed in the hope that it will be useful, but
08abde
# WITHOUT ANY WARRANTY; without even the implied warranty of
08abde
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08abde
# General Public License for more details.
08abde
#
08abde
# You should have received a copy of the GNU General Public License
08abde
# along with this program; if not, write to the Free Software
08abde
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
08abde
# USA.
08abde
# 
08abde
# ----------------------------------------------------------------------
08abde
# $Id$
08abde
# ----------------------------------------------------------------------
08abde
08abde
function verify_doLinkCheck {
08abde
08abde
    local -a LINKS_TARGET
08abde
    local LINKS_COUNT=0
08abde
08abde
    until [[ $LINKS_COUNT -eq ${#LINKS[*]} ]];do
08abde
08abde
        if [[ -h ${LINKS[$LINKS_COUNT]} ]]; then
08abde
08abde
            # At this point the required link does exist but we don't
08abde
            # know if its target is the one it should be. Get target
08abde
            # from required link in order to check it later.
08abde
            LINKS_TARGET[$LINKS_COUNT]=$(stat --format='%N' ${LINKS[$LINKS_COUNT]} \
08abde
                | tr '`' ' ' | tr "'" ' ' | tr -s ' ' | cut -d' ' -f4)
08abde
08abde
            # Check required target from required link in order to
08abde
            # know if it is indeed the one it should be. Otherwise add
08abde
            # required link to list of missing links.
08abde
            if [[ ${LINKS_TARGET[$LINKS_COUNT]} != ${TARGETS[$LINKS_COUNT]} ]] ;then
08abde
                LINKS_MISSING[$LINKS_COUNT]=${LINKS[$LINKS_COUNT]}
08abde
                LINKS_MISSING_ID="$LINKS_MISSING_ID $LINKS_COUNT"
08abde
            fi
08abde
08abde
        else
08abde
08abde
            # At this point the required link doesn't exist at all.
08abde
            # Add required link to list of missing links.
08abde
            LINKS_MISSING[$LINKS_COUNT]=${LINKS[$LINKS_COUNT]}
08abde
            LINKS_MISSING_ID="$LINKS_MISSING_ID $LINKS_COUNT"
08abde
08abde
        fi
08abde
08abde
        # Increase link counter.
08abde
        LINKS_COUNT=$(($LINKS_COUNT + 1))
08abde
        
08abde
    done
08abde
08abde
    # Stript out leading spaces from missing links ids.
08abde
    LINKS_MISSING_ID=$(echo $LINKS_MISSING_ID | sed 's!^ +!!')
08abde
08abde
    # If there is no missing link, end script execution with a
08abde
    # descriptive output.
08abde
    if [[ ${#LINKS_MISSING[*]} -eq 0 ]];then
08abde
        cli_printMessage "`gettext "The required links are already installed."`"
08abde
        cli_printMessage "$(caller)" 'AsToKnowMoreLine'
08abde
    fi
08abde
08abde
}