Blame Scripts/Bash/Cli/Functions/Prepare/prepare_doLinks.sh

08abde
#!/bin/bash
08abde
#
0b585a
# prepare_doLinks.sh -- This function installs the symbolic links your
0b585a
# workstation needs to have in order for centos-art command to run
0b585a
# correctly.
08abde
#
9f5f2e
# 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
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
0b585a
    local -a 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
0b585a
    # Define both source and target location for centos-art command.
0b585a
    LINKS_SRC[0]=${HOME}/bin/$CLI_PROGRAM
8e457b
    LINKS_DST[0]=${CLI_BASEDIR}/init.sh
8e457b
0b585a
    # Define both source and target location for fonts.
0b585a
    local FONTS=$(cli_getFilesList "${HOME}/artwork/trunk/Identity/Fonts" 'denmark\.ttf')
0b585a
    for FONT in $FONTS;do
0b585a
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${HOME}/.fonts/$(basename $FONT)
0b585a
        LINKS_DST[((++${#LINKS_DST[*]}))]=$FONT
bc584b
    done
bc584b
0b585a
    # Define both source and target location for Gimp and Inkscape
0b585a
    # palettes.
0b585a
    local PALETTES=$(cli_getFilesList "$HOME/artwork/trunk/Identity/Themes/Motifs/*/*/Palettes
0b585a
        ${HOME}/artwork/trunk/Identity/Palettes" ".+\.gpl")
0b585a
    for PALETTE in $PALETTES;do
0b585a
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${GIMP_USER_DIR}/palettes/$(basename $PALETTE)
0b585a
        LINKS_DST[((++${#LINKS_DST[*]}))]=$PALETTE
0b585a
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${INKS_USER_DIR}/palettes/$(basename $PALETTE)
0b585a
        LINKS_DST[((++${#LINKS_DST[*]}))]=$PALETTE
0b585a
    done
8e457b
0b585a
    # Define both source and target location for Gimp brushes.
0b585a
    local BRUSHES=$(cli_getFilesList \
0b585a
        "${HOME}/artwork/trunk/Identity/Themes/Motifs/*/*/Brushes" \
6975fc
        ".+\.(gbr|gih)")
0b585a
    for BRUSH in $BRUSHES;do
0b585a
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${GIMP_USER_DIR}/brushes/$(basename $BRUSH)
0b585a
        LINKS_DST[((++${#LINKS_DST[*]}))]=$BRUSH
0b585a
    done
8e457b
0b585a
    # Define both source and target location for Gimp patterns.
0b585a
    local PATTERNS=$(cli_getFilesList \
0b585a
        "${HOME}/artwork/trunk/Identity/Themes/Motifs/*/*/Patterns" \
0b585a
        ".+\.png")
0b585a
    for PATTERN in $PATTERNS;do
0b585a
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${GIMP_USER_DIR}/patterns/$(basename $PATTERN)
0b585a
        LINKS_DST[((++${#LINKS_DST[*]}))]=$PATTERN
0b585a
    done
8e457b
0b585a
    # Define information installed inside user-specific directories
0b585a
    # that need to be cleaned up in order to make a fresh installation
0b585a
    # of patterns, palettes and brushes from repository by mean of
0b585a
    # symbolic links.
0b585a
    USERFILES[((++${#USERFILES[*]}))]=$(cli_getFilesList "${HOME}/.fonts" '.+\.ttf')
0b585a
    USERFILES[((++${#USERFILES[*]}))]=$(cli_getFilesList "${HOME}/bin" '.+\.sh')
0b585a
    USERFILES[((++${#USERFILES[*]}))]=$(cli_getFilesList "${GIMP_USER_DIR}/palettes" '.+\.gpl')
6975fc
    USERFILES[((++${#USERFILES[*]}))]=$(cli_getFilesList "${GIMP_USER_DIR}/brushes" '.+\.(gbr|gih)')
0b585a
    USERFILES[((++${#USERFILES[*]}))]=$(cli_getFilesList "${GIMP_USER_DIR}/patterns" '.+\.png')
0b585a
    USERFILES[((++${#USERFILES[*]}))]=$(cli_getFilesList "${INKS_USER_DIR}/palettes" '.+\.gpl')
0b585a
0b585a
    # Print action preamble.
0b585a
    cli_printActionPreamble "${USERFILES[*]}" 'doDelete' 'AsResponseLine'
0b585a
0b585a
    # Remove installed inside user-specific directories.
0b585a
    for FILE in ${USERFILES[@]};do
0b585a
        cli_printMessage "${FILE}" 'AsDeletingLine'
0b585a
        rm -r $FILE
8e457b
    done
8e457b
0b585a
    # Print action preamble.
0b585a
    cli_printActionPreamble "${LINKS_SRC[*]}" 'doCreate' 'AsResponseLine'
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
0b585a
    # link creation possible.
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
}