--- /dev/null
+#!/bin/sh
+###############################################################################
+# #
+# IPFire.org - A linux based firewall #
+# Copyright (C) 2007, 2008 Michael Tremer & Christian Schmidt #
+# #
+# 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 3 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, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+#
+# Partly based on scripts by DJ Lucas - dj@linuxfromscratch.org
+#
+
+# Distro Information
+DISTRO="$(</etc/system-release)" # The distro name
+DISTRO_CONTACT="http://bugtracker.ipfire.org" # Bug report address
+
+# This sets default terminal options.
+# stty sane - this has been removed as nobody recalls
+# the reason for it in the first place - if no problems arize,
+# then it will be removed completely at a later date.
+
+# Setup default values for the environment
+umask 022
+
+# If we boot, we should only allow the
+# use tools that are available in /bin:/sbin
+if [ -n "${UPSTART_JOB}" ]; then
+ PATH="/bin:/sbin"
+fi
+
+# Find current screen size
+if [ -z "${COLUMNS}" ]; then
+ COLUMNS=$(stty size)
+ COLUMNS=${COLUMNS##* }
+fi
+
+# When using remote connections, such as a serial port, stty size returns 0
+if [ "${COLUMNS}" = "0" ]; then
+ COLUMNS=80
+fi
+
+## Measurements for positioning result messages
+COL=$((${COLUMNS} - 8))
+WCOL=$((${COL} - 2))
+
+# Set Cursur Position Commands, used via echo -e
+SET_COL="\\033[${COL}G" # at the $COL char
+SET_WCOL="\\033[${WCOL}G" # at the $WCOL char
+CURS_UP="\\033[1A\\033[0G" # Up one line, at the 0'th char
+
+# Normal colors
+CLR_NORM_BLK="\\033[0;30m" # black
+CLR_NORM_RED="\\033[0;31m" # red
+CLR_NORM_GRN="\\033[0;32m" # green
+CLR_NORM_YEL="\\033[0;33m" # yellow
+CLR_NORM_BLU="\\033[0;34m" # blue
+CLR_NORM_MAG="\\033[0;35m" # magenta
+CLR_NORM_CYN="\\033[0;36m" # cyan
+CLR_NORM_WHT="\\033[0;37m" # white
+CLR_NORM_GRY="\\033[0;39m" # grey
+
+# Emphased colors
+CLR_BOLD_BLK="\\033[1;30m" # black
+CLR_BOLD_RED="\\033[1;31m" # red
+CLR_BOLD_GRN="\\033[1;32m" # green
+CLR_BOLD_YEL="\\033[1;33m" # yellow
+CLR_BOLD_BLU="\\033[1;34m" # blue
+CLR_BOLD_MAG="\\033[1;35m" # magenta
+CLR_BOLD_CYN="\\033[1;36m" # cyan
+CLR_BOLD_WHT="\\033[1;37m" # white
+CLR_BOLD_GRY="\\033[1;39m" # grey
+
+# Background colors
+CLR_BACK_BLK="\\033[40m" # black
+CLR_BACK_RED="\\033[41m" # red
+CLR_BACK_GRN="\\033[42m" # green
+CLR_BACK_YEL="\\033[43m" # yellow
+CLR_BACK_BLU="\\033[44m" # blue
+CLR_BACK_MAG="\\033[45m" # magenta
+CLR_BACK_CYN="\\033[46m" # cyan
+CLR_BACK_WHT="\\033[47m" # white
+
+# Action colors
+BOLD=$CLR_BOLD_GRY
+DONE=$CLR_BOLD_GRN
+SKIP=$CLR_BOLD_BLU
+WARN=$CLR_BOLD_MAG
+FAIL=$CLR_BOLD_RED
+NORMAL=$CLR_NORM_GRY
+
+# Color hooks
+BRACKET_L="${CLR_BOLD_BLU}[${NORMAL}"
+BRACKET_R="${CLR_BOLD_BLU}]${NORMAL}"
+
+# Define custom colors used in messages printed to the screen
+BRACKET=${CLR_BOLD_BLU} # Blue
+FAILURE=${CLR_BOLD_RED} # Red
+INFO=${CLR_BOLD_CYN} # Cyan
+NORMAL=${CLR_NORM_GRY} # Grey
+SUCCESS=${CLR_BOLD_GRN} # Green
+WARNING=${CLR_BOLD_YEL} # Yellow
+
+# Prefix boot messages for easier reading on framebuffer consoles
+PREFIX_SUCCESS=" ${SUCCESS}*${NORMAL} "
+PREFIX_WARNING="${WARNING}**${NORMAL} "
+PREFIX_FAILURE="${FAILURE}***${NORMAL}"
+
+welcome_message="Welcome to ${INFO}${DISTRO}${NORMAL}"
+welcome_message_length=$((${#DISTRO} + 11))
+
+# Error message displayed when a script's exit value is not zero
+print_error_msg() {
+ # ${link} and ${error_value} are defined by the rc script
+ echo -e "${FAILURE}FAILURE: You should not be reading this error message."
+ echo -e ""
+ echo -e -n "${FAILURE}It means that an unforseen error took place in"
+ echo -e -n "${INFO} ${link}"
+ echo -e "${FAILURE},"
+ echo -e "${FAILURE}which exited with a return value of ${error_value}."
+ echo -e ""
+ echo -e -n "${FAILURE}If you are able to track this error down to a bug"
+ echo -e "${FAILURE}in one of the files"
+ echo -e -n "provided by ${INFO}${DISTRO}${FAILURE}, "
+ echo -e -n "${FAILURE}please be so kind to inform us at "
+ echo -e "${INFO}${DISTRO_CONTACT}${FAILURE}.${NORMAL}"
+ echo -e ""
+ echo -e "${INFO}Press Enter to continue..."
+ echo -e "${NORMAL}"
+ read ENTER
+}
+
+################################################################################
+# log_success_msg() #
+# Usage: log_success_msg [$MESSAGE | "message"] #
+# #
+# Purpose: Print a successful status message to the screen and optionally #
+# a boot log file. #
+# #
+# Inputs: accepts one string value, either a quoted string or optionally #
+# the value of $MESSAGE if set in the running environment. #
+# #
+# Return values: Not used #
+################################################################################
+log_success_msg() {
+ echo -n -e "${PREFIX_SUCCESS}${INDENT}${@}"
+ echo -e "${SET_COL}${BRACKET}[${SUCCESS} OK ${BRACKET}]${NORMAL}"
+}
+
+################################################################################
+# log_failure_msg() #
+# Usage: log_failure_msg [$MESSAGE | "message"] #
+# #
+# Purpose: Print a failure status message to the screen and optionally #
+# a boot log file. #
+# #
+# Inputs: accepts one string value, either a quoted string or optionally #
+# the value of $MESSAGE if set in the running environment. #
+# #
+# Return values: Not used #
+################################################################################
+log_failure_msg() {
+ echo -n -e "${PREFIX_FAILURE}${INDENT}${@}"
+ echo -e "${SET_COL}${BRACKET}[${FAILURE} FAIL ${BRACKET}]${NORMAL}"
+}
+
+################################################################################
+# log_warning_msg() #
+# Usage: log_warning_msg [$MESSAGE | "message"] #
+# #
+# Purpose: Print a warning status message to the screen and optionally #
+# a boot log file. #
+# #
+# Inputs: accepts one string value, either a quoted string or optionally #
+# the value of $MESSAGE if set in the running environment. #
+# #
+# Return values: Not used #
+################################################################################
+log_warning_msg() {
+ echo -n -e "${PREFIX_WARNING}${INDENT}${@}"
+ echo -e "${SET_COL}${BRACKET}[${WARNING} WARN ${BRACKET}]${NORMAL}"
+}
+
+############################## evaluate_retval() ###############################
+# evaluate_retval requires that you pass exactly one evaluation parameter of #
+# (start, stop, other) based on the previous action that is being evaluated. #
+# This function is intended for use with start_daemon and killproc to #
+# interpret the LSB exit codes properly, othewise the checks only for success #
+# or failure. #
+################################################################################
+evaluate_retval() {
+ local error_value="${?}"
+
+ # Handle LSB defined return values
+ case "${1}" in
+ start)
+ case "${error_value}" in
+ 0)
+ log_success_msg "Starting ${MESSAGE} "
+ return "${error_value}"
+ ;;
+ 2)
+ log_failure_msg "Starting ${MESSAGE} Error: Invalid argument!"
+ return "${error_value}"
+ ;;
+ 5)
+ log_failure_msg "Starting ${MESSAGE} Error: Not available!"
+ return "${error_value}"
+ ;;
+ *)
+ log_failure_msg "Starting ${MESSAGE} Error: General failure!"
+ return "${error_value}"
+ ;;
+ esac
+ ;;
+
+ stop)
+ case "${error_value}" in
+ 0)
+ log_success_msg "Stopping ${MESSAGE} "
+ return "${error_value}"
+ ;;
+ 2)
+ log_failure_msg "Stopping ${MESSAGE} Error: Invalid argument!"
+ return "${error_value}"
+ ;;
+ 5)
+ log_failure_msg "Stopping ${MESSAGE} Error: Not available!"
+ return "${error_value}"
+ ;;
+ 7)
+ log_warning_msg "Stopping ${MESSAGE} Warning: Not running!"
+ return "${error_value}"
+ ;;
+ *)
+ log_failure_msg "Stopping ${MESSAGE} Error: General failure!"
+ return "${error_value}"
+ ;;
+ esac
+ ;;
+
+ force-reload)
+ message="Forcefully reloading "
+ ;;
+
+ reload)
+ message="Reloading "
+ ;;
+
+ restart)
+ message="Restarting "
+ ;;
+
+ try-restart)
+ message="Trying restart "
+ ;;
+
+ standard)
+ # $message or $MESSAGE must be set, but not both in order
+ # to use the 'standard' target.
+ ;;
+ esac
+
+ # Print messages for the generic force-reload, reload, restart,
+ # and try-restart targets
+ if [ "${error_value}" = "0" ]; then
+ log_success_msg "${message}${MESSAGE} "
+ return "${error_value}"
+ else
+ log_failure_msg "${message}${MESSAGE} "
+ return "${error_value}"
+ fi
+}