mirror of
https://gh.wpcy.net/https://github.com/CaptainCore/captaincore.git
synced 2026-04-18 13:16:01 +08:00
73 lines
No EOL
1.8 KiB
Bash
Executable file
73 lines
No EOL
1.8 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
#
|
|
# Sync website data for one or more sites.
|
|
#
|
|
# `captaincore sync-data <site>`
|
|
#
|
|
# [<site>...]
|
|
# One or more sites.
|
|
#
|
|
# [@<target>]
|
|
# Sync website data for all sites with @all.
|
|
#
|
|
# [--skip-screenshot]
|
|
# Skips screenshot
|
|
#
|
|
|
|
# Load configuration
|
|
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
|
source ${root_path}lib/arguments
|
|
|
|
run_command() {
|
|
|
|
site=$1
|
|
|
|
# Extract environment
|
|
if [[ "$site" == *"-staging"* ]]; then
|
|
environment=staging
|
|
else
|
|
environment=production
|
|
fi
|
|
|
|
# Load site configs
|
|
while read site_configs; do if [[ $site_configs == "" ]]; then continue; fi; declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain_id=$captain_id)"
|
|
|
|
# Skip if not compatible
|
|
if [[ $protocol != "sftp" ]] || [[ $site == "" ]]; then
|
|
echo "Error: Can't SSH to $site";
|
|
return 1
|
|
fi
|
|
|
|
# Remove leading "--" from flags
|
|
for i in "${!flags[@]}"; do
|
|
flags[$i]=`echo ${flags[$i]} | cut -c 3-`
|
|
done
|
|
|
|
echo "$(date +'%Y-%m-%d %H:%M') Begin sync data ${site}-${environment}"
|
|
|
|
cd ${root_path}data
|
|
wp eval-file ../lib/local-scripts/site-sync-data.php site=$site environment=$environment ${flags[@]}
|
|
|
|
if [ -f "${path}/process-${process_id}-progress.log" ]; then
|
|
echo -n "." >> ${path}/process-${process_id}-progress.log
|
|
fi
|
|
|
|
}
|
|
|
|
if [ ${#arguments[*]} -eq 0 ] && [ ${#targets[*]} -eq 0 ]; then
|
|
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify one or more sites, or use a target @all, @production or @staging."
|
|
exit
|
|
fi
|
|
|
|
if [ ${#arguments[*]} -eq 1 ] && [ ${#targets[*]} -eq 0 ]; then
|
|
run_command ${arguments[*]}
|
|
fi
|
|
|
|
if [ ${#arguments[*]} -gt 1 ] && [ ${#targets[*]} -eq 0 ]; then
|
|
captaincore bulk sync-data ${arguments[*]} ${flags[@]}
|
|
fi
|
|
|
|
if [ ${#targets[*]} -gt 0 ] && [ ${#arguments[*]} -eq 0 ]; then
|
|
captaincore bulk sync-data ${targets[*]/targets=/@} ${flags[@]}
|
|
fi |