Blame Scripts/CentOS-Art/Functions/cli_getPathComponent.sh

5b6935
#!/bin/bash
5b6935
#
a0d7a2
# cli_getPathComponent.sh -- This function standardizes the way
a0d7a2
# directory structures are organized inside the working copy of CentOS
a0d7a2
# Artwork Repository. You can use this function to retrive information
57dc44
# from paths (e.g., releases, architectures and theme artistic motifs)
57dc44
# or the patterns used to build the paths.
5b6935
#
2fe9b7
# 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
3b0984
# the Free Software Foundation; either version 2 of the License, or (at
3b0984
# 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
5b6935
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5b6935
# General Public License for more details.
5b6935
#
5b6935
# You should have received a copy of the GNU General Public License
5b6935
# along with this program; if not, write to the Free Software
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
5b6935
# ----------------------------------------------------------------------
5b6935
# $Id$
5b6935
# ----------------------------------------------------------------------
5b6935
78667f
function cli_getPathComponent {
5b6935
a0d7a2
    # Define short options.
a0d7a2
    local ARGSS=''
a0d7a2
a0d7a2
    # Define long options.
57dc44
    local ARGSL='release,release-major,release-minor,release-pattern,architecture,architecture-pattern,motif,motif-name,motif-release,motif-pattern'
a0d7a2
57dc44
    # Initialize ARGUMENTS with an empty value and set it as local
a0d7a2
    # variable to this function scope.
a0d7a2
    local ARGUMENTS=''
5b6935
5b6935
    # Define release pattern.
dd2477
    local RELEASE="(([[:digit:]]+)(\.([[:digit:]]+)){0,1})"
5b6935
7649f3
    # Define architecture pattern. Make it match the architectures the
7649f3
    # CentOS distribution is able to be installed on.
a0d7a2
    local ARCHITECTURE="(i386|x86_64)"
9e4cfb
57dc44
    # Define pattern for themes' artistic motifs.
57dc44
    local THEME_MOTIF="Identity/Images/Themes/(([[:alnum:]]+)/(${RELEASE}))"
a0d7a2
a0d7a2
    # Redefine ARGUMENTS variable using current positional parameters. 
793c4c
    cli_parseArgumentsReDef "$@"
a0d7a2
a0d7a2
    # Redefine ARGUMENTS variable using getopt output.
793c4c
    cli_parseArguments
a0d7a2
a0d7a2
    # Redefine positional parameters using ARGUMENTS variable.
a0d7a2
    eval set -- "$ARGUMENTS"
a0d7a2
a0d7a2
    # Define location we want to apply verifications to.
a0d7a2
    local LOCATION=$(echo $@ | sed -r 's!^.*--[[:space:]](.+)$!\1!')
a0d7a2
a0d7a2
    # Look for options passed through positional parameters.
a0d7a2
    while true;do
a0d7a2
a0d7a2
        case "$1" in
a0d7a2
a0d7a2
            --release )
a0d7a2
                echo "$LOCATION" | egrep "${RELEASE}" | sed -r "s!.*/${RELEASE}/.*!\1!"
4b745e
                shift 1
a0d7a2
                break
a0d7a2
                ;;
a0d7a2
a0d7a2
            --release-major )
a0d7a2
                echo "$LOCATION" | egrep "${RELEASE}" | sed -r "s!.*/${RELEASE}/.*!\2!"
4b745e
                shift 1
a0d7a2
                break
a0d7a2
                ;;
a0d7a2
a0d7a2
            --release-minor )
a0d7a2
                echo "$LOCATION" | egrep "${RELEASE}" | sed -r "s!.*/${RELEASE}/.*!\4!"
4b745e
                shift 1
a0d7a2
                break
a0d7a2
                ;;
a0d7a2
a0d7a2
            --release-pattern )
a0d7a2
                echo "${RELEASE}"
4b745e
                shift 1
a0d7a2
                break
a0d7a2
                ;;
a0d7a2
a0d7a2
            --architecture )
a0d7a2
                echo "$LOCATION" | egrep "${ARCHITECTURE}" | sed -r "s!${ARCHITECTURE}!\1!"
4b745e
                shift 1
a0d7a2
                break
a0d7a2
                ;;
a0d7a2
a0d7a2
            --architecture-pattern )
a0d7a2
                echo "${ARCHITECTURE}"
4b745e
                shift 1
a0d7a2
                break
a0d7a2
                ;;
a0d7a2
57dc44
            --motif )
57dc44
                echo "$LOCATION" | egrep "${THEME_MOTIF}" | sed -r "s!.*${THEME_MOTIF}.*!\1!"
4b745e
                shift 1
a0d7a2
                break
a0d7a2
                ;;
a0d7a2
57dc44
            --motif-name )
57dc44
                echo "$LOCATION" | egrep "${THEME_MOTIF}" | sed -r "s!.*${THEME_MOTIF}.*!\2!"
4b745e
                shift 1
a0d7a2
                break
a0d7a2
                ;;
a0d7a2
57dc44
            --motif-release )
57dc44
                echo "$LOCATION" | egrep "${THEME_MOTIF}" | sed -r "s!.*${THEME_MOTIF}.*!\3!"
4b745e
                shift 1
a0d7a2
                break
a0d7a2
                ;;
a0d7a2
57dc44
            --motif-pattern )
57dc44
                echo "${THEME_MOTIF}"
4b745e
                shift 1
a0d7a2
                break
a0d7a2
                ;;
a0d7a2
a0d7a2
        esac
a0d7a2
a0d7a2
    done
5b6935
}