mirror of
https://github.com/msmhq/msm.git
synced 2024-08-30 18:12:35 +00:00
Updated cash completion to use lazy property loading.
This commit is contained in:
parent
46f9b8204a
commit
9cb6bf365c
@ -18,70 +18,67 @@ fi
|
|||||||
|
|
||||||
MSM="${MSM_SCRIPT:-/etc/init.d/msm}"
|
MSM="${MSM_SCRIPT:-/etc/init.d/msm}"
|
||||||
|
|
||||||
# Loads variables
|
# # Loads server variables
|
||||||
__init() {
|
# # $1: The name of a server
|
||||||
source "$MSM"
|
# __init_server() {
|
||||||
}
|
# # Load some useful defaults
|
||||||
|
# SERVER_NAME="$1"
|
||||||
|
# SERVER_CONF="$SETTINGS_SERVER_STORAGE_PATH/$SERVER_NAME/$SETTINGS_SERVER_PROPERTIES"
|
||||||
|
|
||||||
# Loads server variables
|
# SERVER_PATH="$SETTINGS_SERVER_STORAGE_PATH/$SERVER_NAME"
|
||||||
# $1: The name of a server
|
# WORLD_STORAGE_PATH="$SERVER_PATH/$SETTINGS_DEFAULT_WORLD_STORAGE_PATH"
|
||||||
__init_server() {
|
# WORLD_STORAGE_INACTIVE_PATH="$SERVER_PATH/$SETTINGS_DEFAULT_WORLD_STORAGE_INACTIVE_PATH"
|
||||||
# Load some useful defaults
|
|
||||||
SERVER_NAME="$1"
|
|
||||||
SERVER_CONF="$SETTINGS_SERVER_STORAGE_PATH/$SERVER_NAME/$SETTINGS_SERVER_PROPERTIES"
|
|
||||||
|
|
||||||
SERVER_PATH="$SETTINGS_SERVER_STORAGE_PATH/$SERVER_NAME"
|
# WHITELIST_PATH="$SERVER_PATH/$SETTINGS_DEFAULT_WHITELIST_PATH"
|
||||||
WORLD_STORAGE_PATH="$SERVER_PATH/$SETTINGS_DEFAULT_WORLD_STORAGE_PATH"
|
# BANNED_PLAYERS_PATH="$SERVER_PATH/$SETTINGS_DEFAULT_BANNED_PLAYERS_PATH"
|
||||||
WORLD_STORAGE_INACTIVE_PATH="$SERVER_PATH/$SETTINGS_DEFAULT_WORLD_STORAGE_INACTIVE_PATH"
|
# BANNED_IPS_PATH="$SERVER_PATH/$SETTINGS_DEFAULT_BANNED_IPS_PATH"
|
||||||
|
# OPS_PATH="$SERVER_PATH/$SETTINGS_DEFAULT_OPS_PATH"
|
||||||
|
|
||||||
WHITELIST_PATH="$SERVER_PATH/$SETTINGS_DEFAULT_WHITELIST_PATH"
|
# if [[ -f "$SERVER_CONF" ]]; then
|
||||||
BANNED_PLAYERS_PATH="$SERVER_PATH/$SETTINGS_DEFAULT_BANNED_PLAYERS_PATH"
|
# local name value name_upper_case
|
||||||
BANNED_IPS_PATH="$SERVER_PATH/$SETTINGS_DEFAULT_BANNED_IPS_PATH"
|
|
||||||
OPS_PATH="$SERVER_PATH/$SETTINGS_DEFAULT_OPS_PATH"
|
|
||||||
|
|
||||||
if [[ -f "$SERVER_CONF" ]]; then
|
|
||||||
local name value name_upper_case
|
|
||||||
|
|
||||||
while read line; do
|
# while read line; do
|
||||||
# ignore comment lines
|
# # ignore comment lines
|
||||||
if [[ "$line" =~ ^# ]]; then
|
# if [[ "$line" =~ ^# ]]; then
|
||||||
continue
|
# continue
|
||||||
fi
|
# fi
|
||||||
|
|
||||||
if [[ "$line" =~ ^msm-([\-\_a-zA-Z0-9]+)\=(\"(.*)\"|\'(.*)\'|(.*)$) ]]; then
|
# if [[ "$line" =~ ^msm-([\-\_a-zA-Z0-9]+)\=(\"(.*)\"|\'(.*)\'|(.*)$) ]]; then
|
||||||
name="${BASH_REMATCH[1]}"
|
# name="${BASH_REMATCH[1]}"
|
||||||
value="${BASH_REMATCH[3]}${BASH_REMATCH[4]}${BASH_REMATCH[5]}"
|
# value="${BASH_REMATCH[3]}${BASH_REMATCH[4]}${BASH_REMATCH[5]}"
|
||||||
|
|
||||||
if is_bash_version 4; then
|
# if is_bash_version 4; then
|
||||||
name="${name//-/_}"
|
# name="${name//-/_}"
|
||||||
name="${name//./_}"
|
# name="${name//./_}"
|
||||||
name="${name^^}"
|
# name="${name^^}"
|
||||||
else
|
# else
|
||||||
name="$(echo "$name" | tr '[\-\.a-z]' '[\_\_A-Z]')"
|
# name="$(echo "$name" | tr '[\-\.a-z]' '[\_\_A-Z]')"
|
||||||
fi
|
# fi
|
||||||
|
|
||||||
# Make relative paths absolute by combining with server directory
|
# # Make relative paths absolute by combining with server directory
|
||||||
if [[ "$name" =~ \-path$ ]] && [[ ! "$value" =~ ^\/ ]]; then
|
# if [[ "$name" =~ \-path$ ]] && [[ ! "$value" =~ ^\/ ]]; then
|
||||||
value="${SERVER_PATH[$1]}/$value"
|
# value="${SERVER_PATH[$1]}/$value"
|
||||||
fi
|
# fi
|
||||||
|
|
||||||
# Create the variable
|
# # Create the variable
|
||||||
eval ${name}=\"$value\"
|
# eval ${name}=\"$value\"
|
||||||
fi
|
# fi
|
||||||
done < "$SERVER_CONF"
|
# done < "$SERVER_CONF"
|
||||||
fi
|
# fi
|
||||||
}
|
# }
|
||||||
|
|
||||||
|
|
||||||
### Auto Completion Function
|
### Auto Completion Function
|
||||||
|
|
||||||
_msm() {
|
_msm() {
|
||||||
__init
|
source "$MSM"
|
||||||
|
|
||||||
local base current options
|
local base current options
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
|
|
||||||
current="${COMP_WORDS[$COMP_CWORD]}"
|
current="${COMP_WORDS[$COMP_CWORD]}"
|
||||||
|
|
||||||
|
manager_property SERVER_STORAGE_PATH
|
||||||
|
|
||||||
if [[ $COMP_CWORD == 1 ]]; then
|
if [[ $COMP_CWORD == 1 ]]; then
|
||||||
if [ -d "$SETTINGS_SERVER_STORAGE_PATH" ]; then
|
if [ -d "$SETTINGS_SERVER_STORAGE_PATH" ]; then
|
||||||
@ -114,6 +111,7 @@ _msm() {
|
|||||||
else
|
else
|
||||||
case "${COMP_WORDS[2]}" in
|
case "${COMP_WORDS[2]}" in
|
||||||
delete|rename|changeurl|getlatest)
|
delete|rename|changeurl|getlatest)
|
||||||
|
manager_property JAR_STORAGE_PATH
|
||||||
if [[ $COMP_CWORD == 3 && -d "$SETTINGS_JAR_STORAGE_PATH" ]]; then
|
if [[ $COMP_CWORD == 3 && -d "$SETTINGS_JAR_STORAGE_PATH" ]]; then
|
||||||
options="$(ls -1 "$SETTINGS_JAR_STORAGE_PATH")"
|
options="$(ls -1 "$SETTINGS_JAR_STORAGE_PATH")"
|
||||||
fi
|
fi
|
||||||
@ -127,8 +125,9 @@ _msm() {
|
|||||||
local server_path="$SETTINGS_SERVER_STORAGE_PATH/${COMP_WORDS[1]}"
|
local server_path="$SETTINGS_SERVER_STORAGE_PATH/${COMP_WORDS[1]}"
|
||||||
if [[ "${COMP_WORDS[1]}" == "all" ]] || [ -e "$server_path" ]; then
|
if [[ "${COMP_WORDS[1]}" == "all" ]] || [ -e "$server_path" ]; then
|
||||||
# If the server exists
|
# If the server exists
|
||||||
|
|
||||||
__init_server "${COMP_WORDS[1]}"
|
server_get_id "${COMP_WORDS[1]}"
|
||||||
|
local sid="$RETURN"
|
||||||
|
|
||||||
if [[ $COMP_CWORD == 2 ]]; then
|
if [[ $COMP_CWORD == 2 ]]; then
|
||||||
options="start stop restart status connected worlds logroll backup jar whitelist blacklist operator gamemode kick say time toggledownfall give xp save cmd cmdlog console config"
|
options="start stop restart status connected worlds logroll backup jar whitelist blacklist operator gamemode kick say time toggledownfall give xp save cmd cmdlog console config"
|
||||||
@ -143,25 +142,29 @@ _msm() {
|
|||||||
if [[ $COMP_CWORD == 3 ]]; then
|
if [[ $COMP_CWORD == 3 ]]; then
|
||||||
options="list load ram todisk backup on off"
|
options="list load ram todisk backup on off"
|
||||||
else
|
else
|
||||||
|
|
||||||
case "${COMP_WORDS[3]}" in
|
case "${COMP_WORDS[3]}" in
|
||||||
ram)
|
ram)
|
||||||
if [[ $COMP_CWORD == 4 ]]; then
|
if [[ $COMP_CWORD == 4 ]]; then
|
||||||
if [ -d "$WORLD_STORAGE_PATH" ]; then
|
server_property "$sid" WORLD_STORAGE_PATH
|
||||||
options="$(ls -1 "$WORLD_STORAGE_PATH")"
|
if [ -d "${SERVER_WORLD_STORAGE_PATH[$sid]}" ]; then
|
||||||
|
options="$(ls -1 "${SERVER_WORLD_STORAGE_PATH[$sid]}")"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
on)
|
on)
|
||||||
if [[ $COMP_CWORD == 4 ]]; then
|
if [[ $COMP_CWORD == 4 ]]; then
|
||||||
if [ -d "$WORLD_STORAGE_INACTIVE_PATH" ]; then
|
server_property "$sid" WORLD_STORAGE_INACTIVE_PATH
|
||||||
options="$(ls -1 "$WORLD_STORAGE_INACTIVE_PATH")"
|
if [ -d "${SERVER_WORLD_STORAGE_INACTIVE_PATH[$sid]}" ]; then
|
||||||
|
options="$(ls -1 "${SERVER_WORLD_STORAGE_INACTIVE_PATH[$sid]}")"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
off)
|
off)
|
||||||
if [[ $COMP_CWORD == 4 ]]; then
|
if [[ $COMP_CWORD == 4 ]]; then
|
||||||
if [ -d "$WORLD_STORAGE_PATH" ]; then
|
server_property "$sid" WORLD_STORAGE_PATH
|
||||||
options="$(ls -1 "$WORLD_STORAGE_PATH")"
|
if [ -d "${SERVER_WORLD_STORAGE_PATH[$sid]}" ]; then
|
||||||
|
options="$(ls -1 "${SERVER_WORLD_STORAGE_PATH[$sid]}")"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@ -169,6 +172,7 @@ _msm() {
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
jar)
|
jar)
|
||||||
|
manager_property JAR_STORAGE_PATH
|
||||||
if [[ $COMP_CWORD == 3 && -d "$SETTINGS_JAR_STORAGE_PATH" ]]; then
|
if [[ $COMP_CWORD == 3 && -d "$SETTINGS_JAR_STORAGE_PATH" ]]; then
|
||||||
options="$(ls -1 "$SETTINGS_JAR_STORAGE_PATH")"
|
options="$(ls -1 "$SETTINGS_JAR_STORAGE_PATH")"
|
||||||
fi
|
fi
|
||||||
@ -184,8 +188,9 @@ _msm() {
|
|||||||
case "${COMP_WORDS[3]}" in
|
case "${COMP_WORDS[3]}" in
|
||||||
remove)
|
remove)
|
||||||
if [[ $COMP_CWORD == 4 ]]; then
|
if [[ $COMP_CWORD == 4 ]]; then
|
||||||
if [ -f "$WHITELIST_PATH" ]; then
|
server_property "$sid" WHITELIST_PATH
|
||||||
options="$(cat "$WHITELIST_PATH")"
|
if [ -f "${SERVER_WHITELIST_PATH[$sid]}" ]; then
|
||||||
|
options="$(cat "${SERVER_WHITELIST_PATH[$sid]}")"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@ -204,8 +209,9 @@ _msm() {
|
|||||||
case "${COMP_WORDS[4]}" in
|
case "${COMP_WORDS[4]}" in
|
||||||
remove)
|
remove)
|
||||||
if [[ $COMP_CWORD == 5 ]]; then
|
if [[ $COMP_CWORD == 5 ]]; then
|
||||||
if [ -f "$BANNED_PLAYERS_PATH" ]; then
|
server_property "$sid" BANNED_PLAYERS_PATH
|
||||||
options="$(cat "$BANNED_PLAYERS_PATH")"
|
if [ -f "${SERVER_BANNED_PLAYERS_PATH[$sid]}" ]; then
|
||||||
|
options="$(cat "${SERVER_BANNED_PLAYERS_PATH[$sid]}")"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@ -219,8 +225,9 @@ _msm() {
|
|||||||
case "${COMP_WORDS[4]}" in
|
case "${COMP_WORDS[4]}" in
|
||||||
remove)
|
remove)
|
||||||
if [[ $COMP_CWORD == 5 ]]; then
|
if [[ $COMP_CWORD == 5 ]]; then
|
||||||
if [ -f "$BANNED_IPS_PATH" ]; then
|
server_property "$sid" BANNED_PLAYERS_PATH
|
||||||
options="$(cat "$BANNED_IPS_PATH")"
|
if [ -f "${SERVER_BANNED_IPS_PATH[$sid]}" ]; then
|
||||||
|
options="$(cat "${SERVER_BANNED_IPS_PATH[$sid]}")"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@ -237,8 +244,9 @@ _msm() {
|
|||||||
case "${COMP_WORDS[3]}" in
|
case "${COMP_WORDS[3]}" in
|
||||||
remove)
|
remove)
|
||||||
if [[ $COMP_CWORD == 4 ]]; then
|
if [[ $COMP_CWORD == 4 ]]; then
|
||||||
|
server_property "$sid" OPS_PATH
|
||||||
if [ -f "$OPS_PATH" ]; then
|
if [ -f "$OPS_PATH" ]; then
|
||||||
options="$(cat "$OPS_PATH")"
|
options="$(cat "${SERVER_OPS_PATH[$sid]}")"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@ -262,7 +270,8 @@ _msm() {
|
|||||||
;;
|
;;
|
||||||
config)
|
config)
|
||||||
if [[ $COMP_CWORD == 3 ]]; then
|
if [[ $COMP_CWORD == 3 ]]; then
|
||||||
options="$(more "$SERVER_CONF" | sed 's/=.*$//' | grep -v '#')";
|
server_property "$sid" SERVER_CONF
|
||||||
|
options="$(more "${SERVER_CONF[$sid]}" | sed 's/=.*$//' | grep -v '#')";
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user