Blame Scripts/Functions/Prepare/prepare_doLinks.sh

08abde
#!/bin/bash
08abde
#
c3ce6a
# prepare_doLinks.sh -- This function creates the base configuration
c3ce6a
# of symbolic links your workstation needs to have in order for
c3ce6a
# centos-art command to run correctly.
08abde
#
9f5f2e
# Copyright (C) 2009-2011 Alain Reguera Delgado
fa95b1
#
fa95b1
# This program is free software; you can redistribute it and/or modify
fa95b1
# it under the terms of the GNU General Public License as published by
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# 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
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
08abde
# ----------------------------------------------------------------------
08abde
# $Id$
08abde
# ----------------------------------------------------------------------
08abde
1700f3
function prepare_doLinks {
08abde
8e457b
    # Verify `--links' option.
8e457b
    if [[ $FLAG_LINKS == 'false' ]];then
8e457b
        return
8e457b
    fi
8e457b
8e457b
    # Print line separator.
8e457b
    cli_printMessage '-' 'AsSeparatorLine'
8e457b
0b585a
    # Print action message.
0b585a
    cli_printMessage "`gettext "Checking symbolic links"`" 'AsResponseLine'
0b585a
0b585a
    # Print line separator.
0b585a
    cli_printMessage '-' 'AsSeparatorLine'
0b585a
8e457b
    local -a LINKS_SRC
8e457b
    local -a LINKS_DST
c3ce6a
    local SUFFIX=''
06f172
    local USERFILES=''
0b585a
    local PALETTE=''
0b585a
    local BRUSH=''
0b585a
    local PATTERN=''
0b585a
    local FONT=''
0b585a
    local FILE=''
8e457b
    local COUNT=0
08abde
0b585a
    # Define user-specific directory for Gimp.
0b585a
    local GIMP_USER_DIR=${HOME}/.$(rpm -q gimp | cut -d. -f-2)
8e457b
0b585a
    # Define user-specific directory for Inkscape.
0b585a
    local INKS_USER_DIR=${HOME}/.inkscape
0b585a
c3ce6a
    # Define lists of files which symbolic links will point to.
c3ce6a
    local FONTS=$(cli_getFilesList "${HOME}/artwork/trunk/Identity/Fonts" 'denmark\.ttf')
c3ce6a
    local PALETTES=$(cli_getFilesList "${HOME}/artwork/trunk/Identity/Palettes" ".+\.gpl")
c3ce6a
    local BRUSHES=$(cli_getFilesList "${HOME}/artwork/trunk/Identity/Brushes" ".+\.(gbr|gih)")
c3ce6a
    local PATTERNS=$(cli_getFilesList "${HOME}/artwork/trunk/Identity/Patterns" ".+\.png")
c3ce6a
c3ce6a
    # Define link relation for cli.
0b585a
    LINKS_SRC[0]=${HOME}/bin/$CLI_PROGRAM
a34b3a
    LINKS_DST[0]=${CLI_BASEDIR}/${CLI_PROGRAM}.sh
8e457b
c3ce6a
    # Define link relation for fonts.
0b585a
    for FONT in $FONTS;do
0b585a
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${HOME}/.fonts/$(basename $FONT)
0b585a
        LINKS_DST[((++${#LINKS_DST[*]}))]=$FONT
bc584b
    done
bc584b
c3ce6a
    # Define link relation for common palettes.
0b585a
    for PALETTE in $PALETTES;do
c3ce6a
        SUFFIX="${GIMP_USER_DIR}/palettes/$(prepare_doLinksSuffixes $PALETTE)"
c3ce6a
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${SUFFIX}${NAME}${VERS}$(basename $PALETTE)
0b585a
        LINKS_DST[((++${#LINKS_DST[*]}))]=$PALETTE
c3ce6a
        SUFFIX="${INKS_USER_DIR}/palettes/$(prepare_doLinksSuffixes $PALETTE)"
c3ce6a
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${SUFFIX}${NAME}${VERS}$(basename $PALETTE)
0b585a
        LINKS_DST[((++${#LINKS_DST[*]}))]=$PALETTE
0b585a
    done
8e457b
c3ce6a
    # Define link relation for common brushes.
0b585a
    for BRUSH in $BRUSHES;do
c3ce6a
        SUFFIX="${GIMP_USER_DIR}/brushes/$(prepare_doLinksSuffixes $BRUSH)"
c3ce6a
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${SUFFIX}${NAME}${VERS}$(basename $BRUSH)
0b585a
        LINKS_DST[((++${#LINKS_DST[*]}))]=$BRUSH
0b585a
    done
8e457b
c3ce6a
    # Define link relation for common patterns.
0b585a
    for PATTERN in $PATTERNS;do
c3ce6a
        SUFFIX="${GIMP_USER_DIR}/patterns/$(prepare_doLinksSuffixes $PATTERN)"
c3ce6a
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${SUFFIX}${NAME}${VERS}$(basename $PATTERN)
0b585a
        LINKS_DST[((++${#LINKS_DST[*]}))]=$PATTERN
0b585a
    done
8e457b
c3ce6a
    # Define which files inside user-specific directories need to be
c3ce6a
    # removed in order for centos-art to make a fresh installation of
c3ce6a
    # common patterns, common palettes and common brushes using
c3ce6a
    # symbolic links from the repository.
06f172
    USERFILES=$(cli_getFilesList "${HOME}/.fonts" '.+\.ttf';
06f172
        cli_getFilesList "${HOME}/bin" '.+\.sh';
06f172
        cli_getFilesList "${GIMP_USER_DIR}/palettes" '.+\.gpl';
06f172
        cli_getFilesList "${GIMP_USER_DIR}/brushes" '.+\.(gbr|gih)';
06f172
        cli_getFilesList "${GIMP_USER_DIR}/patterns" '.+\.png';
06f172
        cli_getFilesList "${INKS_USER_DIR}/palettes" '.+\.gpl')
06f172
06f172
    # Remove installed files inside user-specific directories.
06f172
    if [[ "$USERFILES" != '' ]];then
06f172
        cli_printActionPreamble "${USERFILES[*]}" 'doDelete' 'AsResponseLine'
c3ce6a
        for FILE in ${USERFILES};do
06f172
            cli_printMessage "${FILE}" 'AsDeletingLine'
06f172
            rm -r $FILE
06f172
        done
06f172
    fi
8e457b
0b585a
    # Create symbolic links. In case the the symbolic link parent
0b585a
    # directory isn't created, it will be created in order to make
06f172
    # the link creation possible.
06f172
    cli_printActionPreamble "${LINKS_SRC[*]}" 'doCreate' 'AsResponseLine'
0b585a
    while [[ $COUNT -lt ${#LINKS_SRC[*]} ]];do
8e457b
0b585a
        if [[ -f ${LINKS_SRC[$COUNT]} ]];then
0b585a
            cli_printMessage "${LINKS_SRC[$COUNT]}" 'AsUpdatingLine'
0b585a
        else
0b585a
            cli_printMessage "${LINKS_SRC[$COUNT]}" 'AsCreatingLine'
8e457b
        fi
8e457b
0b585a
        if [[ ! -d $(dirname ${LINKS_SRC[$COUNT]}) ]];then
0b585a
            mkdir -p $(dirname ${LINKS_SRC[$COUNT]})
0b585a
        fi
8e457b
0b585a
        ln ${LINKS_DST[$COUNT]} ${LINKS_SRC[$COUNT]} --symbolic --force
8e457b
0b585a
        COUNT=$(($COUNT + 1))
8e457b
8e457b
    done
08abde
08abde
}