captaincore/app/site/deploy-defaults
2020-04-03 17:41:54 -04:00

64 lines
1.5 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# Deploy default plugins/themes/settings for website
#
# `captaincore deploy-defaults`
#
# [<site>...]
# One or more sites.
#
# [--global-only]
#
# [@<target>]
# Target groups of sites like @all @production or @staging.
#
# Load configuration
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
source ${root_path}lib/arguments
run_command() {
echo "Deploying defaults to $# sites"
# Remove leading "--" from flags
for i in "${!flags[@]}"; do
flags[$i]=`echo ${flags[$i]} | cut -c 3-`
done
cd ${root_path}data;
for website in "$@"; do
# Extract environment
if [[ "$website" == *"-staging"* ]]; then
environment=staging
else
environment=production
fi
# Load site configs
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $website --bash --captain_id=$captain_id)"
wp eval-file ../lib/local-scripts/site-deploy-defaults.php site=$site environment=$environment ${flags[@]}
done
}
# See if any sites are specifed
if [ ${#arguments[*]} -gt 0 ]; then
# Runs on specifed sites
run_command ${arguments[*]}
fi
# Runs on targeted sites
if [ ${#targets[*]} -gt 0 ]; then
run_command $(captaincore site list ${targets[*]/targets=/@} --captain_id=$captain_id)
fi
# Error if no sites specifed
if [ ${#targets[*]} -eq 0 ] && [ ${#arguments[*]} -eq 0 ]; then
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify one or more sites, or use a target @all, @production or @staging."
fi