Blame Scripts/Bash/Functions/Render/Svg/svg_convertPngToDm.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# svg_convertPngToDm.sh -- This function standardize production of
878a2b
# display managers (e.g., Gdm and Kdm). This function copies all files
878a2b
# needed into a temporal directory, realize expansion of translation
878a2b
# markers and packs all the files into a tar.gz package that is used
878a2b
# for installation. This function must be used as last-rendition
878a2b
# action for Gdm and Kdm directory specific base-rendition actions.
878a2b
#
878a2b
# Copyright (C) 2009, 2010, 2011 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function svg_convertPngToDm {
878a2b
878a2b
    # Print separator line.
878a2b
    cli_printMessage '-' --as-separator-line
878a2b
878a2b
    # Initialize source and destination local variables.
878a2b
    local SRC=''
878a2b
    local DST=''
878a2b
878a2b
    # Initialize display manager type.
878a2b
    local DM=$(render_getConfigOption "${ACTION}" '2')
878a2b
878a2b
    # Initialize screen resolutions used by display manager theme.
878a2b
    # These are the different screen resolutions a display manager
878a2b
    # theme is built for. The amount of screen resolution a display
878a2b
    # manager theme can be built for is limited to the amount of
878a2b
    # background files provided by the artistic motif used to build
878a2b
    # the display manager theme.
878a2b
    local RESOLUTION=''
878a2b
    local RESOLUTIONS=$(render_getConfigOption "${ACTION}" '3')
878a2b
878a2b
    # Verify screen resolutions. We cannot produce display manager
878a2b
    # theme if no screen resolution has been specified.
878a2b
    if [[ "$RESOLUTIONS" == '' ]];then
878a2b
        cli_printMessage "`gettext "There is no resolution information to process."`" --as-error-line
878a2b
    fi
878a2b
878a2b
    # Initialize theme information we are going to build the display
878a2b
    # manager theme for.
878a2b
    local THEME=$(cli_getPathComponent $ACTIONVAL --motif)
878a2b
    local THEME_NAME=$(cli_getPathComponent $ACTIONVAL --motif-name)
878a2b
878a2b
    # Initialize temporal directory where we collect all files needed
878a2b
    # in order to create the tar.gz file. This intermediate step is
878a2b
    # also needed in order to expand translation markers from XML and
878a2b
    # Desktop definitions.
878a2b
    local TMPDIR=$(cli_getTemporalFile 'dm')
878a2b
878a2b
    # Initialize source location for brands. This is the place where
878a2b
    # brand information, needed to build the display manager theme, is
878a2b
    # retrived from.
878a2b
    local BRANDS=$(cli_getRepoTLDir)/Identity/Images/Brands
878a2b
878a2b
    # Initialize source location for artistic motif's backgrounds.
878a2b
    # This is the place where background information needed to ubild
878a2b
    # the display manager theme is retrived from. 
878a2b
    local BGS=$(cli_getRepoTLDir)/Identity/Images/Themes/${THEME}/Backgrounds/Img/Png
878a2b
878a2b
    # Initialize file variables. File variables are used build and
878a2b
    # process the file relation between source and target locations. 
878a2b
    local FILE=''
878a2b
    local FILES=''
878a2b
878a2b
    # Define major release from template.
878a2b
    local MAJOR_RELEASE=$(cli_getPathComponent "$TEMPLATE" "--release-major")
878a2b
878a2b
    # Define file relation between source and target locations, based
878a2b
    # on whether we are producing GDM or KDM. Use the colon character
878a2b
    # (`:') as separator; on the left side we put the file's source
878a2b
    # location and in the right side the file's target location.
878a2b
    # Presently, both GDM and KDM are very similar on files with the
878a2b
    # exception that GDM does use icons near actions buttons (e.g.,
878a2b
    # shutdown, reboot, session, language) and KDM doesn't.
878a2b
    case ${DM} in
878a2b
878a2b
        Gdm )
878a2b
            FILES="\
2b0a79
            ${BRANDS}/Symbols/White/48/${BRAND_FILENAME}.png:${BRAND_FILENAME}-symbol.png
878a2b
            ${OUTPUT}/screenshot.png:screenshot.png
878a2b
            $(dirname $TEMPLATE)/GdmGreeterTheme.xml:${THEME_NAME}.xml
878a2b
            $(dirname $TEMPLATE)/GdmGreeterTheme.desktop:GdmGreeterTheme.desktop
878a2b
            $(dirname $TEMPLATE)/icon-language.png:icon-language.png
878a2b
            $(dirname $TEMPLATE)/icon-reboot.png:icon-reboot.png
878a2b
            $(dirname $TEMPLATE)/icon-session.png:icon-session.png
878a2b
            $(dirname $TEMPLATE)/icon-shutdown.png:icon-shutdown.png
878a2b
            "
878a2b
            ;;
878a2b
            
878a2b
        Kdm )
878a2b
            FILES="\
2b0a79
            ${BRANDS}/Symbols/White/48/${BRAND_FILENAME}.png:${BRAND_FILENAME}-symbol.png
878a2b
            ${OUTPUT}/screenshot.png:screenshot.png
878a2b
            $(dirname $TEMPLATE)/GdmGreeterTheme.xml:${THEME_NAME}.xml
878a2b
            $(dirname $TEMPLATE)/GdmGreeterTheme.desktop:GdmGreeterTheme.desktop
878a2b
            "
878a2b
            ;;
878a2b
878a2b
        * )
878a2b
            cli_printMessage "`eval_gettext "The \\\"\\\$DM\\\" display manager is not supported yet."`" --as-error-line
878a2b
            ;;
878a2b
    esac
878a2b
878a2b
    for FILE in $FILES;do
878a2b
878a2b
        # Define source location.
878a2b
        SRC=$(echo $FILE | cut -d: -f1)
878a2b
878a2b
        # Define target location.
878a2b
        DST=${TMPDIR}/${THEME_NAME}/$(echo $FILE | cut -d: -f2)
878a2b
878a2b
        # Verify source files.
878a2b
        cli_checkFiles $SRC
878a2b
878a2b
        # Verify parent directory for target file.
878a2b
        if [[ ! -d $(dirname $DST) ]];then
878a2b
            mkdir -p $(dirname $DST)
878a2b
        fi
878a2b
878a2b
        # Copy files from source to target location.
878a2b
        cp ${SRC} ${DST}
878a2b
878a2b
        # Expand translation markers.
878a2b
        if [[ ${DST} =~ "\.(xml|desktop)$"  ]];then
878a2b
            cli_expandTMarkers "${DST}"
878a2b
        fi
878a2b
878a2b
    done
878a2b
878a2b
    # Move into temporal directory.
878a2b
    pushd $TMPDIR > /dev/null
878a2b
878a2b
    for RESOLUTION in $RESOLUTIONS;do
878a2b
878a2b
        # Verify background information. If it doesn't exist go on
878a2b
        # with the next one in the list.
878a2b
        if [[ ! -f $BGS/${RESOLUTION}-final.png ]];then
878a2b
            continue
878a2b
        fi
878a2b
878a2b
        # Print action message.
878a2b
        if [[ -f ${RESOLUTION}.tar.gz ]];then
878a2b
            cli_printMessage "${OUTPUT}/${RESOLUTION}.tar.gz" --as-updating-line
878a2b
        else
878a2b
            cli_printMessage "${OUTPUT}/${RESOLUTION}.tar.gz" --as-creating-line
878a2b
        fi
878a2b
878a2b
        # Copy background information.
878a2b
        cp $BGS/${RESOLUTION}-final.png ${THEME_NAME}/background.png
878a2b
878a2b
        # Create tar.gz file.
878a2b
        tar -czf ${RESOLUTION}.tar.gz ${THEME_NAME}
878a2b
878a2b
        # Move from temporal directory to its final location.
878a2b
        mv ${RESOLUTION}.tar.gz ${OUTPUT}
878a2b
878a2b
    done
878a2b
878a2b
    # Return to where we were initially.
878a2b
    popd > /dev/null
878a2b
878a2b
    # Remove temporal directory.
878a2b
    rm -r ${TMPDIR}
878a2b
878a2b
}