|
|
5b6935 |
#!/bin/bash
|
|
|
5b6935 |
#
|
|
|
5b6935 |
# cli_getPathComponent.sh -- This function outputs different parts
|
|
|
5b6935 |
# from path string. By default the full release information is output.
|
|
|
5b6935 |
#
|
|
|
5b6935 |
# Copyright (C) 2009-2011 Alain Reguera Delgado
|
|
|
5b6935 |
#
|
|
|
5b6935 |
# This program is free software; you can redistribute it and/or
|
|
|
5b6935 |
# modify it under the terms of the GNU General Public License as
|
|
|
5b6935 |
# published by the Free Software Foundation; either version 2 of the
|
|
|
5b6935 |
# License, or (at your option) any later version.
|
|
|
5b6935 |
#
|
|
|
5b6935 |
# This program is distributed in the hope that it will be useful, but
|
|
|
5b6935 |
# 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
|
|
|
5b6935 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
5b6935 |
# USA.
|
|
|
5b6935 |
#
|
|
|
5b6935 |
# ----------------------------------------------------------------------
|
|
|
5b6935 |
# $Id$
|
|
|
5b6935 |
# ----------------------------------------------------------------------
|
|
|
5b6935 |
|
|
|
5b6935 |
function cli_getPathComponent {
|
|
|
5b6935 |
|
|
|
5b6935 |
local -a PATTERN
|
|
|
5b6935 |
local RELEASE=''
|
|
|
5b6935 |
|
|
|
5b6935 |
# Define release pattern.
|
|
|
5b6935 |
PATTERN[0]="(([[:digit:]]+)(\.([[:digit:]]+)){,1})"
|
|
|
5b6935 |
|
|
|
5b6935 |
# Define architecture pattern.
|
|
|
5b6935 |
PATTERN[1]='(i386|x86_64)'
|
|
|
5b6935 |
|
|
|
5b6935 |
# Identify which part of the release we want to output.
|
|
|
5b6935 |
case "$2" in
|
|
|
5b6935 |
|
|
|
5b6935 |
'--arch' )
|
|
|
5b6935 |
RELEASE=$(echo "$1" | sed -r "s!.+/${PATTERN[0]}/${PATTERN[1]}/.+!\5!")
|
|
|
5b6935 |
;;
|
|
|
5b6935 |
|
|
|
5b6935 |
'--major-release' )
|
|
|
5b6935 |
RELEASE=$(echo "$1" | sed -r "s!.+/${PATTERN[0]}/.+!\2!")
|
|
|
5b6935 |
;;
|
|
|
5b6935 |
|
|
|
5b6935 |
'--minor-release' )
|
|
|
5b6935 |
RELEASE=$(echo "$1" | sed -r "s!.+/${PATTERN[0]}/.+!\4!")
|
|
|
5b6935 |
;;
|
|
|
5b6935 |
|
|
|
5b6935 |
'--verify-release' )
|
|
|
5b6935 |
# Verify release value against release pattern.
|
|
|
5b6935 |
if [[ ! $RELEASE =~ "^${PATTERN}$" ]];then
|
|
|
5b6935 |
cli_printMessage "`gettext "The release number \\\`\\\$RELEASE' is not valid."`" 'AsErrorLine'
|
|
|
5b6935 |
cli_printMessage "$(caller)" 'AsToKnowMoreLine'
|
|
|
5b6935 |
fi
|
|
|
5b6935 |
;;
|
|
|
5b6935 |
|
|
|
5b6935 |
'--release-pattern' )
|
|
|
5b6935 |
RELEASE=$(echo ${PATTERN[0]})
|
|
|
5b6935 |
;;
|
|
|
5b6935 |
|
|
|
5b6935 |
'--arch-pattern' )
|
|
|
5b6935 |
RELEASE=$(echo ${PATTERN[1]})
|
|
|
5b6935 |
;;
|
|
|
5b6935 |
|
|
|
5b6935 |
'--full-release' | * )
|
|
|
5b6935 |
# Define absolute path from which relase information is retrived.
|
|
|
5b6935 |
# As convenction, we use the first coincidence that match release
|
|
|
5b6935 |
# pattern.
|
|
|
5b6935 |
RELEASE=$(echo "$1" | sed -r "s!.+/${PATTERN[0]}/.+!\1!" )
|
|
|
5b6935 |
;;
|
|
|
5b6935 |
esac
|
|
|
5b6935 |
|
|
|
5b6935 |
# If no release information is found in the provided absolute
|
|
|
5b6935 |
# path, use zero as default release information.
|
|
|
5b6935 |
if [[ ! "$RELEASE" =~ "$PATTERN" ]];then
|
|
|
5b6935 |
RELEASE='0'
|
|
|
5b6935 |
fi
|
|
|
5b6935 |
|
|
|
5b6935 |
# Output release information.
|
|
|
5b6935 |
echo "$RELEASE"
|
|
|
5b6935 |
|
|
|
5b6935 |
}
|