Clean up untidiness where Shorewall6 tries to start on a system with an old kernel

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep
2010-09-25 08:46:14 -07:00
parent a79a8d4acc
commit f07ec1e9d3
4 changed files with 142 additions and 95 deletions

View File

@ -17,6 +17,19 @@ usage() {
echo " -R <file> Override RESTOREFILE setting"
exit $1
}
checkkernelversion() {
local kernel
kernel=$(printf "%2d%02d%02d" $(uname -r 2> /dev/null | sed -e 's/-.*//' -e 's/^\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/\1 \2 \3/g'))
if [ $kernel -lt 20624 ]; then
error_message "ERROR: $g_product requires Linux kernel 2.6.24 or later"
return 1
else
return 0
fi
}
################################################################################
# E X E C U T I O N B E G I N S H E R E #
################################################################################
@ -155,40 +168,41 @@ done
COMMAND="$1"
kernel=$(printf "%2d%02d%02d" $(uname -r 2> /dev/null | sed -e 's/-.*//' -e 's/^\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/\1 \2 \3/g'))
if [ $kernel -lt 20624 ]; then
error_message "ERROR: $g_product requires Linux kernel 2.6.24 or later"
status=2
else
case "$COMMAND" in
start)
[ $# -ne 1 ] && usage 2
if shorewall6_is_started; then
error_message "$g_product is already Running"
status=0
else
progress_message3 "Starting $g_product...."
case "$COMMAND" in
start)
[ $# -ne 1 ] && usage 2
if shorewall6_is_started; then
error_message "$g_product is already Running"
status=0
else
progress_message3 "Starting $g_product...."
if checkkernelversion; then
detect_configuration
define_firewall
status=$?
[ -n "$SUBSYSLOCK" -a $status -eq 0 ] && touch $SUBSYSLOCK
progress_message3 "done."
fi
;;
stop)
[ $# -ne 1 ] && usage 2
fi
;;
stop)
[ $# -ne 1 ] && usage 2
if checkkernelversion; then
progress_message3 "Stopping $g_product...."
detect_configuration
stop_firewall
status=0
[ -n "$SUBSYSLOCK" ] && rm -f $SUBSYSLOCK
progress_message3 "done."
;;
reset)
if ! shorewall6_is_started ; then
error_message "$g_product is not running"
status=2
elif [ $# -eq 1 ]; then
fi
;;
reset)
if ! shorewall6_is_started ; then
error_message "$g_product is not running"
status=2
elif checkkernelversion; then
if [ $# -eq 1 ]; then
$IP6TABLES -Z
$IP6TABLES -t mangle -Z
date > ${VARDIR}/restarted
@ -211,17 +225,19 @@ else
fi
done
fi
;;
restart)
[ $# -ne 1 ] && usage 2
if shorewall6_is_started; then
progress_message3 "Restarting $g_product...."
else
error_message "$g_product is not running"
progress_message3 "Starting $g_product...."
COMMAND=start
fi
fi
;;
restart)
[ $# -ne 1 ] && usage 2
if shorewall6_is_started; then
progress_message3 "Restarting $g_product...."
else
error_message "$g_product is not running"
progress_message3 "Starting $g_product...."
COMMAND=start
fi
if checkkernelversion; then
detect_configuration
define_firewall
status=$?
@ -229,84 +245,90 @@ else
[ $status -eq 0 ] && touch $SUBSYSLOCK || rm -f $SUBSYSLOCK
fi
progress_message3 "done."
;;
refresh)
[ $# -ne 1 ] && usage 2
if shorewall6_is_started; then
progress_message3 "Refreshing $g_product...."
fi
;;
refresh)
[ $# -ne 1 ] && usage 2
if shorewall6_is_started; then
progress_message3 "Refreshing $g_product...."
if checkkernelversion; then
detect_configuration
define_firewall
status=$?
progress_message3 "done."
else
echo "$g_product is not running" >&2
status=2
fi
;;
restore)
[ $# -ne 1 ] && usage 2
else
echo "$g_product is not running" >&2
status=2
fi
;;
restore)
[ $# -ne 1 ] && usage 2
if checkkernelversion; then
detect_configuration
define_firewall
status=$?
if [ -n "$SUBSYSLOCK" ]; then
[ $status -eq 0 ] && touch $SUBSYSLOCK || rm -f $SUBSYSLOCK
fi
;;
clear)
[ $# -ne 1 ] && usage 2
progress_message3 "Clearing $g_product...."
fi
;;
clear)
[ $# -ne 1 ] && usage 2
progress_message3 "Clearing $g_product...."
if checkkernelversion; then
clear_firewall
status=0
if [ -n "$SUBSYSLOCK" ]; then
rm -f $SUBSYSLOCK
fi
progress_message3 "done."
;;
status)
[ $# -ne 1 ] && usage 2
echo "$g_product-$SHOREWALL_VERSION Status at $(hostname) - $(date)"
echo
if shorewall6_is_started; then
echo "$g_product is running"
status=0
else
echo "$g_product is stopped"
status=4
fi
if [ -f ${VARDIR}/state ]; then
state="$(cat ${VARDIR}/state)"
case $state in
Stopped*|Clear*)
status=3
;;
esac
else
state=Unknown
fi
echo "State:$state"
echo
;;
up|down)
[ $# -eq 1 ] && exit 0
shift
[ $# -ne 1 ] && usage 2
updown $1
fi
;;
status)
[ $# -ne 1 ] && usage 2
echo "$g_product-$SHOREWALL_VERSION Status at $(hostname) - $(date)"
echo
if shorewall6_is_started; then
echo "$g_product is running"
status=0
;;
version)
[ $# -ne 1 ] && usage 2
echo $SHOREWALL_VERSION
status=0
;;
help)
[ $# -ne 1 ] && usage 2
usage 0
;;
*)
usage 2
;;
esac
fi
else
echo "$g_product is stopped"
status=4
fi
if [ -f ${VARDIR}/state ]; then
state="$(cat ${VARDIR}/state)"
case $state in
Stopped*|Clear*)
status=3
;;
esac
else
state=Unknown
fi
echo "State:$state"
echo
;;
up|down)
[ $# -eq 1 ] && exit 0
shift
[ $# -ne 1 ] && usage 2
updown $1
status=0
;;
version)
[ $# -ne 1 ] && usage 2
echo $SHOREWALL_VERSION
status=0
;;
help)
[ $# -ne 1 ] && usage 2
usage 0
;;
*)
usage 2
;;
esac
exit $status