mirror of
https://github.com/msmhq/msm.git
synced 2024-08-30 18:12:35 +00:00
Don't use heredoc for sudo wrapping
This commit is contained in:
parent
2f41ae5552
commit
014ef73ed2
@ -48,16 +48,16 @@ function 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 --user-group $msm_user
|
||||
sudo useradd $msm_user || install_error "Couldn't create server 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'"
|
||||
sudo 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'"
|
||||
sudo 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
|
||||
@ -67,15 +67,15 @@ function download_latest_files() {
|
||||
fi
|
||||
|
||||
install_log "Downloading latest MSM configuration file"
|
||||
wget https://raw.github.com/marcuswhybrow/minecraft-server-manager/latest/msm.conf \
|
||||
sudo 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 \
|
||||
sudo 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 \
|
||||
sudo 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"
|
||||
}
|
||||
|
||||
@ -83,23 +83,23 @@ function download_latest_files() {
|
||||
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" | \
|
||||
sudo 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 }' \
|
||||
sudo awk '{ if ($0 !~ /^#/) sub(/minecraft/, "'$msm_user'"); print }' \
|
||||
"$dl_dir/msm.cron.orig" >"$dl_dir/msm.cron"
|
||||
|
||||
# patch init file
|
||||
install_log "Patching MSM init file"
|
||||
cp "$dl_dir/msm.init.orig" "$dl_dir/msm.init"
|
||||
sudo cp "$dl_dir/msm.init.orig" "$dl_dir/msm.init"
|
||||
}
|
||||
|
||||
# Installs msm.conf into /etc
|
||||
function install_config() {
|
||||
install_log "Installing MSM configuration file"
|
||||
install -b -m0644 "$dl_dir/msm.conf" /etc/msm.conf
|
||||
sudo install -b -m0644 "$dl_dir/msm.conf" /etc/msm.conf
|
||||
if [ ! -e /etc/msm.conf ]; then
|
||||
install_error "Couldn't install configuration file"
|
||||
fi
|
||||
@ -108,7 +108,7 @@ function install_config() {
|
||||
# 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"
|
||||
sudo install "$dl_dir/msm.cron" /etc/cron.d/msm || install_error "Couldn't install cron file"
|
||||
}
|
||||
|
||||
# Reloads cron service (if necessary)
|
||||
@ -120,10 +120,10 @@ function 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"
|
||||
sudo 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
|
||||
sudo ln -s /etc/init.d/msm /usr/local/bin/msm
|
||||
}
|
||||
|
||||
# Enables init script in default runlevels
|
||||
@ -135,7 +135,7 @@ function 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
|
||||
sudo /etc/init.d/msm update --noinput
|
||||
}
|
||||
|
||||
function install_complete() {
|
||||
@ -143,30 +143,18 @@ function install_complete() {
|
||||
}
|
||||
|
||||
function install_msm() {
|
||||
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
|
||||
|
||||
# Run install functions as sudo
|
||||
# These functions are defined in another script
|
||||
# after which this script is sourced
|
||||
sudo sh <<SCRIPT
|
||||
config_installation
|
||||
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
|
||||
|
||||
config_installation
|
||||
add_minecraft_user
|
||||
update_system_packages
|
||||
install_dependencies
|
||||
create_msm_directories
|
||||
download_latest_files
|
||||
patch_latest_files
|
||||
install_config
|
||||
install_cron
|
||||
reload_cron
|
||||
install_init
|
||||
enable_init
|
||||
update_msm
|
||||
install_complete
|
||||
}
|
||||
|
@ -1,25 +1,23 @@
|
||||
wget -q https://raw.github.com/marcuswhybrow/minecraft-server-manager/master/installers/common.sh -O /tmp/msmcommon.sh
|
||||
source /tmp/msmcommon.sh
|
||||
rm -f /tmp/msmcommon.sh
|
||||
source <(wget -qO- https://raw.github.com/marcuswhybrow/minecraft-server-manager/master/installers/common.sh)
|
||||
|
||||
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"
|
||||
sudo apt-get update || install_error "Couldn't update package list"
|
||||
sudo apt-get upgrade || install_error "Couldn't upgrade packages"
|
||||
}
|
||||
|
||||
function install_dependencies() {
|
||||
install_log "Installing required packages"
|
||||
apt-get install screen rsync zip || install_error "Couldn't install dependencies"
|
||||
sudo apt-get install screen rsync zip || install_error "Couldn't install dependencies"
|
||||
}
|
||||
|
||||
function reload_cron() {
|
||||
install_log "Reloading cron service"
|
||||
hash service 2>/dev/null
|
||||
if [[ $? == 0 ]]; then
|
||||
service cron reload
|
||||
sudo service cron reload
|
||||
else
|
||||
/etc/init.d/cron reload
|
||||
sudo /etc/init.d/cron reload
|
||||
fi
|
||||
}
|
||||
|
||||
@ -27,10 +25,10 @@ function enable_init() {
|
||||
install_log "Enabling automatic startup and shutdown"
|
||||
hash insserv 2>/dev/null
|
||||
if [[ $? == 0 ]]; then
|
||||
insserv msm
|
||||
sudo insserv msm
|
||||
else
|
||||
update-rc.d msm defaults
|
||||
sudo update-rc.d msm defaults
|
||||
fi
|
||||
}
|
||||
|
||||
install_msm
|
||||
install_msm
|
@ -1,25 +1,23 @@
|
||||
wget -q https://raw.github.com/marcuswhybrow/minecraft-server-manager/master/installers/common.sh -O /tmp/msmcommon.sh
|
||||
source /tmp/msmcommon.sh
|
||||
rm -f /tmp/msmcommon.sh
|
||||
source <(wget -qO- https://raw.github.com/marcuswhybrow/minecraft-server-manager/master/installers/common.sh)
|
||||
|
||||
function update_system_packages() {
|
||||
install_log "Updating sources"
|
||||
yum update || install_error "Couldn't update packages"
|
||||
sudo 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"
|
||||
sudo yum install screen rsync zip || install_error "Couldn't install dependencies"
|
||||
}
|
||||
|
||||
function reload_cron() {
|
||||
install_log "Reloading cron service"
|
||||
service crond reload
|
||||
sudo service crond reload
|
||||
}
|
||||
|
||||
function enable_init() {
|
||||
install_log "Enabling automatic startup and shutdown"
|
||||
chkconfig --add msm
|
||||
sudo chkconfig --add msm
|
||||
}
|
||||
|
||||
install_msm
|
||||
|
Loading…
Reference in New Issue
Block a user