From dd924704feb0f034abdf3c20d5c658cbb46aab7d Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Wed, 17 Feb 2016 09:46:34 -0800 Subject: [PATCH 1/2] add freebsd support --- installers/freebsd.sh | 69 +++++++++++++++++++++++++++++++++++++++++++ installers/install.sh | 42 ++++++++++++++++++++------ 2 files changed, 102 insertions(+), 9 deletions(-) create mode 100644 installers/freebsd.sh diff --git a/installers/freebsd.sh b/installers/freebsd.sh new file mode 100644 index 00000000..4fa036fa --- /dev/null +++ b/installers/freebsd.sh @@ -0,0 +1,69 @@ +#!/bin/sh +# +# NOTES: +# - uses the standard FreeBSD Bourne shell, meaning +POSIX and -bash +# - does not attempt to load common.sh, due to heavy Linux assumptions +# - user creation is done automatically by the FreeBSD port of minecraft-server + +install_error() { + echo -e "\n\033[1;37;41mMSM INSTALL ERROR: $*\033[m" + exit 1 +} + +update_system_packages() { + install_log "Updating sources" + sudo pkg update || install_error "Couldn't update package list" +} + +install_minecraft() +{ + echo "installing java" + pkg install openjdk8 || exit + + echo "installing minecraft deps" + pkg install tmux dialog4ports screen rsync || exit + + echo "installing minecraft" + if grep -qs minecraft /etc/make.conf; then + # already configured + else + echo "games_minecraft-server_SET=DAEMON" | tee -a /etc/make.conf + fi + export BATCH=${BATCH:="1"} + make -C /usr/ports/games/minecraft-server install clean +} + +configure_minecraft() +{ + echo "configuring minecraft" + + service minecraft onestart + local _eula="$STAGE_MNT/usr/local/etc/minecraft-server/eula.txt" + until [ -f "$_eula" ]; do + echo "waiting for $_eula to appear" + sleep 1 + done + echo "accepting EULA" + sed -i .bak -e '/^eula/ s/false/true/' "$_eula" + echo "done" +} + +start_minecraft() +{ + echo "starting minecraft" + sysrc minecraft_enable=YES + service minecraft start + sleep 3 +} + +test_minecraft() +{ + echo "testing minecraft" + sockstat -l -4 | grep :25565 || exit + echo "it worked" +} + +install_minecraft +configure_minecraft +start_minecraft +test_minecraft diff --git a/installers/install.sh b/installers/install.sh index 85f33baa..be7d786d 100644 --- a/installers/install.sh +++ b/installers/install.sh @@ -1,4 +1,5 @@ BASE_URL="https://raw.githubusercontent.com/msmhq/msm/master/installers/" +TMP_FILE="/tmp/msminst.sh" function check_os() { if [[ -f /etc/debian_version ]]; then @@ -7,25 +8,48 @@ function check_os() { INSTALL_SCRIPT="redhat.sh" elif [[ -f /etc/arch-release ]]; then INSTALL_SCRIPT="arch.sh" + elif [[ -f /bin/freebsd-version ]]; then + INSTALL_SCRIPT="freebsd.sh" else echo "Error, unsupported distribution. Please install manually." exit 1 fi } +function download_installer() { + local _dl_uri="${BASE_URL}/${INSTALL_SCRIPT}" + + case "$1" in + curl) + curl -L "$_dl_uri" -o "$TMP_FILE" + ;; + wget) + wget -q "$_dl_uri" -O "$TMP_FILE" + ;; + fetch) + fetch -m -o "$TMP_FILE" "$_dl_uri" + ;; + esac +} + function get_installer() { - type curl 1>/dev/null 2>&1 - if [[ $? -eq 0 ]]; then - curl -L "${BASE_URL}/${INSTALL_SCRIPT}" -o /tmp/msminst.sh - else - wget -q "${BASE_URL}/${INSTALL_SCRIPT}" -O /tmp/msminst.sh - fi - chmod u+x /tmp/msminst.sh + + for util in curl wget fetch; do + type "$util" 1>/dev/null 2>&1 + if [[ $? -eq 0 ]]; then + download_installer $util + return # we suceeded, exit this function + fi + done + + echo "neither curl, wget, nor fetch was found. Install one and try again." + exit 1 } function do_install() { - if [[ -f /tmp/msminst.sh ]]; then - /tmp/msminst.sh && rm -f /tmp/msminst.sh + if [[ -f "$TMP_FILE" ]]; then + chmod u+x "$TMP_FILE" + "$TMP_FILE" && rm -f "$TMP_FILE" else echo "Error, failed to download install script." exit 1 From 4805ca7cc51353b6ed3f6b07811293aed4ef249f Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 9 Jul 2021 22:47:19 -0400 Subject: [PATCH 2/2] freebsd.sh, whitespace fixes --- installers/freebsd.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/installers/freebsd.sh b/installers/freebsd.sh index 4fa036fa..8675f05c 100644 --- a/installers/freebsd.sh +++ b/installers/freebsd.sh @@ -24,8 +24,9 @@ install_minecraft() pkg install tmux dialog4ports screen rsync || exit echo "installing minecraft" - if grep -qs minecraft /etc/make.conf; then - # already configured + if grep -qs minecraft /etc/make.conf; + then + # already configured else echo "games_minecraft-server_SET=DAEMON" | tee -a /etc/make.conf fi