2019-07-07 13:22:00 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
#
|
|
|
|
# Runs custom bash script or WP-CLI commands on a site.
|
|
|
|
#
|
2019-07-07 13:37:49 -05:00
|
|
|
# `captaincore run <site> --code=<code>`
|
2019-07-07 13:22:00 -05:00
|
|
|
#
|
|
|
|
|
2021-06-24 23:05:07 -04:00
|
|
|
while read config; do
|
|
|
|
if [[ "$config" == "Error:"* ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
declare "$config"
|
|
|
|
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
2019-07-07 13:22:00 -05:00
|
|
|
|
2021-06-24 23:05:07 -04:00
|
|
|
if [ ${#@} -gt 0 ] && [[ "$CAPTAINCORE_CODE" != "" ]]; then
|
2019-07-07 13:37:49 -05:00
|
|
|
# Generates receipe
|
|
|
|
timestamp=$( date +'%Y-%m-%d' )
|
2021-06-24 23:05:07 -04:00
|
|
|
recipe_file=$path_recipes/${CAPTAIN_ID}-${timestamp}-${CAPTAINCORE_CODE:0:8}.sh
|
|
|
|
recipe_name=${timestamp}-${CAPTAINCORE_CODE:0:8}
|
2019-07-07 13:37:49 -05:00
|
|
|
read -r -d '' php_code << heredoc
|
|
|
|
\$run_code = <<<PHPHEREDOC
|
2021-06-24 23:05:07 -04:00
|
|
|
$CAPTAINCORE_CODE
|
2019-07-07 13:37:49 -05:00
|
|
|
PHPHEREDOC;
|
2019-07-07 13:22:00 -05:00
|
|
|
|
2019-07-07 13:37:49 -05:00
|
|
|
echo base64_decode( \$run_code );
|
|
|
|
heredoc
|
2019-07-07 13:22:00 -05:00
|
|
|
|
2019-07-07 13:37:49 -05:00
|
|
|
code=$( php -r "$php_code" )
|
|
|
|
echo -n "$code" > "${recipe_file}"
|
2019-07-07 13:22:00 -05:00
|
|
|
|
|
|
|
# Runs on specifed sites
|
2021-06-24 23:05:07 -04:00
|
|
|
captaincore ssh $1 --recipe=$recipe_name --captain-id=$CAPTAIN_ID
|
|
|
|
exit
|
2019-07-07 13:22:00 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Error if no sites specifed
|
2021-06-24 23:05:07 -04:00
|
|
|
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a <site> and --code=<code>."
|