Blame Scripts/Functions/Prepare/prepare_doLinks.sh

08abde
#!/bin/bash
08abde
#
c3ce6a
# prepare_doLinks.sh -- This function creates the base configuration
c23a8a
# of symbolic links your workstation needs to have installed in order
c23a8a
# for you to use the `centos-art' command and some auxiliar components
c23a8a
# (e.g., palettes, brushes, patterns, fonts, etc.) that may result
c23a8a
# useful for you when designing graphical compositions.
08abde
#
2d3646
# Copyright (C) 2009, 2010, 2011 The CentOS Project
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
7ac5a5
# the Free Software Foundation; either version 2 of the License, or (at
7ac5a5
# 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.
7ac5a5
#
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
    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
c23a8a
    # Define user-specific directories.
c23a8a
    local GIMP_USERDIR=${HOME}/.$(rpm -q gimp | cut -d. -f-2)
c23a8a
    local INKS_USERDIR=${HOME}/.inkscape
c3ce6a
c3ce6a
    # Define link relation for cli.
c23a8a
    LINKS_SRC[((++${#LINKS_SRC[*]}))]=${HOME}/bin/$CLI_PROGRAM
c23a8a
    LINKS_DST[((++${#LINKS_DST[*]}))]=${CLI_BASEDIR}/${CLI_PROGRAM}.sh
c0ce08
    USERFILES="${HOME}/bin/$CLI_PROGRAM"
8e457b
c3ce6a
    # Define link relation for fonts.
c23a8a
    for FONT in $(cli_getFilesList "${HOME}/artwork/trunk/Identity/Fonts" 'denmark\.ttf');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.
c23a8a
    for PALETTE in $(cli_getFilesList "${HOME}/artwork/trunk/Identity/Palettes" ".+\.gpl");do
c23a8a
        SUFFIX="${GIMP_USERDIR}/palettes/$(prepare_doLinksSuffixes $PALETTE)"
c3ce6a
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${SUFFIX}${NAME}${VERS}$(basename $PALETTE)
0b585a
        LINKS_DST[((++${#LINKS_DST[*]}))]=$PALETTE
c23a8a
        SUFFIX="${INKS_USERDIR}/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.
c23a8a
    for BRUSH in $(cli_getFilesList "${HOME}/artwork/trunk/Identity/Brushes" ".+\.(gbr|gih)");do
c23a8a
        SUFFIX="${GIMP_USERDIR}/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.
c23a8a
    for PATTERN in $(cli_getFilesList "${HOME}/artwork/trunk/Identity/Patterns" ".+\.png");do
c23a8a
        SUFFIX="${GIMP_USERDIR}/patterns/$(prepare_doLinksSuffixes $PATTERN)"
c3ce6a
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${SUFFIX}${NAME}${VERS}$(basename $PATTERN)
0b585a
        LINKS_DST[((++${#LINKS_DST[*]}))]=$PATTERN
0b585a
    done
8e457b
c0ce08
    # Define link relation for Vim text editor.
c0ce08
    if [[ $EDITOR == '/usr/bin/vim' ]];then
c0ce08
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${HOME}/.vimrc
c0ce08
        LINKS_DST[((++${#LINKS_DST[*]}))]=${FUNCCONFIG}/vimrc
c0ce08
        USERFILES="${USERFILES} ${HOME}/.vimrc"
c0ce08
    fi
c0ce08
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.
c0ce08
    USERFILES=$(echo "$USERFILES";
06f172
        cli_getFilesList "${HOME}/bin" '.+\.sh';
c0ce08
        cli_getFilesList "${HOME}/.fonts" '.+\.ttf';
c23a8a
        cli_getFilesList "${GIMP_USERDIR}/brushes" '.+\.(gbr|gih)';
83df8c
        cli_getFilesList "${GIMP_USERDIR}/patterns" '.+\.(pat|png|jpg|bmp)';
c0ce08
        cli_getFilesList "${GIMP_USERDIR}/palettes" '.+\.gpl';
c0ce08
        cli_getFilesList "${INKS_USERDIR}/palettes" '.+\.gpl';)
06f172
c0ce08
    # Remove files installed inside user-specific directories.
06f172
    if [[ "$USERFILES" != '' ]];then
c0ce08
        cli_printActionPreamble "$USERFILES" 'doDelete' 'AsResponseLine'
c23a8a
        rm -r $USERFILES
06f172
    fi
8e457b
c23a8a
    # Print preamble message for symbolic link creation.
06f172
    cli_printActionPreamble "${LINKS_SRC[*]}" 'doCreate' 'AsResponseLine'
c23a8a
0b585a
    while [[ $COUNT -lt ${#LINKS_SRC[*]} ]];do
8e457b
c23a8a
        # Print action message.
c23a8a
        if [[ -a ${LINKS_SRC[$COUNT]} ]];then
0b585a
            cli_printMessage "${LINKS_SRC[$COUNT]}" 'AsUpdatingLine'
0b585a
        else
0b585a
            cli_printMessage "${LINKS_SRC[$COUNT]}" 'AsCreatingLine'
8e457b
        fi
8e457b
c23a8a
        # Create symbolic link parent directory if it doesn't exist.
0b585a
        if [[ ! -d $(dirname ${LINKS_SRC[$COUNT]}) ]];then
0b585a
            mkdir -p $(dirname ${LINKS_SRC[$COUNT]})
0b585a
        fi
8e457b
c23a8a
        # Create symbolic link.
0b585a
        ln ${LINKS_DST[$COUNT]} ${LINKS_SRC[$COUNT]} --symbolic --force
8e457b
c23a8a
        # Increment counter.
0b585a
        COUNT=$(($COUNT + 1))
8e457b
8e457b
    done
08abde
08abde
}