2023-07-03 19:55:23 +02:00
|
|
|
#!/bin/bash
|
2023-07-03 19:50:13 +02:00
|
|
|
|
|
|
|
shopt -s expand_aliases
|
|
|
|
alias mcscreen='sudo -u minecraft screen'
|
|
|
|
|
|
|
|
print_error() {
|
|
|
|
>&2 printf '\033[31;1m%s\033[0m \033[1m%s\033[0m\n' ERROR: "$*"
|
|
|
|
}
|
|
|
|
|
|
|
|
public_usage() {
|
|
|
|
local name
|
|
|
|
name="$(basename "$0")"
|
|
|
|
cat << EOF
|
|
|
|
${name}: utilisation
|
|
|
|
${name} start|status|stop|watch NOM_SERVEUR
|
|
|
|
${name} list
|
2023-07-03 19:54:35 +02:00
|
|
|
${name} usage
|
2023-07-03 19:50:13 +02:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
error_usage() {
|
|
|
|
print_error "Utilisation invalide."
|
|
|
|
>&2 public_usage
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
public_start() {
|
|
|
|
mcscreen -d -m -S "$1" \
|
|
|
|
"/srv/minecraft/bin/${1}"
|
|
|
|
}
|
|
|
|
|
|
|
|
public_status() {
|
|
|
|
printf '\033[1m%s\033[0m : ' "$1"
|
|
|
|
if mcscreen -ls "$1" > /dev/null 2>&1; then
|
|
|
|
echo "en cours d'exécution"
|
|
|
|
else
|
|
|
|
echo "non en cours d'exécution"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
public_stop() {
|
|
|
|
mcscreen -S "$1" -X stuff '^E^Ustop^M'
|
|
|
|
}
|
|
|
|
|
|
|
|
public_watch() {
|
|
|
|
mcscreen -dr "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
public_list() {
|
|
|
|
mcscreen -ls
|
|
|
|
}
|
|
|
|
|
|
|
|
verb="$1"
|
|
|
|
shift
|
|
|
|
case "$verb" in
|
2023-07-03 19:54:35 +02:00
|
|
|
start|status|stop|watch|list|usage)
|
2023-07-03 19:50:13 +02:00
|
|
|
"public_${verb}" "$@"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
error_usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|