Files
plugin-drone-volume-cache/cacher.sh
T
Michael de Wit 13f372a63c add project
2016-12-07 11:45:05 +01:00

28 lines
976 B
Bash

#!/bin/bash
if [ -z "$PLUGIN_MOUNT" ]; then
echo "Specify folders to cache in the mount property! Plugin won't do anything!"
exit 0;
fi
IFS=','; read -ra SOURCES <<< "$PLUGIN_MOUNT"
if [ -n "$PLUGIN_REBUILD" ]; then
# Create cache
for source in "${SOURCES[@]}"; do
echo "Rebuilding cache for $source..."
mkdir -p "/cache/$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$source" && rsync -aHAX "$source/" "/cache/$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$source"
done
elif [ -n "$PLUGIN_RESTORE" ]; then
# Restore from cache
for source in "${SOURCES[@]}"; do
if [ -d "/cache/$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$source" ]; then
echo "Restoring cache for $source..."
mkdir -p "$source" && rsync -aHAX "/cache/$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$source/" "$source"
else
echo "No cache for $source"
fi
done
else
echo "No restore or rebuild flag specified, plugin won't do anything!"
fi