Compare commits

..

4 commits

Author SHA1 Message Date
Hippolyte Chauvin
6c092c3c07 Correction : les arguments n'étaient pas correctement passés 2023-07-04 20:35:11 +02:00
Hippolyte Chauvin
d7a948723f Ajout : nouvelles options dans l'aide 2023-07-04 20:31:59 +02:00
Hippolyte Chauvin
9b112c69df Correction : erreur dans le case 2023-07-04 20:29:09 +02:00
Hippolyte Chauvin
de6e7df68c Ajout : nouvelles fonctionnalités non-testées sur mcserv 2023-07-04 20:24:37 +02:00

View file

@ -1,7 +1,18 @@
#!/bin/bash
shopt -s expand_aliases
alias mcscreen='sudo -u minecraft screen'
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
print_error() {
>&2 printf '\033[31;1m%s\033[0m \033[1m%s\033[0m\n' ERROR: "$*"
@ -13,8 +24,7 @@ public_usage() {
cat << EOF
${name}: utilisation
${name} start|status|stop|watch NOM_SERVEUR
${name} list
${name} usage
${name} list|active|usage
EOF
}
@ -26,8 +36,8 @@ error_usage() {
public_start() {
if [ -n "$1" ]; then
mcscreen -d -m -S "$1" \
"/srv/minecraft/bin/${1}"
screen -d -m -S "$1" \
"./${1}"
else
error_usage
fi
@ -36,7 +46,7 @@ public_start() {
public_status() {
if [ -n "$1" ]; then
printf '\033[1m%s\033[0m : ' "$1"
if mcscreen -ls "$1" > /dev/null 2>&1; then
if screen -ls "$1" > /dev/null 2>&1; then
echo "en cours d'exécution"
else
echo "non en cours d'exécution"
@ -48,26 +58,34 @@ public_status() {
public_stop() {
if [ -n "$1" ]; then
mcscreen -S "$1" -X stuff '^E^Ustop^M'
screen -S "$1" -X stuff '^E^Ustop^M'
else
error_usage
fi
}
public_watch() {
mcscreen -dr "$1"
screen -dr "$1"
}
public_active() {
screen -ls
}
public_list() {
mcscreen -ls
echo "Serveurs disponibles :"
ls --color=auto
}
verb="$1"
shift
case "$verb" in
start|status|stop|watch|list|usage)
start|status|stop|watch|active|list|usage)
"public_${verb}" "$@"
;;
"")
public_active
;;
*)
error_usage
;;