]>
git.ipfire.org Git - ipfire-3.x.git/blob - initscripts/functions
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007, 2008 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 # Partly based on scripts by DJ Lucas - dj@linuxfromscratch.org
26 DISTRO
="$(</etc/system-release)" # The distro name
27 DISTRO_CONTACT
="http://bugtracker.ipfire.org" # Bug report address
29 # This sets default terminal options.
30 # stty sane - this has been removed as nobody recalls
31 # the reason for it in the first place - if no problems arize,
32 # then it will be removed completely at a later date.
34 # Setup default values for the environment
37 # If we boot, we should only allow the
38 # use tools that are available in /bin:/sbin
39 if [ -n "${UPSTART_JOB}" ]; then
43 # Find current screen size
44 if [ -z "${COLUMNS}" ]; then
46 COLUMNS
=${COLUMNS##* }
49 # When using remote connections, such as a serial port, stty size returns 0
50 if [ "${COLUMNS}" = "0" ]; then
54 ## Measurements for positioning result messages
55 COL
=$
((${COLUMNS} - 8))
58 # Set Cursur Position Commands, used via echo -e
59 SET_COL
="\\033[${COL}G" # at the $COL char
60 SET_WCOL
="\\033[${WCOL}G" # at the $WCOL char
61 CURS_UP
="\\033[1A\\033[0G" # Up one line, at the 0'th char
64 CLR_NORM_BLK
="\\033[0;30m" # black
65 CLR_NORM_RED
="\\033[0;31m" # red
66 CLR_NORM_GRN
="\\033[0;32m" # green
67 CLR_NORM_YEL
="\\033[0;33m" # yellow
68 CLR_NORM_BLU
="\\033[0;34m" # blue
69 CLR_NORM_MAG
="\\033[0;35m" # magenta
70 CLR_NORM_CYN
="\\033[0;36m" # cyan
71 CLR_NORM_WHT
="\\033[0;37m" # white
72 CLR_NORM_GRY
="\\033[0;39m" # grey
75 CLR_BOLD_BLK
="\\033[1;30m" # black
76 CLR_BOLD_RED
="\\033[1;31m" # red
77 CLR_BOLD_GRN
="\\033[1;32m" # green
78 CLR_BOLD_YEL
="\\033[1;33m" # yellow
79 CLR_BOLD_BLU
="\\033[1;34m" # blue
80 CLR_BOLD_MAG
="\\033[1;35m" # magenta
81 CLR_BOLD_CYN
="\\033[1;36m" # cyan
82 CLR_BOLD_WHT
="\\033[1;37m" # white
83 CLR_BOLD_GRY
="\\033[1;39m" # grey
86 CLR_BACK_BLK
="\\033[40m" # black
87 CLR_BACK_RED
="\\033[41m" # red
88 CLR_BACK_GRN
="\\033[42m" # green
89 CLR_BACK_YEL
="\\033[43m" # yellow
90 CLR_BACK_BLU
="\\033[44m" # blue
91 CLR_BACK_MAG
="\\033[45m" # magenta
92 CLR_BACK_CYN
="\\033[46m" # cyan
93 CLR_BACK_WHT
="\\033[47m" # white
104 BRACKET_L
="${CLR_BOLD_BLU}[${NORMAL}"
105 BRACKET_R
="${CLR_BOLD_BLU}]${NORMAL}"
107 # Define custom colors used in messages printed to the screen
108 BRACKET
=${CLR_BOLD_BLU} # Blue
109 FAILURE
=${CLR_BOLD_RED} # Red
110 INFO
=${CLR_BOLD_CYN} # Cyan
111 NORMAL
=${CLR_NORM_GRY} # Grey
112 SUCCESS
=${CLR_BOLD_GRN} # Green
113 WARNING
=${CLR_BOLD_YEL} # Yellow
115 # Prefix boot messages for easier reading on framebuffer consoles
116 PREFIX_SUCCESS
=" ${SUCCESS}*${NORMAL} "
117 PREFIX_WARNING
="${WARNING}**${NORMAL} "
118 PREFIX_FAILURE
="${FAILURE}***${NORMAL}"
120 welcome_message
="Welcome to ${INFO}${DISTRO}${NORMAL}"
121 welcome_message_length
=$
((${#DISTRO} + 11))
123 # Error message displayed when a script's exit value is not zero
125 # ${link} and ${error_value} are defined by the rc script
126 echo -e "${FAILURE}FAILURE: You should not be reading this error message."
128 echo -e -n "${FAILURE}It means that an unforseen error took place in"
129 echo -e -n "${INFO} ${link}"
130 echo -e "${FAILURE},"
131 echo -e "${FAILURE}which exited with a return value of ${error_value}."
133 echo -e -n "${FAILURE}If you are able to track this error down to a bug"
134 echo -e "${FAILURE}in one of the files"
135 echo -e -n "provided by ${INFO}${DISTRO}${FAILURE}, "
136 echo -e -n "${FAILURE}please be so kind to inform us at "
137 echo -e "${INFO}${DISTRO_CONTACT}${FAILURE}.${NORMAL}"
139 echo -e "${INFO}Press Enter to continue..."
144 ################################################################################
145 # log_success_msg() #
146 # Usage: log_success_msg [$MESSAGE | "message"] #
148 # Purpose: Print a successful status message to the screen and optionally #
151 # Inputs: accepts one string value, either a quoted string or optionally #
152 # the value of $MESSAGE if set in the running environment. #
154 # Return values: Not used #
155 ################################################################################
157 echo -n -e "${PREFIX_SUCCESS}${INDENT}${@}"
158 echo -e "${SET_COL}${BRACKET}[${SUCCESS} OK ${BRACKET}]${NORMAL}"
161 ################################################################################
162 # log_failure_msg() #
163 # Usage: log_failure_msg [$MESSAGE | "message"] #
165 # Purpose: Print a failure status message to the screen and optionally #
168 # Inputs: accepts one string value, either a quoted string or optionally #
169 # the value of $MESSAGE if set in the running environment. #
171 # Return values: Not used #
172 ################################################################################
174 echo -n -e "${PREFIX_FAILURE}${INDENT}${@}"
175 echo -e "${SET_COL}${BRACKET}[${FAILURE} FAIL ${BRACKET}]${NORMAL}"
178 ################################################################################
179 # log_warning_msg() #
180 # Usage: log_warning_msg [$MESSAGE | "message"] #
182 # Purpose: Print a warning status message to the screen and optionally #
185 # Inputs: accepts one string value, either a quoted string or optionally #
186 # the value of $MESSAGE if set in the running environment. #
188 # Return values: Not used #
189 ################################################################################
191 echo -n -e "${PREFIX_WARNING}${INDENT}${@}"
192 echo -e "${SET_COL}${BRACKET}[${WARNING} WARN ${BRACKET}]${NORMAL}"
195 ############################## evaluate_retval() ###############################
196 # evaluate_retval requires that you pass exactly one evaluation parameter of #
197 # (start, stop, other) based on the previous action that is being evaluated. #
198 # This function is intended for use with start_daemon and killproc to #
199 # interpret the LSB exit codes properly, othewise the checks only for success #
201 ################################################################################
203 local error_value
="${?}"
205 # Handle LSB defined return values
208 case "${error_value}" in
210 log_success_msg
"Starting ${MESSAGE} "
211 return "${error_value}"
214 log_failure_msg
"Starting ${MESSAGE} Error: Invalid argument!"
215 return "${error_value}"
218 log_failure_msg
"Starting ${MESSAGE} Error: Not available!"
219 return "${error_value}"
222 log_failure_msg
"Starting ${MESSAGE} Error: General failure!"
223 return "${error_value}"
229 case "${error_value}" in
231 log_success_msg
"Stopping ${MESSAGE} "
232 return "${error_value}"
235 log_failure_msg
"Stopping ${MESSAGE} Error: Invalid argument!"
236 return "${error_value}"
239 log_failure_msg
"Stopping ${MESSAGE} Error: Not available!"
240 return "${error_value}"
243 log_warning_msg
"Stopping ${MESSAGE} Warning: Not running!"
244 return "${error_value}"
247 log_failure_msg
"Stopping ${MESSAGE} Error: General failure!"
248 return "${error_value}"
254 message
="Forcefully reloading "
262 message
="Restarting "
266 message
="Trying restart "
270 # $message or $MESSAGE must be set, but not both in order
271 # to use the 'standard' target.
275 # Print messages for the generic force-reload, reload, restart,
276 # and try-restart targets
277 if [ "${error_value}" = "0" ]; then
278 log_success_msg
"${message}${MESSAGE} "
279 return "${error_value}"
281 log_failure_msg
"${message}${MESSAGE} "
282 return "${error_value}"