Blame Scripts/tcar_getPathComponent.sh

Alain Reguera Delgado 66223d
#!/bin/bash
Alain Reguera Delgado 66223d
######################################################################
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado b33753
#   tcar - The CentOS Artwork Repository automation tool.
Alain Reguera Delgado b33753
#   Copyright © 2014 The CentOS Artwork SIG
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado b33753
#   This program is free software; you can redistribute it and/or
Alain Reguera Delgado b33753
#   modify it under the terms of the GNU General Public License as
Alain Reguera Delgado b33753
#   published by the Free Software Foundation; either version 2 of the
Alain Reguera Delgado b33753
#   License, or (at your option) any later version.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado b33753
#   This program is distributed in the hope that it will be useful,
Alain Reguera Delgado b33753
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado b33753
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado b33753
#   General Public License for more details.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado b33753
#   You should have received a copy of the GNU General Public License
Alain Reguera Delgado b33753
#   along with this program; if not, write to the Free Software
Alain Reguera Delgado b33753
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado b33753
#   Alain Reguera Delgado <al@centos.org.cu>
Alain Reguera Delgado b33753
#   39 Street No. 4426 Cienfuegos, Cuba.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
######################################################################
Alain Reguera Delgado 66223d
Alain Reguera Delgado b33753
# Standardize the way directory structures are organized inside the
Alain Reguera Delgado b33753
# working copy of CentOS Artwork Repository. You can use this function
Alain Reguera Delgado b33753
# to retrieve information from paths (e.g., releases, architectures
Alain Reguera Delgado b33753
# and theme artistic motifs) or the patterns used to build the paths.
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
}