Fixed regex tests to not do string comparisons.

This commit is contained in:
Marcus Whybrow
2012-05-30 23:06:23 +01:00
parent 4db6d1b5cb
commit ef9c90ab79

26
msm
View File

@ -90,8 +90,8 @@ is_valid_name() {
local valid="^[a-zA-Z0-9\_\-]+$" local valid="^[a-zA-Z0-9\_\-]+$"
local invalid="^server|jargroup|start|stop|restart|all$" local invalid="^server|jargroup|start|stop|restart|all$"
if [[ "$1" =~ $valid ]]; then if [[ $1 =~ $valid ]]; then
if [[ "$1" =~ $invalid ]]; then if [[ $1 =~ $invalid ]]; then
echoerr "Invalid name \"$1\": A name may not be any of the following reserved worlds \"start\", \"stop\", \"restart\", \"server\", \"jargroup\" or \"all\"." echoerr "Invalid name \"$1\": A name may not be any of the following reserved worlds \"start\", \"stop\", \"restart\", \"server\", \"jargroup\" or \"all\"."
return 1 return 1
else else
@ -357,7 +357,7 @@ server_log_get_line() {
for search_line in "${@:3}"; do for search_line in "${@:3}"; do
local regex="${LOG_REGEX} ${search_line}" local regex="${LOG_REGEX} ${search_line}"
# and matches the regular expression # and matches the regular expression
if [[ "$line" =~ $regex ]]; then if [[ $line =~ $regex ]]; then
echo $line echo $line
return 0 return 0
fi fi
@ -443,7 +443,7 @@ jargroup_list() {
for group in $(ls -1 "$JAR_STORAGE_PATH"); do for group in $(ls -1 "$JAR_STORAGE_PATH"); do
echo "${group}:" echo "${group}:"
for jar in $(ls -1r $JAR_STORAGE_PATH/$group); do for jar in $(ls -1r $JAR_STORAGE_PATH/$group); do
if [[ "$jar" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}- ]]; then if [[ $jar =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}- ]]; then
echo " $jar" echo " $jar"
fi fi
done done
@ -566,7 +566,7 @@ jargroup_delete() {
printf "Are you sure you want to delete this jar group [y/N]: " printf "Are you sure you want to delete this jar group [y/N]: "
read answer read answer
if [[ "$answer" =~ ^y|Y|yes$ ]]; then if [[ $answer =~ ^y|Y|yes$ ]]; then
as_user "$USERNAME" "rm -rf $JAR_STORAGE_PATH/$1" as_user "$USERNAME" "rm -rf $JAR_STORAGE_PATH/$1"
echo "Jar group deleted." echo "Jar group deleted."
else else
@ -650,7 +650,7 @@ server_delete() {
printf "Are you sure you want to delete this server and its worlds (note: backups are preserved) [y/N]: " printf "Are you sure you want to delete this server and its worlds (note: backups are preserved) [y/N]: "
read answer read answer
if [[ "$answer" =~ ^y|Y|yes$ ]]; then if [[ $answer =~ ^y|Y|yes$ ]]; then
# TODO: stop the server if running first # TODO: stop the server if running first
as_user "$USERNAME" "rm -rf '$SERVER_STORAGE_PATH/$1'" as_user "$USERNAME" "rm -rf '$SERVER_STORAGE_PATH/$1'"
echo "Server deleted." echo "Server deleted."
@ -1655,7 +1655,7 @@ main() {
echo "Kicked \"$3\" from game." echo "Kicked \"$3\" from game."
fi fi
local regex="${LOG_REGEX} ${server_confirm_kick_fail[$id]}" local regex="${LOG_REGEX} ${server_confirm_kick_fail[$id]}"
if [[ "$line" =~ $regex ]]; then if [[ $line =~ $regex ]]; then
echo "The player \"$3\" is not connected." echo "The player \"$3\" is not connected."
fi fi
else else
@ -1685,11 +1685,11 @@ main() {
local line=$(server_eval_and_get_line $id "time set $4" "${server_confirm_time_set[$id]}" "${server_confirm_time_set_fail[$id]}") local line=$(server_eval_and_get_line $id "time set $4" "${server_confirm_time_set[$id]}" "${server_confirm_time_set_fail[$id]}")
local regex="${LOG_REGEX} ${server_confirm_time_set[$id]}" local regex="${LOG_REGEX} ${server_confirm_time_set[$id]}"
if [[ "$line" =~ $regex ]]; then if [[ $line =~ $regex ]]; then
echo "Set time to \"$4\"." echo "Set time to \"$4\"."
fi fi
local regex="${LOG_REGEX} ${server_confirm_time_set_fail[$id]}" local regex="${LOG_REGEX} ${server_confirm_time_set_fail[$id]}"
if [[ "$line" =~ $regex ]]; then if [[ $line =~ $regex ]]; then
echo "Unable to convert \"$4\" to a time." echo "Unable to convert \"$4\" to a time."
fi fi
else else
@ -1705,11 +1705,11 @@ main() {
local line=$(server_eval_and_get_line $id "time add $4" "${server_confirm_time_add[$id]}" "${server_confirm_time_add_fail[$id]}") local line=$(server_eval_and_get_line $id "time add $4" "${server_confirm_time_add[$id]}" "${server_confirm_time_add_fail[$id]}")
local regex="${LOG_REGEX} ${server_confirm_time_add[$id]}" local regex="${LOG_REGEX} ${server_confirm_time_add[$id]}"
if [[ "$line" =~ $regex ]]; then if [[ $line =~ $regex ]]; then
echo "Added \"$4\" to time." echo "Added \"$4\" to time."
fi fi
local regex="${LOG_REGEX} ${server_confirm_time_add_fail[$id]}" local regex="${LOG_REGEX} ${server_confirm_time_add_fail[$id]}"
if [[ "$line" =~ $regex ]]; then if [[ $line =~ $regex ]]; then
echo "Unable to convert \"$4\" to a time." echo "Unable to convert \"$4\" to a time."
fi fi
else else
@ -1727,11 +1727,11 @@ main() {
local line=$(server_eval_and_get_line $id "toggledownfall $3" "${server_confirm_toggledownfall[$id]}" "${server_confirm_toggledownfall_fail[$id]}") local line=$(server_eval_and_get_line $id "toggledownfall $3" "${server_confirm_toggledownfall[$id]}" "${server_confirm_toggledownfall_fail[$id]}")
local regex="${LOG_REGEX} ${server_confirm_toggledownfall[$id]}" local regex="${LOG_REGEX} ${server_confirm_toggledownfall[$id]}"
if [[ "$line" =~ $regex ]]; then if [[ $line =~ $regex ]]; then
echo ${line:36:(-3)} echo ${line:36:(-3)}
fi fi
local regex="${LOG_REGEX} ${server_confirm_toggledownfall_fail[$id]}" local regex="${LOG_REGEX} ${server_confirm_toggledownfall_fail[$id]}"
if [[ "$line" =~ $regex ]]; then if [[ $line =~ $regex ]]; then
echo ${line:34:(-3)} echo ${line:34:(-3)}
fi fi
else else