mirror of
https://github.com/msmhq/msm.git
synced 2024-08-30 18:12:35 +00:00
Abstracted install.sh and implemented Debian and Red Hat installs.
This commit is contained in:
parent
138ef441ab
commit
c191a0cc2d
2
install-debian.sh
Normal file
2
install-debian.sh
Normal file
@ -0,0 +1,2 @@
|
||||
cd installers
|
||||
bash install.sh debian.sh
|
2
install-redhat.sh
Normal file
2
install-redhat.sh
Normal file
@ -0,0 +1,2 @@
|
||||
cd installers
|
||||
bash install.sh redhat.sh
|
126
installers/common.sh
Normal file
126
installers/common.sh
Normal file
@ -0,0 +1,126 @@
|
||||
if [ -f defaults.conf ]; then
|
||||
source defaults.conf
|
||||
fi
|
||||
|
||||
msm_dir="${MSM_DIRECTORY:-/opt/msm}"
|
||||
msm_user="${MSM_USERNAME:-minecraft}"
|
||||
dl_dir="$(mktemp -t msm)"
|
||||
|
||||
# Outputs an MSM INSTALL log line
|
||||
function install_log() {
|
||||
echo -e "\n\033[1;32mMSM INSTALL: $*\033[m"
|
||||
}
|
||||
|
||||
# Outputs an MSM INSTALL ERROR log line and exits with status code 1
|
||||
function install_error() {
|
||||
echo -e "\n\033[1;37;41mMSM INSTALL ERROR: $*\033[m"
|
||||
exit 1
|
||||
}
|
||||
|
||||
### NOTE: all the below functions are overloadable for system-specific installs
|
||||
### NOTE: some of the below functions MUST be overloaded due to system-specific installs
|
||||
|
||||
# Runs a system software update to make sure we're using all fresh packages
|
||||
function update_system_packages() {
|
||||
# OVERLOAD THIS
|
||||
install_error "No function definition for update_system_packages"
|
||||
}
|
||||
|
||||
# Installs additional dependencies (screen, rsync, zip, wget) using system package manager
|
||||
function install_dependencies() {
|
||||
# OVERLOAD THIS
|
||||
install_error "No function definition for install_dependencies"
|
||||
}
|
||||
|
||||
# Verifies existence of or adds user for Minecraft server (default "minecraft")
|
||||
function add_minecraft_user() {
|
||||
install_log "Creating default user '$msm_user'"
|
||||
useradd --system $msm_user
|
||||
}
|
||||
|
||||
# Verifies existence and permissions of msm server directory (default /opt/msm)
|
||||
function create_msm_directories() {
|
||||
install_log "Creating MSM directories"
|
||||
if [ ! -d "$msm_dir" ]; then
|
||||
mkdir -p "$msm_dir" || install_error "Couldn't create directory '$msm_dir'"
|
||||
fi
|
||||
chown -R $msm_user:$msm_user "$msm_dir" || install_error "Couldn't change file ownership for '$msm_dir'"
|
||||
}
|
||||
|
||||
# Fetches latest msm.conf, cron job, and init script
|
||||
function download_latest_files() {
|
||||
if [ ! -d "$dl_dir" ]; then
|
||||
install_error "Temporary download directory was not created properly"
|
||||
fi
|
||||
|
||||
install_log "Downloading latest MSM configuration file"
|
||||
wget https://raw.github.com/marcuswhybrow/minecraft-server-manager/latest/msm.conf \
|
||||
-O "$dl_dir/msm.conf.orig" || install_error "Couldn't download configuration file"
|
||||
|
||||
install_log "Downloading latest MSM cron file"
|
||||
wget https://raw.github.com/marcuswhybrow/minecraft-server-manager/latest/cron/msm \
|
||||
-O "$dl_dir/msm.cron.orig" || install_error "Couldn't download cron file"
|
||||
|
||||
install_log "Downloading latest MSM version"
|
||||
wget https://raw.github.com/marcuswhybrow/minecraft-server-manager/latest/init/msm \
|
||||
-O "$dl_dir/msm.init.orig" || install_error "Couldn't download init file"
|
||||
}
|
||||
|
||||
# Patches msm.conf and cron job to use specified username and directory
|
||||
function patch_latest_files() {
|
||||
# patch config file
|
||||
install_log "Patching MSM configuration file"
|
||||
sed 's#USERNAME="minecraft"#USERNAME="'$msm_user'"#g' "$dl_dir/msm.conf.orig" | \
|
||||
sed "s#/opt/msm#$msm_dir#g" >"$dl_dir/msm.conf"
|
||||
|
||||
# patch cron file
|
||||
install_log "Patching MSM cron file"
|
||||
awk '{ if ($0 !~ /^#/) sub(/minecraft/, "'$msm_user'"); print }' \
|
||||
"$dl_dir/msm.cron.orig" >"$dl_dir/msm.cron"
|
||||
}
|
||||
|
||||
# Installs msm.conf into /etc
|
||||
function install_config() {
|
||||
install_log "Installing MSM configuration file"
|
||||
install -b -m0644 "$dl_dir/msm.conf" /etc/msm.conf
|
||||
if [ ! -e /etc/msm.conf ]; then
|
||||
install_error "Couldn't install configuration file"
|
||||
fi
|
||||
}
|
||||
|
||||
# Installs msm.cron into /etc/cron.d
|
||||
function install_cron() {
|
||||
install_log "Installing MSM cron file"
|
||||
install "$dl_dir/msm.cron" /etc/cron.d/msm || install_error "Couldn't install cron file"
|
||||
}
|
||||
|
||||
# Reloads cron service (if necessary)
|
||||
function reload_cron() {
|
||||
# OVERLOAD THIS
|
||||
install_error "No function defined for reload_cron"
|
||||
}
|
||||
|
||||
# Installs init script into /etc/init.d
|
||||
function install_init() {
|
||||
install_log "Installing MSM init file"
|
||||
install -b "$dl_dir/msm.init" /etc/init.d/msm || install_error "Couldn't install init file"
|
||||
|
||||
install_log "Making MSM accessible as the command 'msm'"
|
||||
ln -s /etc/init.d/msm /usr/local/bin/msm
|
||||
}
|
||||
|
||||
# Enables init script in default runlevels
|
||||
function enable_init() {
|
||||
# OVERLOAD THIS
|
||||
install_error "No function defined for enable_init"
|
||||
}
|
||||
|
||||
# Updates rest of MSM using init script updater
|
||||
function update_msm() {
|
||||
install_log "Asking MSM to update itself"
|
||||
/etc/init.d/msm update --noinput
|
||||
}
|
||||
|
||||
function install_complete() {
|
||||
install_log "Done. Type 'msm help' to get started. Have fun!"
|
||||
}
|
@ -1,36 +1,26 @@
|
||||
echo "\033[1;32mMSM INSTALL: Updating sources\033[m"
|
||||
apt-get update
|
||||
source common.sh
|
||||
|
||||
echo "\n\033[1;32mMSM INSTALL: Installing required packages\033[m"
|
||||
apt-get install screen rsync zip
|
||||
function update_system_packages() {
|
||||
install_log "Updating sources"
|
||||
apt-get update || install_error "Couldn't update package list"
|
||||
apt-get upgrade || install_error "Couldn't upgrade packages"
|
||||
}
|
||||
|
||||
echo "\n\033[1;32mMSM INSTALL: Creating default user \"minecraft\"\033[m"
|
||||
adduser --system minecraft
|
||||
function install_dependencies() {
|
||||
install_log "Installing required packages"
|
||||
apt-get install screen rsync zip || install_error "Couldn't install dependencies"
|
||||
}
|
||||
|
||||
echo "\n\033[1;32mMSM INSTALL: Creating MSM directories\033[m"
|
||||
mkdir -p /opt/msm
|
||||
chown minecraft:minecraft /opt/msm
|
||||
function reload_cron() {
|
||||
install_log "Reloading cron service"
|
||||
if [ -x $(which service) ]; then
|
||||
service cron reload
|
||||
else
|
||||
/etc/init.d/cron reload
|
||||
fi
|
||||
}
|
||||
|
||||
echo "\n\033[1;32mMSM INSTALL: Downloading latest MSM configuration file\033[m"
|
||||
wget https://raw.github.com/marcuswhybrow/minecraft-server-manager/latest/msm.conf -O /etc/msm.conf
|
||||
|
||||
echo "\n\033[1;32mMSM INSTALL: Downloading latest MSM cron file\033[m"
|
||||
wget https://raw.github.com/marcuswhybrow/minecraft-server-manager/latest/cron/msm -O /etc/cron.d/msm
|
||||
service cron reload
|
||||
|
||||
echo "\n\033[1;32mMSM INSTALL: Downloading latest MSM version\033[m"
|
||||
wget https://raw.github.com/marcuswhybrow/minecraft-server-manager/latest/init/msm -O /etc/init.d/msm
|
||||
|
||||
echo "\n\033[1;32mMSM INSTALL: Giving it the necessary permissions\033[m"
|
||||
chmod 755 /etc/init.d/msm
|
||||
|
||||
echo "\n\033[1;32mMSM INSTALL: Enabling automatic startup and shutdown\033[m"
|
||||
update-rc.d msm defaults
|
||||
|
||||
echo "\n\033[1;32mMSM INSTALL: Making MSM accessible as the command \"msm\"\033[m"
|
||||
ln -s /etc/init.d/msm /usr/local/bin/msm
|
||||
|
||||
echo "\n\033[1;32mMSM INSTALL: Asking MSM to update itself\033[m"
|
||||
/etc/init.d/msm update --noinput
|
||||
|
||||
echo "\n\033[1;32mMSM INSTALL: Done. Type \"msm help\" to get started. Have fun!\033[m"
|
||||
function enable_init() {
|
||||
install_log "Enabling automatic startup and shutdown"
|
||||
update-rc.d msm defaults
|
||||
}
|
||||
|
4
installers/defaults.conf
Normal file
4
installers/defaults.conf
Normal file
@ -0,0 +1,4 @@
|
||||
# vim:syn=sh:
|
||||
# Configure default MSM username and server directory
|
||||
MSM_USERNAME="minecraft"
|
||||
MSM_DIRECTORY="/opt/msm"
|
28
installers/install.sh
Normal file
28
installers/install.sh
Normal file
@ -0,0 +1,28 @@
|
||||
echo "This script requires superuser access to install files to /etc."
|
||||
echo "You will be prompted for your password by sudo."
|
||||
|
||||
# Clear existing sudo credentials
|
||||
sudo -k
|
||||
|
||||
# Get platform-specific install functions from command arguments
|
||||
install_file="${1:-debian.sh}"
|
||||
|
||||
# run script as sudo
|
||||
sudo sh <<SCRIPT
|
||||
|
||||
source "$install_file"
|
||||
update_system_packages
|
||||
install_dependencies
|
||||
add_minecraft_user
|
||||
create_msm_directories
|
||||
download_latest_files
|
||||
patch_latest_files
|
||||
install_config
|
||||
install_cron
|
||||
reload_cron
|
||||
install_init
|
||||
enable_init
|
||||
update_msm
|
||||
install_complete
|
||||
|
||||
SCRIPT
|
21
installers/redhat.sh
Normal file
21
installers/redhat.sh
Normal file
@ -0,0 +1,21 @@
|
||||
source common.sh
|
||||
|
||||
function update_system_packages() {
|
||||
install_log "Updating sources"
|
||||
yum update || install_error "Couldn't update packages"
|
||||
}
|
||||
|
||||
function install_dependencies() {
|
||||
install_log "Installing required packages"
|
||||
yum install screen rsync zip || install_error "Couldn't install dependencies"
|
||||
}
|
||||
|
||||
function reload_cron() {
|
||||
install_log "Reloading cron service"
|
||||
service crond reload
|
||||
}
|
||||
|
||||
function enable_init() {
|
||||
install_log "Enabling automatic startup and shutdown"
|
||||
chkconfig --add msm
|
||||
}
|
Loading…
Reference in New Issue
Block a user