diff --git a/Scripts/Bash/Functions/cli_doParseArguments.sh b/Scripts/Bash/Functions/cli_doParseArguments.sh new file mode 100755 index 0000000..e77d33d --- /dev/null +++ b/Scripts/Bash/Functions/cli_doParseArguments.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# +# cli_doParseArguments.sh -- This function uses getopt(1) to parse +# optional arguments passed to centos-art.sh script. +# +# Copyright (C) 2009, 2010 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id: cli_doParseArguments.sh 466 2010-11-10 11:39:46Z al $ +# ---------------------------------------------------------------------- + +function cli_doParseArguments { + + # Reset positional parameters using optional arguments. + eval set -- "$ARGUMENTS" + + # Parse optional arguments using getopt. + ARGUMENTS=$(getopt -o "$ARGSS" -l "$ARGSL" -n $CLINAME -- "$@") + + # Be sure getout parsed arguments successfully. + if [[ $? != 0 ]]; then + cli_printMessage "$(caller)" 'AsToKnowMoreLine' + fi + +} diff --git a/Scripts/Bash/Functions/cli_doParseArgumentsReDef.sh b/Scripts/Bash/Functions/cli_doParseArgumentsReDef.sh new file mode 100755 index 0000000..113fc6d --- /dev/null +++ b/Scripts/Bash/Functions/cli_doParseArgumentsReDef.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# +# cli_doParseArgumentsReDef.sh -- This function initializes/reset +# positional parameters based on ARGUMENTS variable. +# +# Copyright (C) 2009, 2010 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function cli_doParseArgumentsReDef { + + local ARG + + # Clean up arguments global variable. + ARGUMENTS='' + + # Fill up arguments global variable with current positional + # parameter information. + for ARG in "$@"; do + ARGUMENTS="$ARGUMENTS \"$ARG\"" + done + +} diff --git a/Scripts/Bash/Functions/cli_getActionArguments.sh b/Scripts/Bash/Functions/cli_getActionArguments.sh new file mode 100755 index 0000000..9a55b1b --- /dev/null +++ b/Scripts/Bash/Functions/cli_getActionArguments.sh @@ -0,0 +1,90 @@ +#!/bin/bash +# +# cli_getActionArguments.sh -- This function initializes the action +# name and value used by functionalities to perform their goals. +# +# Copyright (C) 2009, 2010 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function cli_getActionArguments { + + # Set command-line arguments for processing using positional + # parameters variables. + eval set -- "$ARGUMENTS" + + # Define function name (FUNCNAM) variable from first command-line + # argument. As convenction we use the first argument to determine + # the exact name of functionality to call. Later we use action + # name (ACTIONNAM) and action value (ACTIONVAL) to know, inside + # functionality defined by FUNCNAME, the exact action to perform. + FUNCNAM=$(cli_getRepoName "$1" 'f') + + # Define action name (ACTIONNAM) and action value (ACTIONVAL) + # variables passed as second argument to the command line + # interface when the format is `--option=value' without the value + # # part. + if [[ "$2" =~ '^--[a-z-]+=.+$' ]];then + + # Define action name passed in the second argument. + ACTIONNAM=$(echo "$2" | cut -d = -f1) + + # Define action value passed in the second argument. + ACTIONVAL=$(echo "$2" | cut -d = -f2-) + + # Define action name (ACTIONNAM), and action value (ACTIONVAL) + # variables passed as second argument to the command line + # interface when the format is `--option' without the value part. + elif [[ "$2" =~ '^--[a-z-]+=?$' ]];then + + # Define action name passed in the second argument. + ACTIONNAM=$(echo "$2" | cut -d = -f1) + + # Define action value passed in the second argument. There is + # no action value (ACTIONVAL) entered from command-line here. + # To find out which action value to use, check current working + # directory, and if inside the repository, use current working + # directory as ACTIONVAL default value. + if [[ $(pwd) =~ '^/home/centos/artwork' ]];then + ACTIONVAL=$(pwd) + fi + + # Define default action when second argument is wrongly specified, + # or not specified at all. + else + cli_printMessage "`gettext "Missing arguments."`" 'AsErrorLine' + cli_printMessage "$(caller)" 'AsToKnowMoreLine' + fi + + # Check action value passed in the second argument. + cli_checkActionArguments + + # Remove the first and second arguments passed to centos-art.sh + # command-line in order to build optional arguments, they are + # already set in FUNCNAM, ACTIONNAM, and ACTIONVAL variables, so + # we remove it from command-line arguments in order for getopt to + # interpret it not. Now, what was preivously set on $2 is now at + # $1, what was previously set on $3 is now set at $2, and so on. + shift 2 + + # Redefine positional parameters stored inside ARGUMENTS variable. + cli_doParseArgumentsReDef "$@" + +} diff --git a/Scripts/Bash/Functions/cli_getFilesList.sh b/Scripts/Bash/Functions/cli_getFilesList.sh new file mode 100755 index 0000000..d7ea10a --- /dev/null +++ b/Scripts/Bash/Functions/cli_getFilesList.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# +# cli_getFilesList.sh -- This function defines the list of FILES to +# process. +# +# Copyright (C) 2009, 2010 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function cli_getFilesList { + + # Define list of html files to process using action value as + # reference. + if [[ -d $ACTIONVAL ]];then + FILES=$(find $ACTIONVAL -regextype posix-egrep -type f -regex "^${REGEX}$") + elif [[ -f $ACTIONVAL ]];then + FILES=$ACTIONVAL + fi + +}