2020set -e -o pipefail
2121
2222# Version control.
23- PROG_NAME=$( basename " $0 " )
24- PROG_VER =" 2.x.x"
23+ export PROG_NAME && PROG_NAME=$( basename " $0 " )
24+ export PROG_VERSION && PROG_VERSION =" 2.x.x"
2525
2626# Test mode.
2727DRYRUN=false
2828
29+ # Make sure only root can run this script.
30+ function requires_root() {
31+ if [[ " $( id -u) " -ne 0 ]]; then
32+ if ! hash sudo 2> /dev/null; then
33+ echo " ${PROG_NAME} command must be run as 'root' or with sudo."
34+ exit 1
35+ else
36+ # echo "Switching to root user to run this script."
37+ sudo -E " $0 " " $@ "
38+ exit 0
39+ fi
40+ fi
41+ }
42+
43+ requires_root " $@ "
44+
45+ # Export LEMPer Stack configuration.
46+ if [[ -f " /etc/lemper/lemper.conf" ]]; then
47+ # Clean environemnt first.
48+ # shellcheck source=/etc/lemper/lemper.conf
49+ # shellcheck disable=SC2046
50+ unset $( grep -v ' ^#' /etc/lemper/lemper.conf | grep -v ' ^\[' | sed -E ' s/(.*)=.*/\1/' | xargs)
51+
52+ # shellcheck source=/etc/lemper/lemper.conf
53+ # shellcheck disable=SC1094
54+ # shellcheck disable=SC1091
55+ source <( grep -v ' ^#' /etc/lemper/lemper.conf | grep -v ' ^\[' | sed -E ' s|^(.+)=(.*)$|: ${\1=\2}; export \1|g' )
56+ else
57+ echo " LEMPer Stack configuration required, but the file doesn't exist."
58+ echo " It should be created during installation process and placed under '/etc/lemper/lemper.conf'."
59+ exit 1
60+ fi
61+
62+ # Set default variables.
63+ LEMPER_USERNAME=${LEMPER_USERNAME:- " lemper" }
64+ LEMPER_PASSWORD=${LEMPER_PASSWORD:- " " }
65+ MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:- " " }
66+
67+ # Set CLI plugins directory.
68+ CLI_PLUGINS_DIR=" /etc/lemper/cli-plugins"
69+
2970# Color decorator.
30- RED=91
31- GREEN=92
32- YELLOW=93
71+ RED=31
72+ GREEN=32
73+ YELLOW=33
3374
3475# #
3576# Helper Functions.
@@ -108,54 +149,13 @@ function run() {
108149 fi
109150}
110151
111- # Make sure only root can run this script.
112- function requires_root() {
113- if [[ " $( id -u) " -ne 0 ]]; then
114- if ! hash sudo 2> /dev/null; then
115- echo " ${PROG_NAME} command must be run as 'root' or with sudo."
116- exit 1
117- else
118- # echo "Switching to root user to run this script."
119- sudo -E " $0 " " $@ "
120- exit 0
121- fi
122- fi
123- }
124-
125- requires_root " $@ "
126-
127- # Export LEMPer Stack configuration.
128- if [[ -f " /etc/lemper/lemper.conf" ]]; then
129- # Clean environemnt first.
130- # shellcheck source=/etc/lemper/lemper.conf
131- # shellcheck disable=SC2046
132- unset $( grep -v ' ^#' /etc/lemper/lemper.conf | grep -v ' ^\[' | sed -E ' s/(.*)=.*/\1/' | xargs)
133-
134- # shellcheck source=/etc/lemper/lemper.conf
135- # shellcheck disable=SC1094
136- # shellcheck disable=SC1091
137- source <( grep -v ' ^#' /etc/lemper/lemper.conf | grep -v ' ^\[' | sed -E ' s|^(.+)=(.*)$|: ${\1=\2}; export \1|g' )
138- else
139- echo " LEMPer Stack configuration required, but the file doesn't exist."
140- echo " It should be created during installation process and placed under '/etc/lemper/lemper.conf'."
141- exit 1
142- fi
143-
144- # Set default variables.
145- LEMPER_USERNAME=${LEMPER_USERNAME:- " lemper" }
146- LEMPER_PASSWORD=${LEMPER_PASSWORD:- " " }
147- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:- " " }
148-
149- # Set CLI plugins directory.
150- CLI_PLUGINS_DIR=" /etc/lemper/cli-plugins"
151-
152152# #
153153# Show usage
154154# output to STDERR.
155155# #
156156function cmd_help() {
157157 cat << - EOL
158- ${PROG_NAME} ${PROG_VER }
158+ ${PROG_NAME} ${PROG_VERSION }
159159Command line management tool for LEMPer Stack.
160160
161161Usage: ${PROG_NAME} [--version] [--help]
178178# Show version.
179179# #
180180function cmd_version() {
181- echo " ${PROG_NAME} version ${PROG_VER } "
181+ echo " ${PROG_NAME} version ${PROG_VERSION } "
182182}
183183
184184# #
@@ -204,10 +204,9 @@ function init_lemper_cli() {
204204 # Source the plugin executable file.
205205 # shellcheck disable=SC1090
206206 . " ${CLI_PLUGINS_DIR} /lemper-${CMD} " " $@ "
207- exit 0
208207 else
209- echo " ${PROG_NAME} : '${CMD} ' is not ${PROG_NAME} command"
210- echo " See '${PROG_NAME} --help' for more information"
208+ echo " ${PROG_NAME} : '${CMD} ' is not valid command. "
209+ echo " See '${PROG_NAME} --help' for more information. "
211210 exit 1
212211 fi
213212 ;;
0 commit comments