beb384
Add `init.sh' file to `Functions/Commons' directory.
@@ -0,0 +1,132 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# init.sh -- This function initiates the application's command-line
|
4
|
+
# interface. Variables defined in this function are accesible by all
|
5
|
+
# other functions. The cli function is the first script executed by
|
6
|
+
# the application command-line onces invoked.
|
7
|
+
#
|
8
|
+
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
|
9
|
+
#
|
10
|
+
# This program is free software; you can redistribute it and/or modify
|
11
|
+
# it under the terms of the GNU General Public License as published by
|
12
|
+
# the Free Software Foundation; either version 2 of the License, or (at
|
13
|
+
# your option) any later version.
|
14
|
+
#
|
15
|
+
# This program is distributed in the hope that it will be useful, but
|
16
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
18
|
+
# General Public License for more details.
|
19
|
+
#
|
20
|
+
# You should have received a copy of the GNU General Public License
|
21
|
+
# along with this program; if not, write to the Free Software
|
22
|
+
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
23
|
+
#
|
24
|
+
# ----------------------------------------------------------------------
|
25
|
+
# $Id$
|
26
|
+
# ----------------------------------------------------------------------
|
27
|
+
|
28
|
+
function init {
|
29
|
+
|
30
|
+
# Initialize global variables.
|
31
|
+
local CLI_FUNCNAME=''
|
32
|
+
local CLI_FUNCDIRNAM=''
|
33
|
+
local CLI_FUNCSCRIPT=''
|
34
|
+
local ARGUMENTS=''
|
35
|
+
|
36
|
+
# Initialize default value to filter flag. The filter flag
|
37
|
+
# (--filter) is used mainly to reduce the number of files to
|
38
|
+
# process. The value of this variable is interpreted as
|
39
|
+
# egrep-posix regular expression. By default, everything matches.
|
40
|
+
local FLAG_FILTER='.+'
|
41
|
+
|
42
|
+
# Initialize default value to verbosity flag. The verbosity flag
|
43
|
+
# (--quiet) controls whether centos-art.sh script prints messages
|
44
|
+
# or not. By default, all messages are printed out.
|
45
|
+
local FLAG_QUIET='false'
|
46
|
+
|
47
|
+
# Initialize default value to answer flag. The answer flag
|
48
|
+
# (--answer-yes) controls whether centos-art.sh script does or
|
49
|
+
# does not pass confirmation request points. By default, it
|
50
|
+
# doesn't.
|
51
|
+
local FLAG_ANSWER='false'
|
52
|
+
|
53
|
+
# Initialize default value to don't commit changes flag. The don't
|
54
|
+
# commit changes flag (--dont-commit-changes) controls whether
|
55
|
+
# centos-art.sh script syncronizes changes between the central
|
56
|
+
# repository and the working copy. By default, it does.
|
57
|
+
local FLAG_DONT_COMMIT_CHANGES='false'
|
58
|
+
|
59
|
+
# Initialize list of common functionalities to load.
|
60
|
+
local FILES=$(ls ${CLI_FUNCDIR}/Commons/*.sh)
|
61
|
+
|
62
|
+
# Initialize common functionalities.
|
63
|
+
for FILE in ${FILES};do
|
64
|
+
if [[ -x ${FILE} ]];then
|
65
|
+
. ${FILE}
|
66
|
+
export -f $(grep '^function ' ${FILE} | cut -d' ' -f2)
|
67
|
+
else
|
68
|
+
echo "`eval_gettext "The \\\$FILE needs to have execution rights."`"
|
69
|
+
exit
|
70
|
+
fi
|
71
|
+
done
|
72
|
+
|
73
|
+
# Trap signals in order to terminate the script execution
|
74
|
+
# correctly (e.g., removing all temporal files before leaving).
|
75
|
+
# Trapping the exit signal seems to be enough by now, since it is
|
76
|
+
# always present as part of the script execution flow. Each time
|
77
|
+
# the centos-art.sh script is executed it will inevitably end with
|
78
|
+
# an EXIT signal at some point of its execution, even if it is
|
79
|
+
# interrupted in the middle of its execution (e.g., through
|
80
|
+
# `Ctrl+C').
|
81
|
+
trap cli_terminateScriptExecution 0
|
82
|
+
|
83
|
+
# Redefine ARGUMENTS variable using current positional parameters.
|
84
|
+
cli_parseArgumentsReDef "$@"
|
85
|
+
|
86
|
+
# Check function name. The function name is critical for
|
87
|
+
# centos-art.sh script to do something coherent. If it is not
|
88
|
+
# provided, execute the help functionality and end script
|
89
|
+
# execution.
|
90
|
+
if [[ ! "$1" ]] || [[ ! "$1" =~ '^[[:alpha:]]' ]];then
|
91
|
+
echo 'No functionality passed as first argument.'
|
92
|
+
# exec ${CLI_BASEDIR}/${CLI_NAME}.sh help
|
93
|
+
exit
|
94
|
+
fi
|
95
|
+
|
96
|
+
# Define function name (CLI_FUNCNAME) using the first argument in
|
97
|
+
# the command-line.
|
98
|
+
CLI_FUNCNAME=$(cli_getRepoName $1 -f | cut -d '-' -f 1)
|
99
|
+
|
100
|
+
# Define function directory.
|
101
|
+
CLI_FUNCDIRNAM=$(cli_getRepoName $CLI_FUNCNAME -d)
|
102
|
+
|
103
|
+
# Define function file name.
|
104
|
+
CLI_FUNCSCRIPT=${CLI_FUNCDIR}/${CLI_FUNCDIRNAM}/${CLI_FUNCNAME}.sh
|
105
|
+
|
106
|
+
# Check function script execution rights.
|
107
|
+
cli_checkFiles "${CLI_FUNCSCRIPT}" --execution
|
108
|
+
|
109
|
+
# Remove the first argument passed to centos-art.sh command-line
|
110
|
+
# in order to build optional arguments inside functionalities. We
|
111
|
+
# start counting from second argument (inclusive) on.
|
112
|
+
shift 1
|
113
|
+
|
114
|
+
# Redefine ARGUMENTS using current positional parameters.
|
115
|
+
cli_parseArgumentsReDef "$@"
|
116
|
+
|
117
|
+
# Define default text editors used by centos-art.sh script.
|
118
|
+
if [[ ! "$EDITOR" =~ '/usr/bin/(vim|emacs|nano)' ]];then
|
119
|
+
EDITOR='/usr/bin/vim'
|
120
|
+
fi
|
121
|
+
|
122
|
+
# Check text editor execution rights.
|
123
|
+
cli_checkFiles $EDITOR --execution
|
124
|
+
|
125
|
+
# Go for function initialization. Keep the cli_exportFunctions
|
126
|
+
# function calling after all variables and arguments definitions.
|
127
|
+
cli_exportFunctions "${CLI_FUNCDIR}/${CLI_FUNCDIRNAM}"
|
128
|
+
|
129
|
+
# Execute function.
|
130
|
+
eval $CLI_FUNCNAME
|
131
|
+
|
132
|
+
}
|