Skip to content

Commit

Permalink
Merge pull request thijsvanloef#334 from Dashboy1998/File-checks-for-…
Browse files Browse the repository at this point in the history
…config-generation

File checks for config generation
  • Loading branch information
thijsvanloef authored Feb 9, 2024
2 parents 00b953f + 8a2a8bb commit 108994c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 53 deletions.
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

0 comments on commit 108994c

Please sign in to comment.