Skip to content

Commit

Permalink
Merge branch 'main' into Include-only-needed-sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Dashboy1998 committed Feb 21, 2024
2 parents 74d9ec3 + db99463 commit 8b51131
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 36 deletions.
19 changes: 3 additions & 16 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
name: Linting
on: # yamllint disable-line rule:truthy
pull_request:
push:
branches:
- main

run-name: Pull request - ${{ github.event.pull_request.number }}
jobs:
Expand Down Expand Up @@ -49,19 +52,3 @@ jobs:
uses: ibiqlik/action-yamllint@v3
with:
config_file: .yamllint.yml

test-build:
name: Docker - Build
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker - Build
uses: docker/build-push-action@v5
with:
push: false
platforms: linux/amd64,linux/arm64
3 changes: 3 additions & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on: # yamllint disable-line rule:truthy
workflow_dispatch:
schedule:
- cron: 0 0 * * *
push:
branches:
- main

jobs:
container-scanning:
Expand Down
1 change: 1 addition & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
external-sources=true
4 changes: 2 additions & 2 deletions scripts/auto_reboot.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# shellcheck source=/dev/null
# shellcheck source=scripts/helper_functions.sh
source "/home/steam/server/helper_functions.sh"

if [ "${RCON_ENABLED,,}" != true ]; then
Expand All @@ -22,7 +22,7 @@ fi

if [[ "${AUTO_REBOOT_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then
for ((i = "${AUTO_REBOOT_WARN_MINUTES}" ; i > 0 ; i--)); do
RCON "broadcast The_Server_will_reboot_in_${i}_Minutes"
broadcast_command "The Server will reboot in ${i} minutes"
sleep "1m"
done
RCON save
Expand Down
2 changes: 1 addition & 1 deletion scripts/backup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# shellcheck source=/dev/null
# shellcheck source=scripts/helper_functions.sh
source "/home/steam/server/helper_functions.sh"

DiscordMessage "Creating backup..." "in-progress"
Expand Down
2 changes: 1 addition & 1 deletion scripts/compile-settings.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# shellcheck source=/dev/null
# shellcheck source=scripts/helper_functions.sh
source "/home/steam/server/helper_functions.sh"

config_file="/palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini"
Expand Down
2 changes: 1 addition & 1 deletion scripts/discord.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# shellcheck source=/dev/null
# shellcheck source=scripts/helper_functions.sh
source "/home/steam/server/helper_functions.sh"

# Defaults
Expand Down
56 changes: 49 additions & 7 deletions scripts/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ isReadable() {
isWritable() {
local path="$1"
local return_val=0
if ! [ -w "${path}" ]; then
# Directories may be writable but not deletable causing -w to return false
if [ -d "${path}" ]; then
temp_file=$(mktemp -q -p "${path}")
if [ -n "${temp_file}" ]; then
rm -f "${temp_file}"
else
echo "${path} is not writable."
return_val=1
fi
# If it is a file it must be writable
elif ! [ -w "${path}" ]; then
echo "${path} is not writable."
return_val=1
fi
Expand All @@ -66,17 +76,32 @@ isExecutable() {
return "$return_val"
}

# Lists players
# Outputs nothing if RCON is not enabled and returns 1
# Outputs player list if RCON is enabled and returns 0
get_players_list() {
local return_val=0
if [ "${RCON_ENABLED,,}" != true ]; then
return_val=1
fi

# tail -n +2 removes the header "name,playeruid,steamid"
RCON "ShowPlayers" | tail -n +2
return "$return_val"
}

# Checks how many players are currently connected
# Outputs 0 if RCON is not enabled
# Outputs the player count if rcon is enabled
# Outputs 0 if RCON is not enabled and returns 1
# Outputs the player count if rcon is enabled and returns 0
get_player_count() {
local player_list
if [ "${RCON_ENABLED,,}" != true ]; then
echo 0
return 0
local return_val=0
if ! player_list=$(get_players_list); then
return_val=1
fi
player_list=$(RCON "ShowPlayers")

echo -n "${player_list}" | wc -l
return "$return_val"
}

#
Expand Down Expand Up @@ -133,3 +158,20 @@ RCON() {
local args="$1"
rcon-cli -c /home/steam/server/rcon.yaml "$args"
}

# Given a message this will broadcast in game
# Since RCON does not support spaces this will replace all spaces with underscores
# Returns 0 on success
# Returns 1 if not able to broadcast
broadcast_command() {
local return_val=0
# Replaces spaces with underscore
local message="${1// /_}"
if [[ $TEXT = *[![:ascii:]]* ]]; then
LogWarn "Unable to broadcast since the message contains non-ascii characters: \"${message}\""
return_val=1
elif ! RCON "broadcast ${message}"; then
return_val=1
fi
return "$return_val"
}
2 changes: 1 addition & 1 deletion scripts/helper_install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# This file contains functions which can be used in multiple scripts

# shellcheck source=/dev/null
# shellcheck source=scripts/helper_functions.sh
source "/home/steam/server/helper_functions.sh"

# Returns 0 if game is installed
Expand Down
2 changes: 1 addition & 1 deletion scripts/init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# shellcheck source=/dev/null
# shellcheck source=scripts/helper_functions.sh
source "/home/steam/server/helper_functions.sh"

if [[ "$(id -u)" -eq 0 ]] && [[ "$(id -g)" -eq 0 ]]; then
Expand Down
2 changes: 1 addition & 1 deletion scripts/restore.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# shellcheck source=/dev/null
# shellcheck source=scripts/helper_functions.sh
source "/home/steam/server/helper_functions.sh"

# Backup file directory path
Expand Down
4 changes: 2 additions & 2 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
# shellcheck source=/dev/null
# shellcheck source=scripts/helper_functions.sh
source "/home/steam/server/helper_functions.sh"

# Helper Functions for installation & updates
# shellcheck source=/dev/null
# shellcheck source=scripts/helper_install.sh
source "/home/steam/server/helper_install.sh"

dirExists "/palworld" || exit
Expand Down
6 changes: 3 additions & 3 deletions scripts/update.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
# shellcheck source=/dev/null
# shellcheck source=scripts/helper_functions.sh
source "/home/steam/server/helper_functions.sh"

# Helper Functions for installation & updates
# shellcheck source=/dev/null
# shellcheck source=scripts/helper_install.sh
source "/home/steam/server/helper_install.sh"

UpdateRequired
Expand All @@ -28,7 +28,7 @@ fi
if [ "$(get_player_count)" -gt 0 ]; then
LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST."
DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes"
RCON "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes"
broadcast_command "The Serverwill update in ${AUTO_UPDATE_WARN_MINUTES} minutes"
sleep "${AUTO_UPDATE_WARN_MINUTES}m"
fi

Expand Down

0 comments on commit 8b51131

Please sign in to comment.