mirror of
https://gh.wpcy.net/https://github.com/CaptainCore/captaincore.git
synced 2026-04-22 19:11:29 +08:00
68 lines
2.1 KiB
Bash
Executable file
68 lines
2.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
#
|
|
# Preps new site configurations into logins via command line
|
|
#
|
|
# `captaincore site prepare <site>`
|
|
#
|
|
|
|
while read config; do
|
|
if [[ "$config" == "Error:"* ]]; then
|
|
continue
|
|
fi
|
|
declare "$config"
|
|
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
|
|
|
if [ ${#@} -ne 1 ]; then
|
|
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a site."
|
|
exit
|
|
fi
|
|
|
|
site=$1
|
|
|
|
# Load site details
|
|
while read site_configs; do if [[ $site_configs == "" ]]; then continue; fi; declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain-id=$CAPTAIN_ID)"
|
|
|
|
environments=( $( captaincore environment list $site --captain-id=$CAPTAIN_ID ) )
|
|
|
|
for environment in ${environments[@]}; do
|
|
|
|
# Deploy SSH keys
|
|
captaincore site deploy-keys ${site}-${environment} --captain-id=$CAPTAIN_ID
|
|
|
|
# Pull down wp-config.php
|
|
mkdir -p "$path/${site}_${site_id}/${environment}/backup/"
|
|
captaincore ssh $site-$environment --command="cat wp-config.php" --captain-id=$CAPTAIN_ID > $path/${site}_${site_id}/${environment}/backup/wp-config.php
|
|
|
|
# Generate token
|
|
token_key=$( captaincore ssh $site-$environment --script=fetch-token --captain-id=$CAPTAIN_ID )
|
|
|
|
if [[ "$captaincore_dev" == true ]]; then
|
|
curl_argument="-k"
|
|
fi
|
|
|
|
# Assign token
|
|
curl ${curl_argument} --request POST "$captaincore_api" --header "Content-Type: application/json" --data @- << EOF
|
|
{
|
|
"command":"token",
|
|
"site_id":"$site_id",
|
|
"token_key":"$token_key",
|
|
"token":"$token"
|
|
}
|
|
EOF
|
|
|
|
# Set permalink to 'Post name' format if not set
|
|
captaincore ssh ${site}-${environment} --script=rewrite-prep --captain-id=$CAPTAIN_ID
|
|
|
|
# Deploy helper plugin
|
|
captaincore ssh ${site}-${environment} --script=deploy-helper --captain-id=$CAPTAIN_ID -- --wp_content=$wp_content
|
|
|
|
captaincore sync-data ${site}-${environment} --captain-id=$CAPTAIN_ID
|
|
|
|
# Generate new Fathom code if needed
|
|
if [[ "$( captaincore site get ${site}-${environment} --field=fathom -captain-id=$CAPTAIN_ID )" == "" ]]; then
|
|
# Generate new Fathom tracking code, if needed
|
|
captaincore site stats-generate ${site}-${environment} --captain-id=$CAPTAIN_ID
|
|
fi
|
|
|
|
done
|