#!/bin/bash # Load configuration variables . /etc/default/craftbukkit # Some colors red='\033[0;31m' orange='\033[0;33m' green='\033[0;32m' NC='\033[0m' server_running() { if [ -z "$(pgrep -f -n $JARNAME)" ]; then return 1 else return 0 fi } case "$1" in console) if server_running; then sudo -u ${USER} tmux attach -t craftbukkit-console else echo -e "${orange}[warn]${NC} No server running ... ${orange}(warning).${NC}" exit 7 fi ;; backup) # @TODO ;; full-backup) # @TODO ;; whitelist-add) if server_running; then if [ $# -gt 1 && $# -lt 3 ]; then shift sudo -u ${USER} -H tmux send-keys -t craftbukkit-console "whitelist add $2" C-m >/dev/null 2>&1 else echo "Usage: $0 $1 [username]" exit 1 fi else echo -e "${orange}[warn]${NC} No server running ... ${orange}(warning).${NC}" exit 7 fi ;; whitelist-remove) if server_running; then if [ $# -gt 1 && $# -lt 3 ]; then shift sudo -u ${USER} -H tmux send-keys -t craftbukkit-console "whitelist remove $2" C-m >/dev/null 2>&1 else echo "Usage: $0 $1 [username]" exit 1 fi else echo -e "${orange}[warn]${NC} No server running ... ${orange}(warning).${NC}" exit 7 fi ;; --help|-h) echo "Usage: $0 COMMAND" echo echo "Available commands:" echo -e " console \t\t Connects to the console" echo -e " backup \t\t Creates a world backup" echo -e " full-backup \t Creates a full backup" echo -e " wl-add \t\t Creates a full backup" echo -e " wl-rm \t\t Creates a full backup" echo -e " --help, -h \t Prints this page" ;; *) echo "No such command" echo "Usage: $0 {console|backup|full-backup|wl-add|wl-rm}" echo "Or try $0 --help for help" exit 1 ;; esac exit 0