captaincore/app/run
Austin Ginder 825b54016d 📦 NEW: Go CLI
2021-06-24 23:05:07 -04:00

38 lines
No EOL
980 B
Bash
Executable file

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