69 lines
1.6 KiB
Bash
Executable File
69 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
SERVER_NAME="ichigo"
|
|
SERVER_DP_PATH="docker/games/minecraft/spigot/worlds/world/datapacks/"
|
|
DATAPACKS_FILE=datapacks.json
|
|
CRAFTINGTWEAKS_FILE=craftingtweaks.json
|
|
OUT_DIR=datapacks
|
|
|
|
set -e
|
|
|
|
check() {
|
|
if ! command -v "$1" > /dev/null 2>&1; then
|
|
echo "error: command '$1' is not available" >&2
|
|
if [[ -n $2 ]]; then
|
|
echo " $2"
|
|
fi
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
retry() {
|
|
local timeout=1
|
|
local max_retries=10
|
|
local n=0
|
|
|
|
until "$@"; do
|
|
if [[ $n -gt "$max_retries" ]]; then
|
|
echo "Command failed after $max_retries retries"
|
|
exit 1
|
|
fi
|
|
sleep "$timeout"
|
|
(( attempt++ ))
|
|
done
|
|
}
|
|
|
|
check vtdl "You can download it from https://github.com/zekrotja/vtdl/releases or via 'cargo install --git https://github.com/zekrotja/vtdl'"
|
|
check jq
|
|
|
|
out_dir="$OUT_DIR"
|
|
|
|
if [ -d "$out_dir" ]; then
|
|
rm -rf "$out_dir"
|
|
fi
|
|
|
|
updated=0
|
|
|
|
if [[ -f $DATAPACKS_FILE ]]; then
|
|
echo "Downloading datapacks ..."
|
|
vtdl download --packages "$DATAPACKS_FILE" --out-dir "$out_dir"
|
|
(( updated++ ))
|
|
fi
|
|
|
|
if [[ -f $CRAFTINGTWEAKS_FILE ]]; then
|
|
echo "Downloading craftingtweaks ..."
|
|
vtdl download --packages "$CRAFTINGTWEAKS_FILE" --out-dir "$out_dir"
|
|
(( updated++ ))
|
|
fi
|
|
|
|
if [[ $updated -lt 1 ]]; then
|
|
echo "error: nothing to upload" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "Deleting old datapacks on server ..."
|
|
retry ssh "$SERVER_NAME" 'find '"$SERVER_DP_PATH"' -maxdepth 1 -type f -name "*.zip" -exec rm -f {} \+'
|
|
|
|
echo "Uploading new datapacks ..."
|
|
retry scp -r "$out_dir"/* "$SERVER_NAME:$SERVER_DP_PATH"
|