Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File checks for config generation #334

Merged
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
22 changes: 20 additions & 2 deletions scripts/compile-settings.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
#!/bin/bash
# shellcheck source=/dev/null
source "/home/steam/server/helper_functions.sh"

config_file="/palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini"
config_dir=$(dirname "$config_file")

mkdir -p "$config_dir" || exit
# If file exists then check if it is writable
if [ -f "$config_file" ]; then
if ! isWritable "$config_file"; then
echo "Unable to create $config_file"
exit 1
fi
# If file does not exist then check if the directory is writable
elif ! isWritable "$config_dir"; then
# Exiting since the file does not exist and the directory is not writable.
echo "Unable to create $config_file"
exit 1
fi

echo "Compiling PalWorldSettings.ini..."

Expand Down Expand Up @@ -134,8 +153,7 @@ BAN_LIST_URL = $BAN_LIST_URL
EOF
fi

mkdir -p /palworld/Pal/Saved/Config/LinuxServer
cat > /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini <<EOF
cat > "$config_file" <<EOF
[/Script/Pal.PalGameWorldSettings]
$(envsubst < ./files/PalWorldSettings.ini.template | tr -d "\n\r")
EOF
Expand Down
67 changes: 67 additions & 0 deletions scripts/helper_functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash
# This file contains functions which can be used in multiple scripts

# Checks if a given path is a directory
# Returns 0 if the path is a directory
# Returns 1 if the path is not a directory or does not exists and produces an output message
dirExists() {
local path="$1"
local return_val=0
if ! [ -d "${path}" ]; then
echo "${path} does not exist."
return_val=1
fi
return "$return_val"
}

# Checks if a given path is a regular file
# Returns 0 if the path is a regular file
# Returns 1 if the path is not a regular file or does not exists and produces an output message
fileExists() {
local path="$1"
local return_val=0
if ! [ -f "${path}" ]; then
echo "${path} does not exist."
return_val=1
fi
return "$return_val"
}

# Checks if a given path exists and is readable
# Returns 0 if the path exists and is readable
# Returns 1 if the path is not readable or does not exists and produces an output message
isReadable() {
local path="$1"
local return_val=0
if ! [ -e "${path}" ]; then
echo "${path} is not readable."
return_val=1
fi
return "$return_val"
}

# Checks if a given path is writable
# Returns 0 if the path is writable
# Returns 1 if the path is not writable or does not exists and produces an output message
isWritable() {
local path="$1"
local return_val=0
if ! [ -w "${path}" ]; then
echo "${path} is not writable."
return_val=1
fi
return "$return_val"
}

# Checks if a given path is executable
# Returns 0 if the path is executable
# Returns 1 if the path is not executable or does not exists and produces an output message
isExecutable() {
local path="$1"
local return_val=0
if ! [ -x "${path}" ]; then
echo "${path} is not executable."
return_val=1
fi
return "$return_val"
}
54 changes: 3 additions & 51 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,62 +1,14 @@
#!/bin/bash

dirExists() {
local path="$1"
local return_val=0
if ! [ -d "${path}" ]; then
echo "${path} does not exist."
return_val=1
fi
return "$return_val"
}

fileExists() {
local path="$1"
local return_val=0
if ! [ -f "${path}" ]; then
echo "${path} does not exist."
return_val=1
fi
return "$return_val"
}

isReadable() {
local path="$1"
local return_val=0
if ! [ -e "${path}" ]; then
echo "${path} is not readable."
return_val=1
fi
return "$return_val"
}

isWritable() {
local path="$1"
local return_val=0
if ! [ -w "${path}" ]; then
echo "${path} is not writable."
return_val=1
fi
return "$return_val"
}

isExecutable() {
local path="$1"
local return_val=0
if ! [ -x "${path}" ]; then
echo "${path} is not executable."
return_val=1
fi
return "$return_val"
}
# shellcheck source=/dev/null
source "/home/steam/server/helper_functions.sh"

dirExists "/palworld" || exit
isWritable "/palworld" || exit
isExecutable "/palworld" || exit

printf "\e[0;32m*****GENERATING CONFIGS*****\e[0m\n"

./compile-settings.sh
./compile-settings.sh || exit

cd /palworld || exit

Expand Down