mirror of
https://gh.wpcy.net/https://github.com/CaptainCore/captaincore.git
synced 2026-04-22 17:15:42 +08:00
72 lines
No EOL
1.7 KiB
Bash
Executable file
72 lines
No EOL
1.7 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
#
|
|
# Bulk runs a command to many sites.
|
|
#
|
|
# `captaincore bulk <command>`
|
|
#
|
|
# [<site>...]
|
|
# One or more sites.
|
|
#
|
|
# [@<target>]
|
|
# Target groups of sites like @all @production or @staging.
|
|
#
|
|
# [--parallel=<number>]
|
|
# Number of sites to backup at same time
|
|
#
|
|
|
|
while read config; do
|
|
if [[ "$config" == "Error:"* ]]; then
|
|
continue
|
|
fi
|
|
declare "$config"
|
|
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
|
|
|
# Error if no sites specifed
|
|
if [ ${#@} -eq 0 ]; then
|
|
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify <command>."
|
|
exit
|
|
fi
|
|
|
|
cmd=$1
|
|
cmd=${cmd/\// }
|
|
args=(${@/$1/})
|
|
|
|
target=$CAPTAINCORE_ARGS
|
|
count=( $target )
|
|
target_count=(${#target})
|
|
parallel=$FLAG_PARALLEL
|
|
|
|
# Remove targets from args
|
|
args=${args[@]:${#count[@]}:${#args[@]}}
|
|
|
|
# Error if no sites specifed
|
|
if [[ $cmd == "" ]] || [[ $target == "" ]]; then
|
|
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify one or more sites, or use a target @all, @production or @staging."
|
|
exit
|
|
fi
|
|
|
|
run_command() {
|
|
if [[ $target == "@all"* ]] || [[ $target == "@production"* ]] || [[ $target == "@staging"* ]]; then
|
|
target=$( captaincore site list $target --captain-id=$CAPTAIN_ID )
|
|
fi
|
|
|
|
# Start progress tracking
|
|
if [[ $progress == "true" ]]; then
|
|
php ${root_path}lib/local-scripts/process-start.php ${process_id} ${#count[@]} "${path}/process-${process_id}-progress.log"
|
|
fi
|
|
|
|
if [[ "$parallel" == "" ]]; then
|
|
parallel=3
|
|
fi
|
|
|
|
eval "echo $target | xargs -P $parallel -n 1 captaincore $cmd $args --captain-id=$CAPTAIN_ID"
|
|
|
|
# End progress tracking
|
|
if [ -f "${path}/process-${process_id}-progress.log" ]; then
|
|
sleep 10 && rm "${path}/process-${process_id}-progress.log" &
|
|
fi
|
|
|
|
}
|
|
|
|
run_command |