Skip to content

Instantly share code, notes, and snippets.

@Alemiz112
Created September 28, 2022 21:03
Show Gist options
  • Save Alemiz112/865a67b12abb057e05481b92906b697a to your computer and use it in GitHub Desktop.
Save Alemiz112/865a67b12abb057e05481b92906b697a to your computer and use it in GitHub Desktop.
FlowAssets dependency setup script for server
#!/usr/bin/env bash
FLOW_ASSETS_SERVER="server_address"
FLOW_ASSETS_TOKEN="your_token"
# Assets downloaded from server
REQUIRED_ASSETS="assets.txt"
# External assets which are not from FA server,
# but rather do use unauthenticated URL
EXTERNAL_DEPENDENCIES="dependencies.txt"
# Exit on error
set -e
function download_assets() {
content=$(cat "$REQUIRED_ASSETS")
for asset_name in $content
do
./flowassets-client.sh --download --server="${FLOW_ASSETS_SERVER}" --token="${FLOW_ASSETS_TOKEN}" --asset="$asset_name"
echo "" # Make it more readable
done
}
function download_dependencies() {
content=$(cat "$EXTERNAL_DEPENDENCIES")
base_dir=$(pwd)
for dependency in $content
do
download_path=$(echo "$dependency" | cut -d';' -f1)
download_url=$(echo "$dependency" | cut -d';' -f2)
cd "$base_dir/$download_path"
curl -O -J "$download_url"
echo "" # Make it more readable
done
cd "$base_dir"
}
function configure_file() {
echo "Configuring $1"
sed -i -e s/#!BETA_MODE!#/"${BETA_MODE}"/g "$1"
sed -i -e s/#!BETA_PREMIUM_ACCESS!#/"${BETA_MODE_PREMIUM}"/g "$1"
sed -i -e s/#!SERVER_ADDRESS!#/"${PUBLIC_ADDRESS}"/g "$1"
sed -i -e s/#!DOCKER_CID!#/"${DOCKER_CID}"/g "$1"
sed -i -e s/#!BACKEND_ADDRESS!#/"${BACKEND_ADDRESS}"/g "$1"
}
function configure() {
# Configure static files
configure_file server.properties
# Configure files inside of plugin directories
for file_path in plugins/* plugins/**/* ; do
if [[ -d "$file_path" ]]; then
continue
fi
if [[ "$file_path" == *.txt || "$file_path" == *.yml || "$file_path" == *.json || "$file_path" == *.yaml || "$file_path" == *.properties ]]; then
configure_file "$file_path"
fi
done
}
function extract_worlds() {
mkdir -p worlds/
for file_path in worlds/* ; do
if [[ -d "$file_path" || "$file_path" != *.tar.gz ]]; then
continue
fi
echo "Extracting world $file_path"
tar -xf "$file_path" -C worlds/
done
}
# Download FlowAsset script
echo "Downloading latest FlowAssets script..."
curl -s -o flowassets-client.sh https://raw.githubusercontent.com/WaterdogPE/FlowAssets/master/client-bash/flowassets-client.sh
chmod +x flowassets-client.sh
mkdir -p plugins/
# Download assets
echo "Downloading assets ..."
download_assets
# Download external dependencies
echo "Downloading external dependencies ..."
download_dependencies
# Extract worlds
extract_worlds
# Configure
configure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment