Blame Automation/centos-art.sh-prepare/Scripts/prepare_updateLinks.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# prepare_updateLinks.sh -- This option creates/updates the symbolic links
Alain Reguera Delgado 8f60cb
# information required in your workstation to connect it with the
Alain Reguera Delgado 8f60cb
# files inside the working copy of The CentOS Artwork Repository. When
Alain Reguera Delgado 8f60cb
# you provide this option, the centos-art.sh put itself into your
Alain Reguera Delgado 8f60cb
# system's execution path and make common brushes, patterns, palettes
Alain Reguera Delgado 8f60cb
# and fonts available inside applications like GIMP, so you can make
Alain Reguera Delgado 8f60cb
# use of them without loosing version control over them. 
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 8f60cb
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 8f60cb
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 8f60cb
# your option) any later version.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 8f60cb
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 8f60cb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 8f60cb
# General Public License for more details.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 8f60cb
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 8f60cb
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
# $Id$
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
function prepare_updateLinks {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    local -a LINKS_SRC
Alain Reguera Delgado 8f60cb
    local -a LINKS_DST
Alain Reguera Delgado 8f60cb
    local USERFILES=''
Alain Reguera Delgado 8f60cb
    local PALETTE=''
Alain Reguera Delgado 8f60cb
    local BRUSH=''
Alain Reguera Delgado 8f60cb
    local PATTERN=''
Alain Reguera Delgado 8f60cb
    local FONT=''
Alain Reguera Delgado 8f60cb
    local FILE=''
Alain Reguera Delgado 8f60cb
    local COUNT=0
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define user's directories. Here is where configuration links are
Alain Reguera Delgado 8f60cb
    # created in the local workstation.
Alain Reguera Delgado 8f60cb
    local GIMP_DIR=${HOME}/.$(rpm -q gimp | cut -d. -f-2)
Alain Reguera Delgado 8f60cb
    local GIMP_DIR_BRUSHES=${GIMP_DIR}/brushes
Alain Reguera Delgado 8f60cb
    local GIMP_DIR_PALETTES=${GIMP_DIR}/palettes
Alain Reguera Delgado 8f60cb
    local GIMP_DIR_PATTERNS=${GIMP_DIR}/patterns
Alain Reguera Delgado 8f60cb
    local INKS_DIR=${HOME}/.inkscape
Alain Reguera Delgado 8f60cb
    local INKS_DIR_PALETTES=${INKS_DIR}/palettes
Alain Reguera Delgado 8f60cb
    local FONT_DIR=${HOME}/.fonts
Alain Reguera Delgado 8f60cb
    local APPS_DIR=${HOME}/bin
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define the working copy directory structure. Here is where user
Alain Reguera Delgado 8f60cb
    # specific configuration links in the workstation will point to.
Alain Reguera Delgado 8f60cb
    local WCDIR=${TCAR_WORKDIR}/Identity
Alain Reguera Delgado 8f60cb
    local WCDIR_BRUSHES=${WCDIR}/Brushes
Alain Reguera Delgado 8f60cb
    local WCDIR_PALETTES=${WCDIR}/Palettes
Alain Reguera Delgado 8f60cb
    local WCDIR_PATTERNS=${WCDIR}/Patterns
Alain Reguera Delgado 8f60cb
    local WCDIR_FONTS=${WCDIR}/Fonts
Alain Reguera Delgado 8f60cb
    local WCDIR_EDITOR=${PREPARE_CONFIG_DIR}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify required working copy directory structure. If these
Alain Reguera Delgado 8f60cb
    # directories don't exist, there isn't a target location where
Alain Reguera Delgado 8f60cb
    # configuration links can point to. To prevent such an issue
Alain Reguera Delgado 8f60cb
    # output an error message and stop the script execution after it.
Alain Reguera Delgado 8f60cb
    for DIR in $(echo "Brushes Palettes Patterns Fonts");do
Alain Reguera Delgado 8f60cb
        cli_checkFiles ${WCDIR}/${DIR}
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define link relation for cli.
Alain Reguera Delgado 8f60cb
    LINKS_SRC[((++${#LINKS_SRC[*]}))]=${APPS_DIR}/${CLI_NAME}
Alain Reguera Delgado 8f60cb
    LINKS_DST[((++${#LINKS_DST[*]}))]=${CLI_BASEDIR}/${CLI_NAME}.sh
Alain Reguera Delgado 8f60cb
    USERFILES="${APPS_DIR}/${CLI_NAME}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define link relation for fonts.
Alain Reguera Delgado 8f60cb
    for FONT in $(cli_getFilesList "${WCDIR_FONTS}" --pattern='^.+\.ttf$');do
Alain Reguera Delgado 8f60cb
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${FONT_DIR}/$(basename $FONT)
Alain Reguera Delgado 8f60cb
        LINKS_DST[((++${#LINKS_DST[*]}))]=${FONT}
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define link relation for common palettes.
Alain Reguera Delgado 8f60cb
    for PALETTE in $(cli_getFilesList "${WCDIR_PALETTES}" --pattern="^.+\.gpl$");do
Alain Reguera Delgado 8f60cb
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${GIMP_DIR_PALETTES}/$(prepare_getLinkName ${WCDIR_PALETTES} ${PALETTE})
Alain Reguera Delgado 8f60cb
        LINKS_DST[((++${#LINKS_DST[*]}))]=${PALETTE}
Alain Reguera Delgado 8f60cb
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${INKS_DIR_PALETTES}/$(prepare_getLinkName ${WCDIR_PALETTES} ${PALETTE})
Alain Reguera Delgado 8f60cb
        LINKS_DST[((++${#LINKS_DST[*]}))]=${PALETTE}
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define link relation for common brushes.
Alain Reguera Delgado 8f60cb
    for BRUSH in $(cli_getFilesList "${WCDIR_BRUSHES}" --pattern="^.+\.(gbr|gih)$");do
Alain Reguera Delgado 8f60cb
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${GIMP_DIR_BRUSHES}/$(prepare_getLinkName ${WCDIR_BRUSHES} ${BRUSH})
Alain Reguera Delgado 8f60cb
        LINKS_DST[((++${#LINKS_DST[*]}))]=${BRUSH}
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define link relation for common patterns.
Alain Reguera Delgado 8f60cb
    for PATTERN in $(cli_getFilesList "${WCDIR_PATTERNS}" --pattern="^.+\.png$");do
Alain Reguera Delgado 8f60cb
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${GIMP_DIR_PATTERNS}/$(prepare_getLinkName ${WCDIR_BRUSHES} ${BRUSH})
Alain Reguera Delgado 8f60cb
        LINKS_DST[((++${#LINKS_DST[*]}))]=${PATTERN}
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define link relation for Vim text editor's configuration.
Alain Reguera Delgado 8f60cb
    if [[ $EDITOR == '/usr/bin/vim' ]];then
Alain Reguera Delgado 8f60cb
        LINKS_SRC[((++${#LINKS_SRC[*]}))]=${HOME}/.vimrc
Alain Reguera Delgado 8f60cb
        LINKS_DST[((++${#LINKS_DST[*]}))]=${WCDIR_EDITOR}/vim.conf
Alain Reguera Delgado 8f60cb
        USERFILES="${USERFILES} ${HOME}/.vimrc"
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define link relation for the `reset.css' file. The `reset.css'
Alain Reguera Delgado 8f60cb
    # file is resets the web browser default style and use ours
Alain Reguera Delgado 8f60cb
    # instead. The reset.css file is common for all web environments
Alain Reguera Delgado 8f60cb
    # so there is no need to have duplicated files inside the working
Alain Reguera Delgado 8f60cb
    # copy.  Instead, create a symbolic link to it from different
Alain Reguera Delgado 8f60cb
    # places using absolute paths and the default style guide as
Alain Reguera Delgado 8f60cb
    # reference.
Alain Reguera Delgado 8f60cb
    LINKS_SRC[((++${#LINKS_SRC[*]}))]=${TCAR_WORKDIR}/Identity/Webenv/Themes/Default/Docbook/1.69.1/Css/reset.css
Alain Reguera Delgado 8f60cb
    LINKS_DST[((++${#LINKS_DST[*]}))]=${TCAR_WORKDIR}/Identity/Webenv/Themes/Default/Style-guide/0.0.1/Css/reset.css
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define link relation for `images' directory used inside the
Alain Reguera Delgado 8f60cb
    # default web environment style guide. The `images' directory
Alain Reguera Delgado 8f60cb
    # contains common images used by all web environments. By default
Alain Reguera Delgado 8f60cb
    # no image is under version control so we point out the output
Alain Reguera Delgado 8f60cb
    # directory where this images produced, once rendered.
Alain Reguera Delgado 8f60cb
    LINKS_SRC[((++${#LINKS_SRC[*]}))]=${TCAR_WORKDIR}/Identity/Webenv/Themes/Default/Style-guide/0.0.1/Images
Alain Reguera Delgado 8f60cb
    LINKS_DST[((++${#LINKS_DST[*]}))]=${TCAR_WORKDIR}/Identity/Images/Webenv
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define link relation for `Manuals' images. These images exists
Alain Reguera Delgado 8f60cb
    # to help people describe ideas inside documentation.
Alain Reguera Delgado 8f60cb
    LINKS_SRC[((++${#LINKS_SRC[*]}))]=${TCAR_WORKDIR}/Identity/Images/Webenv/Manuals
Alain Reguera Delgado 8f60cb
    LINKS_DST[((++${#LINKS_DST[*]}))]=${TCAR_WORKDIR}/Identity/Images/Manuals
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define link for `centos-logo.png', the branding information that
Alain Reguera Delgado 8f60cb
    # should be used in all web applications on the left-top corner.
Alain Reguera Delgado 8f60cb
    LINKS_SRC[((++${#LINKS_SRC[*]}))]=${TCAR_WORKDIR}/Identity/Images/Webenv/logo-centos.png
Alain Reguera Delgado 8f60cb
    LINKS_DST[((++${#LINKS_DST[*]}))]=${TCAR_WORKDIR}/Identity/Images/Brands/Logos/White/78/centos.png
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define which files inside the user's configuration directories
Alain Reguera Delgado 8f60cb
    # need to be removed in order for centos-art.sh script to make a
Alain Reguera Delgado 8f60cb
    # fresh installation of common patterns, common palettes and
Alain Reguera Delgado 8f60cb
    # common brushes using symbolic links from the working copy to the
Alain Reguera Delgado 8f60cb
    # user's configuration directories inside the workstation.
Alain Reguera Delgado 8f60cb
    USERFILES=$(echo "$USERFILES";
Alain Reguera Delgado 8f60cb
        cli_getFilesList ${APPS_DIR} --pattern='^.+\.sh$';
Alain Reguera Delgado 8f60cb
        cli_getFilesList ${FONT_DIR} --pattern='^.+\.ttf$';
Alain Reguera Delgado 8f60cb
        cli_getFilesList ${GIMP_DIR_BRUSHES} --pattern='^.+\.(gbr|gih)$';
Alain Reguera Delgado 8f60cb
        cli_getFilesList ${GIMP_DIR_PATTERNS} --pattern='^.+\.(pat|png|jpg|bmp)$';
Alain Reguera Delgado 8f60cb
        cli_getFilesList ${GIMP_DIR_PALETTES} --pattern='^.+\.gpl$';
Alain Reguera Delgado 8f60cb
        cli_getFilesList ${INKS_DIR_PALETTES} --pattern='^.+\.gpl$';)
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Remove user-specific configuration files from user's home
Alain Reguera Delgado 8f60cb
    # directory before creating symbolic links from the working copy.
Alain Reguera Delgado 8f60cb
    # Otherwise, we might end up having links inside the user's home
Alain Reguera Delgado 8f60cb
    # directory that don't exist inside the working copy.
Alain Reguera Delgado 8f60cb
    if [[ "$USERFILES" != '' ]];then
Alain Reguera Delgado 8f60cb
        rm -r $USERFILES
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    while [[ $COUNT -lt ${#LINKS_SRC[*]} ]];do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Print action message.
Alain Reguera Delgado 8f60cb
        cli_printMessage "${LINKS_SRC[$COUNT]}" --as-creating-line
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Create symbolic link's parent directory if it doesn't exist.
Alain Reguera Delgado 8f60cb
        if [[ ! -d $(dirname ${LINKS_SRC[$COUNT]}) ]];then
Alain Reguera Delgado 8f60cb
            mkdir -p $(dirname ${LINKS_SRC[$COUNT]})
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Remove symbolic link before creating it to prevent recursive
Alain Reguera Delgado 8f60cb
        # creation once the first symbolic link be created and it be a
Alain Reguera Delgado 8f60cb
        # directory.
Alain Reguera Delgado 8f60cb
        if [[ -a ${LINKS_SRC[$COUNT]} ]];then
Alain Reguera Delgado 8f60cb
            rm ${LINKS_SRC[$COUNT]}
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Create symbolic link.
Alain Reguera Delgado 8f60cb
        ln ${LINKS_DST[$COUNT]} ${LINKS_SRC[$COUNT]} --symbolic --force
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Increment counter.
Alain Reguera Delgado 8f60cb
        COUNT=$(($COUNT + 1))
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}