Compare commits
No commits in common. "6c092c3c0720876564ee21498b7896bd9eb8d023" and "a73208b0a50d1813596a9b7f4f6fa1dc36c1efcf" have entirely different histories.
6c092c3c07
...
a73208b0a5
1 changed files with 11 additions and 29 deletions
40
bin/mcserv
40
bin/mcserv
|
@ -1,18 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
exec_user() {
|
||||
local user="$1"
|
||||
shift
|
||||
if [ "$USER" != "$user" ]; then
|
||||
exec sudo -u "$user" "$0" "$@"
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
exec_user minecraft "$@"
|
||||
|
||||
cd ~/bin || exit
|
||||
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: "$*"
|
||||
|
@ -24,7 +13,8 @@ public_usage() {
|
|||
cat << EOF
|
||||
${name}: utilisation
|
||||
${name} start|status|stop|watch NOM_SERVEUR
|
||||
${name} list|active|usage
|
||||
${name} list
|
||||
${name} usage
|
||||
EOF
|
||||
}
|
||||
|
||||
|
@ -36,8 +26,8 @@ error_usage() {
|
|||
|
||||
public_start() {
|
||||
if [ -n "$1" ]; then
|
||||
screen -d -m -S "$1" \
|
||||
"./${1}"
|
||||
mcscreen -d -m -S "$1" \
|
||||
"/srv/minecraft/bin/${1}"
|
||||
else
|
||||
error_usage
|
||||
fi
|
||||
|
@ -46,7 +36,7 @@ public_start() {
|
|||
public_status() {
|
||||
if [ -n "$1" ]; then
|
||||
printf '\033[1m%s\033[0m : ' "$1"
|
||||
if screen -ls "$1" > /dev/null 2>&1; then
|
||||
if mcscreen -ls "$1" > /dev/null 2>&1; then
|
||||
echo "en cours d'exécution"
|
||||
else
|
||||
echo "non en cours d'exécution"
|
||||
|
@ -58,34 +48,26 @@ public_status() {
|
|||
|
||||
public_stop() {
|
||||
if [ -n "$1" ]; then
|
||||
screen -S "$1" -X stuff '^E^Ustop^M'
|
||||
mcscreen -S "$1" -X stuff '^E^Ustop^M'
|
||||
else
|
||||
error_usage
|
||||
fi
|
||||
}
|
||||
|
||||
public_watch() {
|
||||
screen -dr "$1"
|
||||
}
|
||||
|
||||
public_active() {
|
||||
screen -ls
|
||||
mcscreen -dr "$1"
|
||||
}
|
||||
|
||||
public_list() {
|
||||
echo "Serveurs disponibles :"
|
||||
ls --color=auto
|
||||
mcscreen -ls
|
||||
}
|
||||
|
||||
verb="$1"
|
||||
shift
|
||||
case "$verb" in
|
||||
start|status|stop|watch|active|list|usage)
|
||||
start|status|stop|watch|list|usage)
|
||||
"public_${verb}" "$@"
|
||||
;;
|
||||
"")
|
||||
public_active
|
||||
;;
|
||||
*)
|
||||
error_usage
|
||||
;;
|
||||
|
|
Loading…
Reference in a new issue