Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lgsm/config-default/config-lgsm/inssserver/_default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ maxplayers="28"
fn_parms(){
# Allows serverpassword to work with parameters
if [ "${serverpassword}" != "NOT SET" ]; then
parms="${defaultmap}?Scenario=${defaultscenario}?MaxPlayers=${maxplayers}?Port=${port}?QueryPort=${queryport}?password="${serverpassword}" -hostname="${servername}" -log"
parms="${defaultmap}?Scenario=${defaultscenario}?MaxPlayers=${maxplayers}?Port=${port}?QueryPort=${queryport}?password="${serverpassword}" -hostname='${servername}' -log"
else
parms="${defaultmap}?Scenario=${defaultscenario}?MaxPlayers=${maxplayers}?Port=${port}?QueryPort=${queryport} -hostname='${servername}' -log"
fi
Expand Down
78 changes: 36 additions & 42 deletions lgsm/functions/update_factorio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ local commandaction="Update"
local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"

fn_update_factorio_dl(){
if [ "${branch}" == "stable" ]; then
downloadbranch="stable"
elif [ "${branch}" == "experimental" ]; then
downloadbranch="latest"
fi
fn_fetch_file "https://factorio.com/get-download/${downloadbranch}/headless/${factorioarch}" "${tmpdir}" "factorio_headless_${factorioarch}-${availablebuild}.tar.xz"
fn_dl_extract "${tmpdir}" "factorio_headless_${factorioarch}-${availablebuild}.tar.xz" "${tmpdir}"
echo -e "copying to ${serverfiles}...\c"
Expand All @@ -29,13 +24,23 @@ fn_update_factorio_dl(){
}

fn_update_factorio_currentbuild(){
# Gets current build info
# Checks if current build info is available. If it fails, then a server restart will be forced to generate logs.
if [ ! -f "${serverfiles}/factorio-current.log" ]; then
# Get current build info.
# If log file is missing, the server will restart to generate logs.

if [ -f "${serverfiles}/factorio-current.log" ]; then
currentbuild=$(grep "Loading mod base" "${serverfiles}/factorio-current.log" 2> /dev/null | awk '{print $5}' | tail -1)
fi

if [ -z "${currentbuild}" ]; then
fn_print_error "Checking for update: factorio.com"
sleep 0.5
fn_print_error_nl "Checking for update: factorio.com: No logs with server version found"
fn_script_log_error "Checking for update: factorio.com: No logs with server version found"
if [ ! -f "${serverfiles}/factorio-current.log" ]; then
fn_print_error_nl "Checking for update: factorio.com: No logs with server version found"
fn_script_log_error "Checking for update: factorio.com: No logs with server version found"
elif [ -z "${currentbuild}" ]; then
fn_print_error_nl "Checking for update: factorio.com: Current build version not found"
fn_script_log_error "Checking for update: factorio.com: Current build version not found"
fi
sleep 0.5
fn_print_info_nl "Checking for update: factorio.com: Forcing server restart"
fn_script_log_info "Checking for update: factorio.com: Forcing server restart"
Expand All @@ -45,49 +50,30 @@ fn_update_factorio_currentbuild(){
exitbypass=1
command_start.sh
sleep 0.5
# Check again and exit on failure.

# Check again and exit if failure.
if [ -f "${serverfiles}/factorio-current.log" ]; then
currentbuild=$(grep "Loading mod base" "${serverfiles}/factorio-current.log" 2> /dev/null | awk '{print $5}' | tail -1)
fi

if [ ! -f "${serverfiles}/factorio-current.log" ]; then
fn_print_fail_nl "Checking for update: factorio.com: Still No logs with server version found"
fn_script_log_fatal "Checking for update: factorio.com: Still No logs with server version found"
core_exit.sh
fi
fi

# Get current build from logs
currentbuild=$(grep "Loading mod base" "${serverfiles}/factorio-current.log" 2> /dev/null | awk '{print $5}' | tail -1)
if [ -z "${currentbuild}" ]; then
fn_print_error_nl "Checking for update: factorio.com: Current build version not found"
fn_script_log_error "Checking for update: factorio.com: Current build version not found"
sleep 0.5
fn_print_info_nl "Checking for update: factorio.com: Forcing server restart"
fn_script_log_info "Checking for update: factorio.com: Forcing server restart"
exitbypass=1
command_stop.sh
exitbypass=1
command_start.sh
currentbuild=$(grep "Loading mod base" "${serverfiles}/factorio-current.log" 2> /dev/null | awk '{print $5}' | tail -1)
if [ -z "${currentbuild}" ]; then
elif [ -z "${currentbuild}" ]; then
fn_print_fail_nl "Checking for update: factorio.com: Current build version still not found"
fn_script_log_fatal "Checking for update: factorio.com: Current build version still not found"
core_exit.sh
fi
fi
}

fn_update_factorio_arch(){
# Factorio is linux64 only for now
factorioarch="linux64"
}

fn_update_factorio_availablebuild(){
# Gets latest build info.
if [ "${branch}" != "stable" ]; then
availablebuild=$(${curlpath} -s https://factorio.com/get-download/stable/headless/linux64 | grep -o '[0-9]\.[0-9]\{2\}\.[0-9]\{2\}' | head -1)
else
availablebuild=$(${curlpath} -s https://factorio.com/get-download/latest/headless/linux64 | grep -o '[0-9]\.[0-9]\{2\}\.[0-9]\{2\}' | head -1)
fi
# Checks if availablebuild variable has been set
if [ -z "${availablebuild}" ]; then
availablebuild=$(${curlpath} -s https://factorio.com/get-download/${downloadbranch}/headless/${factorioarch} | grep -o '[0-9]\.[0-9]\{1,\}\.[0-9]\{1,\}' | head -1)

# Checks if availablebuild variable has been set.
if [ -v "${availablebuild}" ]; then
fn_print_fail "Checking for update: factorio.com"
sleep 0.5
fn_print_fail "Checking for update: factorio.com: Not returning version info"
Expand All @@ -103,7 +89,7 @@ fn_update_factorio_availablebuild(){
}

fn_update_factorio_compare(){
# Removes dots so if can compare version numbers
# Removes dots so if statement can compare version numbers.
currentbuilddigit=$(echo "${currentbuild}" | tr -cd '[:digit:]')
availablebuilddigit=$(echo "${availablebuild}" | tr -cd '[:digit:]')

Expand Down Expand Up @@ -157,7 +143,15 @@ fn_update_factorio_compare(){
fi
}

fn_update_factorio_arch
# Factorio is linux64 only for now.
factorioarch="linux64"

if [ "${branch}" == "stable" ]; then
downloadbranch="stable"
elif [ "${branch}" == "experimental" ]; then
downloadbranch="latest"
fi

if [ "${installer}" == "1" ]; then
fn_update_factorio_availablebuild
fn_update_factorio_dl
Expand Down