Indentation: Use tabs everywhere

This commit is contained in:
Gordian Edenhofer 2015-12-13 15:32:38 +01:00
parent 57d7104491
commit 761f7b2418
3 changed files with 153 additions and 153 deletions

View File

@ -15,28 +15,28 @@ options=(!strip)
install=${pkgname}.install install=${pkgname}.install
backup=('etc/conf.d/minecraft') backup=('etc/conf.d/minecraft')
source=("https://s3.amazonaws.com/Minecraft.Download/versions/${pkgver}/minecraft_server.${pkgver}.jar" source=("https://s3.amazonaws.com/Minecraft.Download/versions/${pkgver}/minecraft_server.${pkgver}.jar"
"minecraftd-backup.service" "minecraftd-backup.service"
"minecraftd-backup.timer" "minecraftd-backup.timer"
"minecraftd.service" "minecraftd.service"
"minecraftd.conf" "minecraftd.conf"
"minecraftd.sh") "minecraftd.sh")
noextract=("minecraft_server.${pkgver}.jar") noextract=("minecraft_server.${pkgver}.jar")
md5sums=('a0671390aa0691e70a950155aab06ffb' md5sums=('a0671390aa0691e70a950155aab06ffb'
'2cf6cdf65e0ed6aa6d452943b1e84357' '2cf6cdf65e0ed6aa6d452943b1e84357'
'c644abdf293c2f98033a64d732a4945c' 'c644abdf293c2f98033a64d732a4945c'
'5ed78e366146e47f8498347e93ad5423' '5ed78e366146e47f8498347e93ad5423'
'd4656f27716fd78ab64344a517b07443' 'd4656f27716fd78ab64344a517b07443'
'1991eb0aedeba1dab2371f22a6736b47') '1991eb0aedeba1dab2371f22a6736b47')
package() { package() {
install -Dm644 minecraftd.conf "${pkgdir}/etc/conf.d/minecraft" install -Dm644 minecraftd.conf "${pkgdir}/etc/conf.d/minecraft"
install -Dm755 minecraftd.sh "${pkgdir}/usr/bin/minecraftd" install -Dm755 minecraftd.sh "${pkgdir}/usr/bin/minecraftd"
install -Dm644 minecraftd.service "${pkgdir}/usr/lib/systemd/system/minecraftd.service" install -Dm644 minecraftd.service "${pkgdir}/usr/lib/systemd/system/minecraftd.service"
install -Dm644 minecraftd-backup.service "${pkgdir}/usr/lib/systemd/system/minecraftd-backup.service" install -Dm644 minecraftd-backup.service "${pkgdir}/usr/lib/systemd/system/minecraftd-backup.service"
install -Dm644 minecraftd-backup.timer "${pkgdir}/usr/lib/systemd/system/minecraftd-backup.timer" install -Dm644 minecraftd-backup.timer "${pkgdir}/usr/lib/systemd/system/minecraftd-backup.timer"
install -Dm644 minecraft_server.${pkgver}.jar "${pkgdir}/srv/minecraft/minecraft_server.${pkgver}.jar" install -Dm644 minecraft_server.${pkgver}.jar "${pkgdir}/srv/minecraft/minecraft_server.${pkgver}.jar"
ln -s "minecraft_server.${pkgver}.jar" "${pkgdir}/srv/minecraft/minecraft_server.jar" ln -s "minecraft_server.${pkgver}.jar" "${pkgdir}/srv/minecraft/minecraft_server.jar"
mkdir -p "${pkgdir}/var/log/" mkdir -p "${pkgdir}/var/log/"
ln -s "/srv/minecraft/logs" "${pkgdir}/var/log/minecraft" #&>/dev/null ln -s "/srv/minecraft/logs" "${pkgdir}/var/log/minecraft" #&>/dev/null
} }

View File

@ -3,33 +3,33 @@ SERVER_ROOT="/srv/minecraft"
_update() { _update() {
getent group "${USER}" &>/dev/null getent group "${USER}" &>/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo -e "\e[34;1m==>\e[39;1m Adding ${USER} system group... \e[0m" echo -e "\e[34;1m==>\e[39;1m Adding ${USER} system group... \e[0m"
groupadd -r ${USER} 1>/dev/null groupadd -r ${USER} 1>/dev/null
fi fi
getent passwd "${USER}" &>/dev/null getent passwd "${USER}" &>/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo -e "\e[34;1m==>\e[39;1m Adding ${USER} system user... \e[0m" echo -e "\e[34;1m==>\e[39;1m Adding ${USER} system user... \e[0m"
useradd -r -g ${USER} -d "${SERVER_ROOT}" ${USER} 1>/dev/null useradd -r -g ${USER} -d "${SERVER_ROOT}" ${USER} 1>/dev/null
fi fi
chown -R ${USER}:${USER} "${SERVER_ROOT}" chown -R ${USER}:${USER} "${SERVER_ROOT}"
echo -e "\e[34;1m==>\e[39;1m NOTE: The world data is stored under ${SERVER_ROOT} and the server runs \e[0m" echo -e "\e[34;1m==>\e[39;1m NOTE: The world data is stored under ${SERVER_ROOT} and the server runs \e[0m"
echo -e "\e[34;1m==>\e[39;1m as ${USER} user to increase security. \e[0m" echo -e "\e[34;1m==>\e[39;1m as ${USER} user to increase security. \e[0m"
echo -e "\e[34;1m==>\e[39;1m NOTE: Use the minecraft script under /usr/bin/minecraftd to start, stop or backup the server \e[0m" echo -e "\e[34;1m==>\e[39;1m NOTE: Use the minecraft script under /usr/bin/minecraftd to start, stop or backup the server \e[0m"
echo -e "\e[34;1m==>\e[39;1m and the configuration file under /etc/conf.d/minecraft to adjust it to your liking. \e[0m" echo -e "\e[34;1m==>\e[39;1m and the configuration file under /etc/conf.d/minecraft to adjust it to your liking. \e[0m"
echo -e "\e[34;1m==>\e[39;1m NOTE: For the server to start you have to accept the EULA in ${SERVER_ROOT}/eula.txt \e[0m" echo -e "\e[34;1m==>\e[39;1m NOTE: For the server to start you have to accept the EULA in ${SERVER_ROOT}/eula.txt \e[0m"
echo -e "\e[34;1m==>\e[39;1m which is generated after the first server start. \e[0m" echo -e "\e[34;1m==>\e[39;1m which is generated after the first server start. \e[0m"
} }
post_install() { post_install() {
_update _update
} }
post_upgrade() { post_upgrade() {
_update _update
} }
pre_remove() { pre_remove() {
@ -50,6 +50,6 @@ post_remove() {
fi fi
# Notifying the user of kept dirs # Notifying the user of kept dirs
[ -d ${SERVER_ROOT} ] && chown root:root ${SERVER_ROOT} && echo -e "\e[34;1m==>\e[39;1m NOTE: Game saves in ${SERVER_ROOT} were kept on your system.\e[0m" [ -d ${SERVER_ROOT} ] && chown root:root ${SERVER_ROOT} && echo -e "\e[34;1m==>\e[39;1m NOTE: Game saves in ${SERVER_ROOT} were kept on your system.\e[0m"
[ -d /etc/conf.d/minecraft ] && echo -e "\e[34;1m==>\e[39;1m NOTE: Your configuration file /etc/conf.d/minecraft was kept on your system.\e[0m" [ -d /etc/conf.d/minecraft ] && echo -e "\e[34;1m==>\e[39;1m NOTE: Your configuration file /etc/conf.d/minecraft was kept on your system.\e[0m"
} }

View File

@ -20,8 +20,8 @@ JAVA_PARMS="${JAVA_PARMS:-"-Xmx${MAXHEAP} -Xms${MINHEAP} -XX:ParallelGCThreads=$
# Check for sudo rigths # Check for sudo rigths
if [ $(sudo whoami) != "root" ]; then if [ $(sudo whoami) != "root" ]; then
echo "You must have sudo access in order to use this script." echo "You must have sudo access in order to use this script."
exit 1 exit 1
fi fi
# Pipe any given argument to the minecraft server console # Pipe any given argument to the minecraft server console
@ -31,175 +31,175 @@ mc_command() {
# Start the server if it is not already running # Start the server if it is not already running
server_start() { server_start() {
sudo -u ${MC_USER} screen -S ${SESSION_NAME} -Q select . > /dev/null sudo -u ${MC_USER} screen -S ${SESSION_NAME} -Q select . > /dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "A screen ${SESSION_NAME} session is already running. Please close it first." echo "A screen ${SESSION_NAME} session is already running. Please close it first."
else else
echo -en "Starting server... " echo -en "Starting server... "
sudo -u ${MC_USER} screen -dmS ${SESSION_NAME} /bin/bash -c "cd ${SERVER_ROOT}; java ${JAVA_PARMS} -jar ${SERVER_ROOT}/${MAIN_JAR} nogui" sudo -u ${MC_USER} screen -dmS ${SESSION_NAME} /bin/bash -c "cd ${SERVER_ROOT}; java ${JAVA_PARMS} -jar ${SERVER_ROOT}/${MAIN_JAR} nogui"
echo -e "\e[39;1m done\e[0m" echo -e "\e[39;1m done\e[0m"
fi fi
} }
# Stop the server gracefully by saving everything prior and warning the users # Stop the server gracefully by saving everything prior and warning the users
server_stop() { server_stop() {
sudo -u ${MC_USER} screen -S ${SESSION_NAME} -Q select . > /dev/null sudo -u ${MC_USER} screen -S ${SESSION_NAME} -Q select . > /dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
mc_command save-all mc_command save-all
mc_command say "Server is going down in 10 seconds! HURRY UP WITH WATHEVER YOU ARE DOING!" # Warning the users mc_command say "Server is going down in 10 seconds! HURRY UP WITH WATHEVER YOU ARE DOING!" # Warning the users
echo -en "Server is going down in... " echo -en "Server is going down in... "
for i in $(seq 1 10); for i in $(seq 1 10);
do do
mc_command say "down in... $(expr 10 - $i)" mc_command say "down in... $(expr 10 - $i)"
echo -n " $(expr 10 - $i)" echo -n " $(expr 10 - $i)"
sleep 1 sleep 1
done done
mc_command stop mc_command stop
echo -e "\e[39;1m done\e[0m" echo -e "\e[39;1m done\e[0m"
else else
echo "The corresponding screen session for ${SESSION_NAME} was already dead." echo "The corresponding screen session for ${SESSION_NAME} was already dead."
fi fi
} }
# Print whether the server is running and if so give some information about memory usage and threads # Print whether the server is running and if so give some information about memory usage and threads
server_status() { server_status() {
sudo -u ${MC_USER} screen -S ${SESSION_NAME} -Q select . > /dev/null sudo -u ${MC_USER} screen -S ${SESSION_NAME} -Q select . > /dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo -e "Status:\e[39;1m running\e[0m" echo -e "Status:\e[39;1m running\e[0m"
# Calculating memory usage # Calculating memory usage
for p in $(sudo -u ${MC_USER} pgrep -f ${MAIN_JAR}); do for p in $(sudo -u ${MC_USER} pgrep -f ${MAIN_JAR}); do
ps -p$p -O rss | tail -n1; ps -p$p -O rss | tail -n1;
done | gawk '{ count ++; sum += $2 }; END {count --; print "Number of processes =", count, "(screen, bash,", count-2, "x java)"; print "Total memory usage =", sum/1024, "MB" ;};' done | gawk '{ count ++; sum += $2 }; END {count --; print "Number of processes =", count, "(screen, bash,", count-2, "x java)"; print "Total memory usage =", sum/1024, "MB" ;};'
else else
echo -e "Status:\e[39;1m stopped\e[0m" echo -e "Status:\e[39;1m stopped\e[0m"
fi fi
} }
# Restart the complete server by shutting it down and starting it again # Restart the complete server by shutting it down and starting it again
server_restart() { server_restart() {
sudo -u ${MC_USER} screen -S ${SESSION_NAME} -Q select . > /dev/null sudo -u ${MC_USER} screen -S ${SESSION_NAME} -Q select . > /dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
server_stop server_stop
sleep 0.1 sleep 0.1
server_start server_start
else else
server_start server_start
fi fi
} }
# Backup the directories specified in $WORLDPATHS # Backup the directories specified in $WORLDPATHS
backup_files() { backup_files() {
which tar &> /dev/null which tar &> /dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "The tar binaries are needed for a backup." echo "The tar binaries are needed for a backup."
exit 2 exit 2
fi fi
echo "Starting backup..." echo "Starting backup..."
FILE="`date +%Y%m%d%H%M%S`.tar.gz" FILE="`date +%Y%m%d%H%M%S`.tar.gz"
sudo -u ${MC_USER} mkdir -p ${BACKUPPATH} sudo -u ${MC_USER} mkdir -p ${BACKUPPATH}
sudo -u ${MC_USER} screen -S ${SESSION_NAME} -Q select . > /dev/null sudo -u ${MC_USER} screen -S ${SESSION_NAME} -Q select . > /dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
mc_command save-off mc_command save-off
mc_command save-all mc_command save-all
sync && wait sync && wait
sudo -u ${MC_USER} tar -czf ${BACKUPPATH}/${FILE} --totals ${WORLDPATHS} 2>&1 | grep -v "tar: Removing leading " sudo -u ${MC_USER} tar -czf ${BACKUPPATH}/${FILE} --totals ${WORLDPATHS} 2>&1 | grep -v "tar: Removing leading "
mc_command save-on mc_command save-on
else else
sudo -u ${MC_USER} tar -czf ${BACKUPPATH}/${FILE} --totals ${WORLDPATHS} 2>&1 | grep -v "tar: Removing leading " sudo -u ${MC_USER} tar -czf ${BACKUPPATH}/${FILE} --totals ${WORLDPATHS} 2>&1 | grep -v "tar: Removing leading "
fi fi
echo -e "\e[39;1mbackup completed\e[0m\n" echo -e "\e[39;1mbackup completed\e[0m\n"
echo -n "Only keeping the last ${KEEP_BACKUPS} backups and removing the other ones..." echo -n "Only keeping the last ${KEEP_BACKUPS} backups and removing the other ones..."
BACKUP_COUNT=$(for f in ${BACKUPPATH}/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*; do echo $f; done | wc -l) BACKUP_COUNT=$(for f in ${BACKUPPATH}/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*; do echo $f; done | wc -l)
if [ $(expr ${BACKUP_COUNT} - ${KEEP_BACKUPS}) -gt 0 ]; then if [ $(expr ${BACKUP_COUNT} - ${KEEP_BACKUPS}) -gt 0 ]; then
sudo -u ${MC_USER} rm $(for f in ${BACKUPPATH}/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*; do echo $f; done | head -n$(expr ${BACKUP_COUNT} - ${KEEP_BACKUPS})) sudo -u ${MC_USER} rm $(for f in ${BACKUPPATH}/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*; do echo $f; done | head -n$(expr ${BACKUP_COUNT} - ${KEEP_BACKUPS}))
echo -e "\e[39;1m done\e[0m ($(expr ${BACKUP_COUNT} - ${KEEP_BACKUPS}) backup(s) pruned)" echo -e "\e[39;1m done\e[0m ($(expr ${BACKUP_COUNT} - ${KEEP_BACKUPS}) backup(s) pruned)"
else else
echo -e "\e[39;1m done\e[0m (no backups pruned)" echo -e "\e[39;1m done\e[0m (no backups pruned)"
fi fi
} }
# Run the given comman at the minecraft server console # Run the given comman at the minecraft server console
server_command() { server_command() {
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
echo "No server command specified. Try 'help' for a list of commands." echo "No server command specified. Try 'help' for a list of commands."
exit 1 exit 1
fi fi
sudo -u ${MC_USER} screen -S ${SESSION_NAME} -Q select . > /dev/null sudo -u ${MC_USER} screen -S ${SESSION_NAME} -Q select . > /dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
mc_command "$@" mc_command "$@"
tailf -n 0 ${LOGPATH}/latest.log & tailf -n 0 ${LOGPATH}/latest.log &
TAILFPID=$! # Process id of tailf command TAILFPID=$! # Process id of tailf command
sleep 0.1 sleep 0.1
kill ${TAILFPID} kill ${TAILFPID}
else else
echo "There is no ${SESSION_NAME} session to connect to." echo "There is no ${SESSION_NAME} session to connect to."
fi fi
} }
# Enter the screen minecraft session # Enter the screen minecraft session
server_console() { server_console() {
sudo -u ${MC_USER} screen -S ${SESSION_NAME} -Q select . > /dev/null sudo -u ${MC_USER} screen -S ${SESSION_NAME} -Q select . > /dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
sudo -u ${MC_USER} screen -S ${SESSION_NAME} -rx sudo -u ${MC_USER} screen -S ${SESSION_NAME} -rx
else else
echo "There is no ${SESSION_NAME} session to connect to." echo "There is no ${SESSION_NAME} session to connect to."
fi fi
} }
# Help function, no arguments required # Help function, no arguments required
help() { help() {
cat << 'EOF' cat << 'EOF'
This script was design to easily control any minecraft server. Quite every parameter for a given This script was design to easily control any minecraft server. Quite every parameter for a given
minecraft server derivative can be altered by editing the variables in the configuration file. minecraft server derivative can be altered by editing the variables in the configuration file.
Usage: minecraftd {start|stop|status|backup|command <command>|console} Usage: minecraftd {start|stop|status|backup|command <command>|console}
start Start the minecraft server start Start the minecraft server
stop Stop the minecraft server stop Stop the minecraft server
restart Restart the minecraft server restart Restart the minecraft server
status Print some status information status Print some status information
backup Backup the world data backup Backup the world data
command <command> Run the given comman at the minecraft server console command <command> Run the given comman at the minecraft server console
console Enter the server console through a screen session console Enter the server console through a screen session
Copyright (c) Gordian Edenhofer <gordian.edenhofer@gmail.com> Copyright (c) Gordian Edenhofer <gordian.edenhofer@gmail.com>
EOF EOF
} }
case "$1" in case "$1" in
start) start)
server_start server_start
;; ;;
stop) stop)
server_stop server_stop
;; ;;
status) status)
server_status server_status
;; ;;
restart) restart)
server_restart server_restart
;; ;;
console) console)
server_console server_console
;; ;;
command) command)
server_command "${@:2}" server_command "${@:2}"
;; ;;
backup) backup)
backup_files backup_files
;; ;;
*|-h|--help) *|-h|--help)
help help
esac esac
exit 0 exit 0