Files
wild-cloud/bin/wild-app-config

85 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
set -e
set -o pipefail
if [ $# -ne 1 ]; then
echo "Usage: $0 <app_name>"
exit 1
fi
APP_NAME="$1"
if [ ! -d ".wildcloud" ]; then
echo "Error: .wildcloud directory not found in current directory"
echo "This script must be run from a directory that contains a .wildcloud directory"
exit 1
fi
if [ ! -f ".wildcloud/config.yaml" ]; then
echo "Error: .wildcloud/config.yaml not found"
exit 1
fi
CACHE_APP_DIR=".wildcloud/cache/apps/${APP_NAME}"
# Check if app is cached, if not fetch it first
if [ ! -d "${CACHE_APP_DIR}" ]; then
echo "App '${APP_NAME}' not found in cache, fetching..."
./bin/wild-app-fetch "${APP_NAME}"
fi
DEST_APP_DIR="apps/${APP_NAME}"
mkdir -p "apps"
if [ -d "${DEST_APP_DIR}" ]; then
echo "Warning: Destination directory ${DEST_APP_DIR} already exists"
read -p "Do you want to overwrite it? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Pull cancelled"
exit 1
fi
rm -rf "${DEST_APP_DIR}"
fi
echo "Pulling app '${APP_NAME}' from cache to ${DEST_APP_DIR}"
# Function to process a file with gomplate if it's a YAML file
process_file() {
local src_file="$1"
local dest_file="$2"
if [[ "${src_file}" == *.yaml ]] || [[ "${src_file}" == *.yml ]]; then
echo "Processing YAML file: ${dest_file}"
gomplate -d config=.wildcloud/config.yaml -f "${src_file}" > "${dest_file}"
else
cp "${src_file}" "${dest_file}"
fi
}
# Create destination directory
mkdir -p "${DEST_APP_DIR}"
# Copy directory structure and process files
find "${CACHE_APP_DIR}" -type d | while read -r src_dir; do
rel_path="${src_dir#${CACHE_APP_DIR}}"
rel_path="${rel_path#/}" # Remove leading slash if present
if [ -n "${rel_path}" ]; then
mkdir -p "${DEST_APP_DIR}/${rel_path}"
fi
done
find "${CACHE_APP_DIR}" -type f | while read -r src_file; do
rel_path="${src_file#${CACHE_APP_DIR}}"
rel_path="${rel_path#/}" # Remove leading slash if present
dest_file="${DEST_APP_DIR}/${rel_path}"
# Ensure destination directory exists
dest_dir=$(dirname "${dest_file}")
mkdir -p "${dest_dir}"
process_file "${src_file}" "${dest_file}"
done
echo "Successfully pulled app '${APP_NAME}' with template processing"