2023-07-03 19:55:23 +02:00
|
|
|
#!/bin/bash
|
2023-07-03 19:50:13 +02:00
|
|
|
|
2023-07-04 20:24:37 +02:00
|
|
|
exec_user() {
|
2023-07-04 20:35:11 +02:00
|
|
|
local user="$1"
|
|
|
|
shift
|
|
|
|
if [ "$USER" != "$user" ]; then
|
|
|
|
exec sudo -u "$user" "$0" "$@"
|
2023-07-04 20:24:37 +02:00
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-07-04 20:35:11 +02:00
|
|
|
exec_user minecraft "$@"
|
2023-07-04 20:24:37 +02:00
|
|
|
|
|
|
|
cd ~/bin || exit
|
2023-07-03 19:50:13 +02:00
|
|
|
|
|
|
|
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
|
2023-07-10 15:30:53 +02:00
|
|
|
${name} start|status|stop|watch|restart NOM_SERVEUR
|
2023-07-04 20:31:59 +02:00
|
|
|
${name} list|active|usage
|
2023-07-03 19:50:13 +02:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
error_usage() {
|
|
|
|
print_error "Utilisation invalide."
|
|
|
|
>&2 public_usage
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
public_start() {
|
2023-07-03 20:01:25 +02:00
|
|
|
if [ -n "$1" ]; then
|
2023-07-04 20:24:37 +02:00
|
|
|
screen -d -m -S "$1" \
|
|
|
|
"./${1}"
|
2023-07-03 20:01:25 +02:00
|
|
|
else
|
|
|
|
error_usage
|
|
|
|
fi
|
2023-07-03 19:50:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public_status() {
|
2023-07-03 20:01:25 +02:00
|
|
|
if [ -n "$1" ]; then
|
|
|
|
printf '\033[1m%s\033[0m : ' "$1"
|
2023-07-04 20:24:37 +02:00
|
|
|
if screen -ls "$1" > /dev/null 2>&1; then
|
2023-07-03 20:01:25 +02:00
|
|
|
echo "en cours d'exécution"
|
|
|
|
else
|
|
|
|
echo "non en cours d'exécution"
|
|
|
|
fi
|
2023-07-03 19:50:13 +02:00
|
|
|
else
|
2023-07-03 20:01:25 +02:00
|
|
|
error_usage
|
2023-07-03 19:50:13 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
public_stop() {
|
2023-07-03 20:01:25 +02:00
|
|
|
if [ -n "$1" ]; then
|
2023-07-04 20:24:37 +02:00
|
|
|
screen -S "$1" -X stuff '^E^Ustop^M'
|
2023-07-03 20:01:25 +02:00
|
|
|
else
|
|
|
|
error_usage
|
|
|
|
fi
|
2023-07-03 19:50:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public_watch() {
|
2023-07-04 20:24:37 +02:00
|
|
|
screen -dr "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
public_active() {
|
|
|
|
screen -ls
|
2023-07-03 19:50:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public_list() {
|
2023-07-04 20:24:37 +02:00
|
|
|
echo "Serveurs disponibles :"
|
|
|
|
ls --color=auto
|
2023-07-03 19:50:13 +02:00
|
|
|
}
|
|
|
|
|
2023-07-10 15:30:53 +02:00
|
|
|
public_restart() {
|
|
|
|
set -e
|
|
|
|
stop "$@"
|
|
|
|
start "$@"
|
|
|
|
set +e
|
|
|
|
}
|
|
|
|
|
2023-07-03 19:50:13 +02:00
|
|
|
verb="$1"
|
|
|
|
shift
|
|
|
|
case "$verb" in
|
2023-07-10 15:30:53 +02:00
|
|
|
start|status|stop|watch|active|list|usage|restart)
|
2023-07-03 19:50:13 +02:00
|
|
|
"public_${verb}" "$@"
|
|
|
|
;;
|
2023-07-04 20:24:37 +02:00
|
|
|
"")
|
|
|
|
public_active
|
2023-07-04 20:29:09 +02:00
|
|
|
;;
|
2023-07-03 19:50:13 +02:00
|
|
|
*)
|
|
|
|
error_usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|