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 invalid="^server|jargroup|start|stop|restart|all$"
if [[ "$1" =~ $valid ]]; then
if [[ "$1" =~ $invalid ]]; then
if [[ $1 =~ $valid ]]; 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\"."
return 1
else
@ -357,7 +357,7 @@ server_log_get_line() {
for search_line in "${@:3}"; do
local regex="${LOG_REGEX} ${search_line}"
# and matches the regular expression
if [[ "$line" =~ $regex ]]; then
if [[ $line =~ $regex ]]; then
echo $line
return 0
fi
@ -443,7 +443,7 @@ jargroup_list() {
for group in $(ls -1 "$JAR_STORAGE_PATH"); do
echo "${group}:"
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"
fi
done
@ -566,7 +566,7 @@ jargroup_delete() {
printf "Are you sure you want to delete this jar group [y/N]: "
read answer
if [[ "$answer" =~ ^y|Y|yes$ ]]; then
if [[ $answer =~ ^y|Y|yes$ ]]; then
as_user "$USERNAME" "rm -rf $JAR_STORAGE_PATH/$1"
echo "Jar group deleted."
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]: "
read answer
if [[ "$answer" =~ ^y|Y|yes$ ]]; then
if [[ $answer =~ ^y|Y|yes$ ]]; then
# TODO: stop the server if running first
as_user "$USERNAME" "rm -rf '$SERVER_STORAGE_PATH/$1'"
echo "Server deleted."
@ -1655,7 +1655,7 @@ main() {
echo "Kicked \"$3\" from game."
fi
local regex="${LOG_REGEX} ${server_confirm_kick_fail[$id]}"
if [[ "$line" =~ $regex ]]; then
if [[ $line =~ $regex ]]; then
echo "The player \"$3\" is not connected."
fi
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 regex="${LOG_REGEX} ${server_confirm_time_set[$id]}"
if [[ "$line" =~ $regex ]]; then
if [[ $line =~ $regex ]]; then
echo "Set time to \"$4\"."
fi
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."
fi
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 regex="${LOG_REGEX} ${server_confirm_time_add[$id]}"
if [[ "$line" =~ $regex ]]; then
if [[ $line =~ $regex ]]; then
echo "Added \"$4\" to time."
fi
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."
fi
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 regex="${LOG_REGEX} ${server_confirm_toggledownfall[$id]}"
if [[ "$line" =~ $regex ]]; then
if [[ $line =~ $regex ]]; then
echo ${line:36:(-3)}
fi
local regex="${LOG_REGEX} ${server_confirm_toggledownfall_fail[$id]}"
if [[ "$line" =~ $regex ]]; then
if [[ $line =~ $regex ]]; then
echo ${line:34:(-3)}
fi
else