Added list option
This commit is contained in:
parent
83f6f06aef
commit
5f717de375
@ -82,7 +82,8 @@ start_server() {
|
|||||||
server_session_name="${prefix}-${server_name}"
|
server_session_name="${prefix}-${server_name}"
|
||||||
|
|
||||||
[[ ! -d "${server_directory}" ]] &&
|
[[ ! -d "${server_directory}" ]] &&
|
||||||
log "error" "Unable to find the server directory for $(important "${server_name}")"
|
log "error" "Unable to find the server directory for $(important "${server_name}")" &&
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
local server_port
|
local server_port
|
||||||
@ -178,7 +179,7 @@ kill_server() {
|
|||||||
log "info" "Stopped $(important "${prefix}-Server-${server_id}")"
|
log "info" "Stopped $(important "${prefix}-Server-${server_id}")"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
log "error" "Could not find $(important "${prefix}-Server-${server_id}") or unable to shut down ${prefix}-Server-${server_id}"
|
log "error" "$(important "${prefix}-Server-${server_id}") is not running"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -295,6 +296,71 @@ update() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list_servers() {
|
||||||
|
local picked_option
|
||||||
|
picked_option=""
|
||||||
|
while :; do
|
||||||
|
case ${1} in
|
||||||
|
-h | -\? | --help)
|
||||||
|
printf "Usage: %s\n" \
|
||||||
|
"list [OPTIONS]
|
||||||
|
--running | -r
|
||||||
|
Lists the currently running 7 Days To Die Servers
|
||||||
|
|
||||||
|
Example:
|
||||||
|
--running
|
||||||
|
--installed | -i
|
||||||
|
Lists the currently installed 7 Days To Die Servers
|
||||||
|
|
||||||
|
Example:
|
||||||
|
--installed"
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
--) # End of all options.
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
--running | -r)
|
||||||
|
picked_option=0
|
||||||
|
;;
|
||||||
|
--installed | -i)
|
||||||
|
picked_option=1
|
||||||
|
;;
|
||||||
|
-?*)
|
||||||
|
printf 'Unknown option: %s\n' "$1" >&2
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
*) # Default case: No more options, so break out of the loop.
|
||||||
|
break ;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
[[ -z "${picked_option}" ]] &&
|
||||||
|
log "error" "An option must be passed for list, check list -h" &&
|
||||||
|
return 1
|
||||||
|
|
||||||
|
if (( picked_option == 0 )); then
|
||||||
|
log "debug" "Listing running servers"
|
||||||
|
local tmux_sessions
|
||||||
|
tmux_sessions="$(tmux list-sessions)" >/dev/null 2>&1
|
||||||
|
if [[ ! "${?}" -eq "0" ]]; then
|
||||||
|
important "No servers currently running."
|
||||||
|
fi
|
||||||
|
while read -r; do
|
||||||
|
if [[ "${REPLY}" = *"-Server-"* ]]; then
|
||||||
|
local running_server
|
||||||
|
running_server="$(echo "${REPLY}" | cut -d ":" -f1)"
|
||||||
|
important "${running_server}"
|
||||||
|
fi
|
||||||
|
done <<< "${tmux_sessions}"
|
||||||
|
elif (( picked_option == 1 )); then
|
||||||
|
log "debug" "Listing installed servers"
|
||||||
|
while read -r; do
|
||||||
|
important "${BASE_DIR}/${REPLY}"
|
||||||
|
done <<< "$(find "${BASE_DIR}" -name "startserver.sh" | cut -d "/" -f5)"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
# Print out usage instructions for the local script
|
# Print out usage instructions for the local script
|
||||||
#
|
#
|
||||||
@ -316,7 +382,9 @@ usage() {
|
|||||||
install
|
install
|
||||||
Exposes options to install 7 Days To Die Servers, pass -h to it for details
|
Exposes options to install 7 Days To Die Servers, pass -h to it for details
|
||||||
update
|
update
|
||||||
Exposes options to update 7 Days To Die Servers, pass -h to it for details"
|
Exposes options to update 7 Days To Die Servers, pass -h to it for details
|
||||||
|
list
|
||||||
|
Exposes options to list 7 Days To Die Servers, pass -h to it for details"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -363,6 +431,11 @@ main() {
|
|||||||
update "$@"
|
update "$@"
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
|
list | l)
|
||||||
|
shift
|
||||||
|
list_servers "$@"
|
||||||
|
break
|
||||||
|
;;
|
||||||
-?*)
|
-?*)
|
||||||
printf "Unknown option: %s\n" "$1" >&2
|
printf "Unknown option: %s\n" "$1" >&2
|
||||||
usage
|
usage
|
||||||
|
Loading…
x
Reference in New Issue
Block a user