Blame Scripts/Bash/Functions/Identity/identity_renderDm.sh

ae8a10
#!/bin/bash
ae8a10
#
ce597a
# identity_renderDm.sh -- This function collects Display Manager (DM)
ce597a
# required files and creates a tar.gz package that groups them all
ce597a
# together. Use this function as last-rendition action for Gdm and Kdm
ce597a
# base-rendition actions.
eb0e14
#
7cd8e9
# Usage:
eb0e14
#
d856c1
#   ACTIONS[1]='LAST:renderDm:TYPE:RESOLUTION'
eb0e14
#
7cd8e9
# Where:
eb0e14
#
643925
#   TYPE can be either `Gdm' or `Kdm'. These values correspond to the
d856c1
#   directory names used to store related design models.
eb0e14
#
d856c1
#   RESOLUTION represents the screen resolution tar.gz files are
d856c1
#   produced for (e.g., 800x600, 1024x768, 2048x1536, etc.). 
eb0e14
#
d856c1
# In order to produce tar.gz files correctly, both screen resolution
d856c1
# definition inside pre-rendition configuration script and background
d856c1
# name inside theme directory structure need to match one another.  If
d856c1
# one screen resolution is defined correctly, but there is no
d856c1
# background information for it, the related tar.gz file is not
d856c1
# produced and the next file in the list of files to process is
d856c1
# evaluated.
ae8a10
#
9f5f2e
# Copyright (C) 2009-2011 Alain Reguera Delgado
ae8a10
# 
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.
ae8a10
# 
ae8a10
# This program is distributed in the hope that it will be useful, but
ae8a10
# WITHOUT ANY WARRANTY; without even the implied warranty of
ae8a10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ae8a10
# General Public License for more details.
ae8a10
#
ae8a10
# You should have received a copy of the GNU General Public License
ae8a10
# along with this program; if not, write to the Free Software
ae8a10
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
ae8a10
# USA.
ae8a10
# 
ae8a10
# ----------------------------------------------------------------------
ae8a10
# $Id$
ae8a10
# ----------------------------------------------------------------------
ae8a10
ce597a
function identity_renderDm {
ae8a10
d856c1
    local -a SRC
d856c1
    local -a DST
eb0e14
    local DM=''
d856c1
    local TGZ=''
d856c1
    local COUNT=0
d856c1
    local RESOLUTION=''
d856c1
    local RESOLUTIONS=''
ae8a10
15b1d2
    # Get display manager passed from render.conf.sh pre-rendition
ae8a10
    # configuration script.
c979f9
    DM=$(identity_renderConfigOption "${ACTION}" '2')
643925
 
d856c1
    # Sanitate display manager passed from render.conf.sh
d856c1
    # pre-rendition configuration script. Whatever value be retrived
d856c1
    # as display manager configuration option is converted to
643925
    # uppercase in order to match either Gdm or Kdm design model
d856c1
    # directory structures.
643925
    DM=$(cli_getRepoName "$DM" 'd')
ae8a10
15b1d2
    # Get screen resolutions passed from render.conf.sh pre-rendition
eb0e14
    # configuration script.
c979f9
    RESOLUTIONS=$(identity_renderConfigOption "${ACTION}" '3')
ae8a10
d856c1
    # Check screen resolutions passed from render.conf.sh
d856c1
    # pre-rendition configuration script.
eb0e14
    if [[ "$RESOLUTIONS" == '' ]];then
07c2fe
        cli_printMessage "`gettext "There is no resolution information to process."`" 'AsErrorLine'
ae8a10
        cli_printMessage $(caller) "AsToKnowMoreLine"
ae8a10
    fi
ae8a10
d856c1
    # Define source files using absolute paths.
a77db3
    SRC[0]=$(cli_getRepoTLDir)/Identity/Brands/Img/Symbol/48.png
643925
    SRC[1]=${OUTPUT}/release.png
643925
    SRC[2]=${OUTPUT}/screenshot.png
643925
    SRC[3]=$(cli_getRepoTLDir)/Identity/Themes/Models/${THEMEMODEL}/Distro/${DM}/GdmGreeterTheme.xml
643925
    SRC[4]=$(cli_getRepoTLDir)/Identity/Themes/Models/${THEMEMODEL}/Distro/${DM}/GdmGreeterTheme.desktop
d856c1
    SRC[5]=$(cli_getRepoTLDir)/Identity/Themes/Motifs/$(cli_getPathComponent '--theme')/Backgrounds/Img/Png
643925
    SRC[6]=$(cli_getRepoTLDir)/Identity/Themes/Models/${THEMEMODEL}/Distro/${DM}/icon-language.png
643925
    SRC[7]=$(cli_getRepoTLDir)/Identity/Themes/Models/${THEMEMODEL}/Distro/${DM}/icon-reboot.png
643925
    SRC[8]=$(cli_getRepoTLDir)/Identity/Themes/Models/${THEMEMODEL}/Distro/${DM}/icon-session.png
643925
    SRC[9]=$(cli_getRepoTLDir)/Identity/Themes/Models/${THEMEMODEL}/Distro/${DM}/icon-shutdown.png
d856c1
d856c1
    # Define name used as temporal holder to build tar.gz file. 
d856c1
    TGZ=$(cli_getPathComponent '--theme-name')
d856c1
d856c1
    # Define target files using relative paths.
d856c1
    DST[0]=${TGZ}/centos-symbol.png
d856c1
    DST[1]=${TGZ}/centos-release.png
d856c1
    DST[2]=${TGZ}/screenshot.png
d856c1
    DST[3]=${TGZ}/${TGZ}.xml
d856c1
    DST[4]=${TGZ}/GdmGreeterTheme.desktop
d856c1
    DST[5]=${TGZ}/background.png
d856c1
    DST[6]=${TGZ}/icon-language.png
d856c1
    DST[7]=${TGZ}/icon-reboot.png
d856c1
    DST[8]=${TGZ}/icon-session.png
d856c1
    DST[9]=${TGZ}/icon-shutdown.png
d856c1
d856c1
    # Move into the working directory.
643925
    pushd ${OUTPUT} > /dev/null
d856c1
d856c1
    # Create directory used as temporal holder to build tar.gz file.
d856c1
    if [[ ! -d ${TGZ} ]];then
d856c1
        mkdir ${TGZ}
eb0e14
    fi
ae8a10
d856c1
    for RESOLUTION in $RESOLUTIONS;do
d991f5
d856c1
        while [[ $COUNT -lt ${#SRC[*]} ]];do
ae8a10
d856c1
            if [[ $COUNT -eq 5 ]];then
ae8a10
d856c1
                # Redefine background information using resolution as
d856c1
                # reference. Avoid concatenation.
d856c1
                SRC[$COUNT]=$(echo "${SRC[$COUNT]}" | cut -d/ -f-13)/${RESOLUTION}-final.png
ae8a10
d856c1
                # If background information defined inside
d856c1
                # pre-rendition configuration script doesn't match
d856c1
                # background information inside theme-specific
d856c1
                # backgrounds directory structure, try the next
d856c1
                # background definition.
d856c1
                if [[ ! -f ${SRC[$COUNT]} ]];then
d856c1
                    continue 2
d856c1
                fi
d856c1
        
d856c1
            elif [[ $COUNT =~ '^[6-9]$' ]];then
ae8a10
643925
                # If display manager is Kdm, then increment counter and
643925
                # resume the next iteration. Icons aren't used on Kdm,
d856c1
                # so there's no need to have them inside it.
643925
                if [[ $DM =~ '^Kdm$' ]];then
d856c1
                    COUNT=$(($COUNT + 1))
d856c1
                    continue
d856c1
                fi
ae8a10
d856c1
            fi
eb0e14
d856c1
            # Check existence of source files.
d856c1
            cli_checkFiles ${SRC[$COUNT]}
ae8a10
d856c1
            # Copy files from source to target location.
d856c1
            cp ${SRC[$COUNT]} ${DST[$COUNT]}
ae8a10
d856c1
            # Replace common translation markers from design model
d856c1
            # files with appropriate information.
d856c1
            if [[ $COUNT =~ '^(3|4)$'  ]];then
79e54d
                cli_replaceTMarkers "${DST[$COUNT]}"
8b5668
            fi
ae8a10
d856c1
            # Increment counter.
d856c1
            COUNT=$(($COUNT + 1))
ae8a10
d856c1
        done
ae8a10
d856c1
        # Reset counter.
d856c1
        COUNT=0
ae8a10
643925
        # Print action message.
643925
        cli_printMessage "${OUTPUT}/${RESOLUTION}.tar.gz" "AsCreatingLine"
ae8a10
d856c1
        # Create tar.gz file.
d856c1
        tar -czf "${RESOLUTION}.tar.gz" $TGZ
ae8a10
d856c1
    done
ae8a10
d856c1
    # Remove directory used as temporal holder to build targ.gz
d856c1
    # file.
d856c1
    rm -r $TGZ
ae8a10
d856c1
    # Remove release-specific images.
d856c1
    cli_printMessage "${SRC[1]}" "AsDeletingLine"
d856c1
    rm ${SRC[1]}
d856c1
    cli_printMessage "${SRC[2]}" "AsDeletingLine"
d856c1
    rm ${SRC[2]}
ec641d
d856c1
    # Return to where we were initially.
d856c1
    popd > /dev/null
d856c1
d856c1
    # Output division rule.
d856c1
    cli_printMessage '-' 'AsSeparatorLine'
ae8a10
ae8a10
}