pms-cli/functions/datapack

53 lines
1.4 KiB
Bash

#!/usr/bin/env bash
function datapack_help() {
usage_general
cat<<EOF
commands:
fetch [servername] [download-url]
delete [servername] [datapack-name]
list [servername]
EOF
}
function datapack_fetch() {
checkDatapackDir "${1}"
local datapack_dir="$(getValueByKey 'PODMAN_DIRECTORY')/${1}/data/world/datapacks"
local datapack_name="$(echo ${2} | awk -F/ '{print $NF}')"
if [[ -f "${datapack_dir}/${datapack_name}" ]]; then
log e "Datapack '${datapack_name}' does already exist!"
exit 1
fi
curl -L "${2}" -o "${datapack_dir}/${datapack_name}"
}
function datapack_delete() {
checkDatapackDir "${1}"
local datapack_dir="$(getValueByKey 'PODMAN_DIRECTORY')/${1}/data/world/datapacks"
if [[ ! -f "${datapack_dir}/${2}" ]]; then
log e "Datapack '${2}' does not exist! Check again using '$(basename 0) datapack list'"
exit 1
fi
rm "${datapack_dir}/${2}"
}
function datapack_list() {
checkDatapackDir "${1}"
local datapack_dir="$(getValueByKey 'PODMAN_DIRECTORY')/${1}/data/world/datapacks"
local found_datapacks=($(find "$datapack_dir" -maxdepth 1 -type f -print))
if [[ "${#found_datapacks[@]}" -eq 0 ]]; then
log i "No datapacks found for '$1'"
exit 0
fi
log i "Found ${#found_datapacks[@]} datapacks:"
for datapack in "${found_datapacks[@]}"; do
echo "- $(basename ${datapack})"
done
}