Blame tcar-scripts/tcar_getPathComponent.sh

Alain Reguera Delgado 66223d
#!/bin/bash
Alain Reguera Delgado 66223d
######################################################################
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
#   tcar_getPathComponent.sh -- This function standardizes the way
Alain Reguera Delgado 66223d
#   directory structures are organized inside the working copy of
Alain Reguera Delgado 66223d
#   CentOS Artwork Repository. You can use this function to retrieve
Alain Reguera Delgado 66223d
#   information from paths (e.g., releases, architectures and theme
Alain Reguera Delgado 66223d
#   artistic motifs) or the patterns used to build the paths.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
#   Written by:
Alain Reguera Delgado 66223d
#   * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 66223d
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 66223d
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 66223d
# your option) any later version.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 66223d
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 66223d
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 66223d
# General Public License for more details.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 66223d
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 66223d
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
######################################################################
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
function tcar_getPathComponent {
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
    # Define release pattern.
Alain Reguera Delgado 66223d
    local VERSION="(([[:digit:]]+)(\.([[:digit:]]+))?)"
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
    # Define architecture pattern. Make it match the architectures the
Alain Reguera Delgado 66223d
    # CentOS distribution is able to be installed on.
Alain Reguera Delgado 66223d
    local ARCHITECTURE="(i386|x86_64)"
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
    # Define regular expression pattern that match the theme artistic
Alain Reguera Delgado 66223d
    # motif component inside the path strings.
Alain Reguera Delgado 66223d
    local THEME_MOTIF="Themes/Motifs/(([[:alnum:]]+)/(${VERSION}))"
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
    # Define location we want to apply verifications to.
Alain Reguera Delgado e1d168
    local LOCATION=${1}
Alain Reguera Delgado e1d168
Alain Reguera Delgado e1d168
    # Remove location from positional parameters, so only the option
Alain Reguera Delgado e1d168
    # remain.
Alain Reguera Delgado e1d168
    shift 1
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
    # Look for options passed through positional parameters.
Alain Reguera Delgado 66223d
    while true;do
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
        case "${1}" in
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
            --release )
Alain Reguera Delgado 66223d
                echo "${LOCATION}" | egrep "${VERSION}" | sed -r "s!.*/${VERSION}/.*!\1!"
Alain Reguera Delgado 66223d
                shift 1
Alain Reguera Delgado 66223d
                break
Alain Reguera Delgado 66223d
                ;;
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
            --release-major )
Alain Reguera Delgado 66223d
                echo "${LOCATION}" | egrep "${VERSION}" | sed -r "s!.*/${VERSION}/.*!\2!"
Alain Reguera Delgado 66223d
                shift 1
Alain Reguera Delgado 66223d
                break
Alain Reguera Delgado 66223d
                ;;
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
            --release-minor )
Alain Reguera Delgado 66223d
                echo "${LOCATION}" | egrep "${VERSION}" | sed -r "s!.*/${VERSION}/.*!\4!"
Alain Reguera Delgado 66223d
                shift 1
Alain Reguera Delgado 66223d
                break
Alain Reguera Delgado 66223d
                ;;
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
            --release-pattern )
Alain Reguera Delgado 66223d
                echo "${VERSION}"
Alain Reguera Delgado 66223d
                shift 1
Alain Reguera Delgado 66223d
                break
Alain Reguera Delgado 66223d
                ;;
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
            --architecture )
Alain Reguera Delgado 66223d
                echo "${LOCATION}" | egrep "${ARCHITECTURE}" | sed -r "s!${ARCHITECTURE}!\1!"
Alain Reguera Delgado 66223d
                shift 1
Alain Reguera Delgado 66223d
                break
Alain Reguera Delgado 66223d
                ;;
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
            --architecture-pattern )
Alain Reguera Delgado 66223d
                echo "${ARCHITECTURE}"
Alain Reguera Delgado 66223d
                shift 1
Alain Reguera Delgado 66223d
                break
Alain Reguera Delgado 66223d
                ;;
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
            --motif )
Alain Reguera Delgado 66223d
                echo "${LOCATION}" | egrep "${THEME_MOTIF}" | sed -r "s!.*${THEME_MOTIF}.*!\1!"
Alain Reguera Delgado 66223d
                shift 1
Alain Reguera Delgado 66223d
                break
Alain Reguera Delgado 66223d
                ;;
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
            --motif-name )
Alain Reguera Delgado 66223d
                echo "${LOCATION}" | egrep "${THEME_MOTIF}" | sed -r "s!.*${THEME_MOTIF}.*!\2!"
Alain Reguera Delgado 66223d
                shift 1
Alain Reguera Delgado 66223d
                break
Alain Reguera Delgado 66223d
                ;;
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
            --motif-version )
Alain Reguera Delgado 66223d
                echo "${LOCATION}" | egrep "${THEME_MOTIF}" | sed -r "s!.*${THEME_MOTIF}.*!\3!"
Alain Reguera Delgado 66223d
                shift 1
Alain Reguera Delgado 66223d
                break
Alain Reguera Delgado 66223d
                ;;
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
            --motif-pattern )
Alain Reguera Delgado 66223d
                echo "${THEME_MOTIF}"
Alain Reguera Delgado 66223d
                shift 1
Alain Reguera Delgado 66223d
                break
Alain Reguera Delgado 66223d
                ;;
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
            --repo-dir )
Alain Reguera Delgado 66223d
                echo "${LOCATION}" | sed "s,${TCAR_USER_WRKDIR}/,,"
Alain Reguera Delgado 66223d
                shift 1
Alain Reguera Delgado 66223d
                break
Alain Reguera Delgado 66223d
                ;;
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
        esac
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
    done
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
}