mirror of
https://ghproxy.net/https://github.com/CaptainCore/captaincore.git
synced 2025-08-17 21:31:08 +08:00
📦 NEW: Go CLI
This commit is contained in:
parent
bd7fcf2b88
commit
825b54016d
185 changed files with 4526 additions and 3258 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -5,4 +5,6 @@ config.json
|
|||
config.sh
|
||||
cookies.yaml
|
||||
data
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
captaincore
|
||||
vendor
|
|
@ -1 +0,0 @@
|
|||
Austin Ginder
|
|
@ -1 +0,0 @@
|
|||
v1
|
|
@ -1 +0,0 @@
|
|||
WordPress Management Toolkit
|
|
@ -1 +0,0 @@
|
|||
CaptainCore CLI
|
|
@ -1 +0,0 @@
|
|||
0.11.0
|
64
app/activate
64
app/activate
|
@ -6,46 +6,44 @@
|
|||
# `captaincore activate [<site>...]`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
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
|
||||
|
||||
run_command() {
|
||||
|
||||
for website in "${arguments[*]}"; do
|
||||
# Extract environment
|
||||
if [[ "$website" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
else
|
||||
environment=production
|
||||
fi
|
||||
|
||||
# Extract environment
|
||||
if [[ "$website" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
else
|
||||
environment=production
|
||||
fi
|
||||
# Load site configs
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain-id=$CAPTAIN_ID)"
|
||||
|
||||
# Load site configs
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $website --bash --captain_id=$captain_id)"
|
||||
if [ -z "$domain" ]; then
|
||||
echo "Domain not found"
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ -z "$domain" ]; then
|
||||
echo "Domain not found"
|
||||
continue
|
||||
fi
|
||||
rclone_config_file="$path/${site}_${site_id}/rclone.conf"
|
||||
if [ ! -f "$rclone_config_file" ]; then
|
||||
captaincore site key-generate $site --captain-id=$CAPTAIN_ID
|
||||
fi
|
||||
|
||||
# Define Rclone site name
|
||||
rclone_site_name=${captain_id}-${site}-${environment}
|
||||
|
||||
if [[ "$home_directory" != "" ]]; then
|
||||
home_directory="${home_directory}/"
|
||||
fi
|
||||
|
||||
# Remove deactivation plugin
|
||||
rclone delete sftp-$rclone_site_name:${home_directory}${wp_content}/mu-plugins/captaincore_deactivated.php
|
||||
echo "activated $domain"
|
||||
|
||||
done
|
||||
captaincore ssh $site-$environment --script=activate -- --wp_content=$wp_content
|
||||
|
||||
}
|
||||
|
||||
# See if any specific sites are selected
|
||||
if [ $# -gt 0 ]; then
|
||||
# Run selected site(s)
|
||||
run_command $*
|
||||
fi
|
||||
run_command
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Removes custom deactivate mu-plugin on one or more sites.
|
|
@ -1 +0,0 @@
|
|||
[<site>...]
|
158
app/backup
158
app/backup
|
@ -1,158 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Backups one or more sites.
|
||||
#
|
||||
# `captaincore backup <site>`
|
||||
#
|
||||
# [<site>...]
|
||||
# One or more sites.
|
||||
#
|
||||
# [@<target>]
|
||||
# Target groups of sites like @all @production or @staging.
|
||||
#
|
||||
# [--skip-remote]
|
||||
# Skips saving to Restic backup repo
|
||||
#
|
||||
# [--skip-db]
|
||||
# Skips database backup
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
run_command() {
|
||||
|
||||
site=$@
|
||||
|
||||
# Extract environment
|
||||
if [[ "$site" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
fi
|
||||
|
||||
if [[ "$site" == *"-production"* ]]; then
|
||||
environment=production
|
||||
fi
|
||||
|
||||
if [[ "$site" != *"-"* ]]; then
|
||||
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)"
|
||||
|
||||
# Site found, start the backup
|
||||
if [[ $domain == "" ]]; then
|
||||
echo "Error: $site missing domain. Skipping backup."
|
||||
exit
|
||||
fi
|
||||
|
||||
# Append trailing slash if home_directory exist
|
||||
if [ "$home_directory" != "" ]; then
|
||||
home_directory="${home_directory}/"
|
||||
fi
|
||||
|
||||
# Define Rclone site name
|
||||
rclone_site_name=${captain_id}-${site}-${environment}
|
||||
|
||||
# Lookup rclone
|
||||
remotes=$( rclone listremotes )
|
||||
|
||||
# Check for rclone remote
|
||||
rclone_remote_lookup=false
|
||||
for item in ${remotes[@]}; do
|
||||
if [[ sftp-${rclone_site_name}: == "$item" ]]; then
|
||||
rclone_remote_lookup=true
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $rclone_remote_lookup == false ]]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M') Generating rclone configs for $site"
|
||||
captaincore site rclone-configs $site --captain_id=$captain_id
|
||||
fi
|
||||
|
||||
# Captures FTP errors in $ftp_output and file listing to log file
|
||||
ftp_output=$( { rclone lsd sftp-${rclone_site_name}:$home_directory ; } 2>&1 )
|
||||
ftp_search_for_wordpress=$( echo "$ftp_output" | perl -wnE'say for /wp-admin/g' )
|
||||
|
||||
# Handle FTP errors
|
||||
if [[ $ftp_search_for_wordpress != "wp-admin" ]]; then
|
||||
wordpress_not_found=true
|
||||
fi
|
||||
|
||||
# Incremental backup locally with rclone
|
||||
echo "$(date +'%Y-%m-%d %H:%M') Begin incremental backup ${site}-${environment} to local"
|
||||
|
||||
if [[ $skip_db != true ]] && [[ $wordpress_not_found != true ]]; then
|
||||
|
||||
# Database backup if remote server supports
|
||||
if [[ "$provider" == "kinsta" ]] || [[ "$provider" == "wpengine" ]]; then
|
||||
captaincore ssh ${site}-${environment} --script="db-backup" --captain_id=$captain_id
|
||||
fi
|
||||
|
||||
if [[ "$provider" == "wpengine" ]]; then
|
||||
rclone sync sftp-${rclone_site_name}:_wpeprivate/database-backup.sql $path/${site}_${site_id}/${environment}/backup/
|
||||
fi
|
||||
if [[ "$provider" == "kinsta" ]]; then
|
||||
rclone sync sftp-${rclone_site_name}:private/database-backup.sql $path/${site}_${site_id}/${environment}/backup/
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# Backup site locally
|
||||
if [[ "$wp_content" != "wp-content" ]]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M') Backing up ${site}-${environment} alternative wp-content location ($wp_content)"
|
||||
rclone sync sftp-${rclone_site_name}:$home_directory $path/${site}_${site_id}/${environment}/backup/ --exclude-from="${root_path}lib/excludes" --filter="+ $wp_content/**" --filter="- wp-content/**" --filter="- content/**"
|
||||
else
|
||||
rclone sync sftp-${rclone_site_name}:$home_directory $path/${site}_${site_id}/${environment}/backup/ --exclude-from="${root_path}lib/excludes" --filter="- content/**"
|
||||
fi
|
||||
|
||||
if [[ "$OSTYPE" == "linux-gnu" ]]; then
|
||||
# Begin folder size in bytes without apparent-size flag
|
||||
folder_size=$( du -s --block-size=1 $path/${site}_${site_id}/${environment}/backup/ )
|
||||
folder_size=$( echo $folder_size | cut -d' ' -f 1 )
|
||||
fi
|
||||
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# Calculate folder size in bytes http://superuser.com/questions/22460/how-do-i-get-the-size-of-a-linux-or-mac-os-x-directory-from-the-command-line
|
||||
folder_size=$( find $path/${site}_${site_id}/${environment}/backup/ -type f -print0 | xargs -0 stat -f%z | awk '{b+=$1} END {print b}' )
|
||||
fi
|
||||
|
||||
if [[ $skip_remote != true ]]; then
|
||||
# Incremental backup upload to Restic
|
||||
echo "$(date +'%Y-%m-%d %H:%M') Storing $site to backup archive"
|
||||
if [[ $( restic snapshots --repo rclone:$rclone_backup/${site}_${site_id}/${environment}/restic-repo --password-file="${root_path}data/restic.key" ) == "" ]]; then
|
||||
echo "Generating restic repo for $site"
|
||||
restic init --quiet --repo rclone:$rclone_backup/${site}_${site_id}/${environment}/restic-repo --password-file="${root_path}data/restic.key"
|
||||
fi
|
||||
cd $path/${site}_${site_id}/${environment}/backup/
|
||||
restic backup . --quiet --repo rclone:$rclone_backup/${site}_${site_id}/${environment}/restic-repo --exclude-file="${root_path}lib/restic-excludes" --password-file="${root_path}data/restic.key"
|
||||
captaincore site backup list-generate ${site}-${environment} --captain_id=$captain_id
|
||||
captaincore site backup get-generate ${site}-${environment} --captain_id=$captain_id
|
||||
fi
|
||||
|
||||
captaincore usage-update ${site}-${environment} --captain_id=$captain_id
|
||||
|
||||
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 backup ${arguments[*]} ${flags[@]}
|
||||
fi
|
||||
|
||||
if [ ${#targets[*]} -gt 0 ] && [ ${#arguments[*]} -eq 0 ]; then
|
||||
captaincore bulk backup ${targets[*]/targets=/@} ${flags[@]}
|
||||
fi
|
|
@ -1 +0,0 @@
|
|||
Backups one or more sites.
|
|
@ -1 +0,0 @@
|
|||
[<site>...] [@<target>] [--use-direct] [--skip-remote] [--skip-db]
|
|
@ -3,23 +3,26 @@
|
|||
#
|
||||
# Runs custom bash script or WP-CLI commands on a site.
|
||||
#
|
||||
# `captaincore site backup download <site> <backup_id> --payload=<payload_id>`
|
||||
# `captaincore site backup download <site> <backup_id> <payload_id>`
|
||||
#
|
||||
# [<email>]
|
||||
# Sent email with downloadable link
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#arguments[*]} -eq 0 ] || [[ "$payload" == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a <site> and --payload=<payload_id>."
|
||||
if [ ${#@} -ne 3 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify <site> <backup-id> and <payload-id>."
|
||||
fi
|
||||
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
site=$1
|
||||
backup_id=$2
|
||||
payload_id=$3
|
||||
|
||||
# Extract environment
|
||||
if [[ "$site" == *"-staging"* ]]; then
|
||||
|
@ -33,17 +36,17 @@ fi
|
|||
if [[ "$site" != *"-"* ]]; then
|
||||
environment=production
|
||||
fi
|
||||
mkdir -p "${root_path}data/payload/"
|
||||
payload_file="${root_path}data/payload/${payload}.txt"
|
||||
mkdir -p "${CAPTAINCORE_PATH}/data/payload/"
|
||||
payload_file="${CAPTAINCORE_PATH}/data/payload/${payload_id}.txt"
|
||||
|
||||
# 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)"
|
||||
while read site_configs; do if [[ $site_configs == "" ]]; then continue; fi; declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain-id=$CAPTAIN_ID)"
|
||||
|
||||
timestamp=$( date +'%Y-%m-%d_%H-%M-%S' )
|
||||
restore_path="$path/${site}_${site_id}/${environment}/restores/${timestamp}-${backup_id:0:8}"
|
||||
mount_name="mount_${captain_id}-$site-${environment}-${timestamp}-${backup_id:0:8}"
|
||||
mount_name="${timestamp}-${backup_id:0:3}"
|
||||
zip_name="${site}_${environment}_${backup_id:0:8}_at_$timestamp.zip"
|
||||
mkdir -p "$restore_path"
|
||||
mkdir -p "$restore_path/$mount_name"
|
||||
|
||||
read -r -d '' php_code << heredoc
|
||||
\$data = json_decode( base64_decode( file_get_contents ( "$payload_file" ) ) );
|
||||
|
@ -57,6 +60,7 @@ heredoc
|
|||
|
||||
php -r "$php_code"
|
||||
|
||||
rclone_config_file="$path/${site}_${site_id}/rclone.conf"
|
||||
echo "Mounting Restic repo"
|
||||
command="mount ${restore_path}/$mount_name/ --repo rclone:$rclone_backup/${site}_${site_id}/${environment}/restic-repo"
|
||||
restic $command > $restore_path/restic-mount.log 2>&1 &
|
||||
|
@ -110,16 +114,11 @@ rm -rf ${restore_path}/restore/
|
|||
# Moves snapshot to Backblaze archive folder
|
||||
rclone move $zip_name $rclone_snapshot/${site}_${site_id}/
|
||||
|
||||
# Remove leading "--" from flags
|
||||
for i in "${!flags[@]}"; do
|
||||
flags[$i]=`echo ${flags[$i]} | cut -c 3-`
|
||||
done
|
||||
|
||||
cd ${root_path}data
|
||||
backup_url=$( wp eval-file ../lib/local-scripts/restore-fetch-download-link.php zip_name="$zip_name" site=$site site_id=$site_id ${flags[@]} )
|
||||
cd ${CAPTAINCORE_PATH}/data
|
||||
backup_url=$( wp eval-file ../lib/local-scripts/restore-fetch-download-link.php zip_name="$zip_name" site=$site site_id=$site_id )
|
||||
echo $backup_url
|
||||
|
||||
if [[ $email != "" ]]; then
|
||||
if [[ $FLAG_EMAIL != "" ]]; then
|
||||
count=$(( $( wc -l "$restore_path/files_to_restore.txt" | awk '{ print $1 }' ) + 1 ))
|
||||
printf "Contains files from $domain $environment environment as of $timestamp.<br><a href='$backup_url'>Download zip</a><br><br>" | mutt -e 'set content_type=text/html' -s "Downloadable zip with $count items" -- $email
|
||||
printf "Contains files from $domain $environment environment as of $timestamp.<br><a href='$backup_url'>Download zip</a><br><br>" | mutt -e 'set content_type=text/html' -s "Downloadable zip with $count items" -- $FLAG_EMAIL
|
||||
fi
|
145
app/backup/generate
Normal file
145
app/backup/generate
Normal file
|
@ -0,0 +1,145 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Backups one or more sites.
|
||||
#
|
||||
# `captaincore backup generate <site>`
|
||||
#
|
||||
# [--skip-remote]
|
||||
# Skips saving to Restic backup repo
|
||||
#
|
||||
# [--skip-db]
|
||||
# Skips database backup
|
||||
#
|
||||
|
||||
if [ ${#@} -ne 1 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Requires a <site>"
|
||||
exit
|
||||
fi
|
||||
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
run_command() {
|
||||
|
||||
if [[ $SKIP_REMOTE == true ]]; then
|
||||
echo "Skipping remote"
|
||||
fi
|
||||
|
||||
site=$@
|
||||
|
||||
# Extract environment
|
||||
if [[ "$site" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
fi
|
||||
|
||||
if [[ "$site" == *"-production"* ]]; then
|
||||
environment=production
|
||||
fi
|
||||
|
||||
if [[ "$site" != *"-"* ]]; then
|
||||
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)"
|
||||
|
||||
# Site found, start the backup
|
||||
if [[ $domain == "" ]]; then
|
||||
echo "Error: $site missing domain. Skipping backup."
|
||||
exit
|
||||
fi
|
||||
|
||||
# Append trailing slash if home_directory exist
|
||||
if [ "$home_directory" != "" ]; then
|
||||
home_directory="${home_directory}/"
|
||||
fi
|
||||
|
||||
# Define Rclone config file
|
||||
rclone_config_file="$path/${site}_${site_id}/rclone.conf"
|
||||
if [ ! -f "$rclone_config_file" ]; then
|
||||
captaincore site key-generate $site --captain-id=$CAPTAIN_ID
|
||||
fi
|
||||
|
||||
# Lookup rclone
|
||||
remote_check=$( rclone config show $environment --config="$rclone_config_file" )
|
||||
|
||||
if [[ $remote_check == *"Couldn't find type of fs"* ]]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M') Generating rclone configs for $site"
|
||||
captaincore site key-generate $site --captain-id=$CAPTAIN_ID
|
||||
fi
|
||||
|
||||
# Captures FTP errors in $ftp_output and file listing to log file
|
||||
ftp_output=$( { rclone lsd ${environment}:$home_directory --config="$rclone_config_file" ; } 2>&1 )
|
||||
ftp_search_for_wordpress=$( echo "$ftp_output" | perl -wnE'say for /wp-admin/g' )
|
||||
|
||||
# Handle FTP errors
|
||||
if [[ $ftp_search_for_wordpress != "wp-admin" ]]; then
|
||||
wordpress_not_found=true
|
||||
fi
|
||||
|
||||
# Incremental backup locally with rclone
|
||||
echo "$(date +'%Y-%m-%d %H:%M') Begin incremental backup ${site}-${environment} to local"
|
||||
|
||||
if [[ $SKIP_DB != true ]] && [[ $wordpress_not_found != true ]]; then
|
||||
|
||||
# Database backup if remote server supports
|
||||
if [[ "$provider" == "kinsta" ]] || [[ "$provider" == "wpengine" ]]; then
|
||||
captaincore ssh ${site}-${environment} --script="db-backup" --captain-id=$CAPTAIN_ID
|
||||
fi
|
||||
|
||||
if [[ "$provider" == "wpengine" ]]; then
|
||||
rclone sync ${environment}:_wpeprivate/database-backup.sql $path/${site}_${site_id}/${environment}/backup/ --config="$rclone_config_file"
|
||||
fi
|
||||
|
||||
if [[ "$provider" == "kinsta" ]]; then
|
||||
rclone sync ${environment}:private/database-backup.sql $path/${site}_${site_id}/${environment}/backup/ --config="$rclone_config_file"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# Backup site locally
|
||||
if [[ "$wp_content" != "wp-content" ]]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M') Backing up ${site}-${environment} alternative wp-content location ($wp_content)"
|
||||
rclone sync ${environment}:$home_directory $path/${site}_${site_id}/${environment}/backup/ --exclude-from="${CAPTAINCORE_PATH}/lib/excludes" --filter="+ $wp_content/**" --filter="- wp-content/**" --filter="- content/**" --config="$rclone_config_file"
|
||||
else
|
||||
rclone sync ${environment}:$home_directory $path/${site}_${site_id}/${environment}/backup/ --exclude-from="${CAPTAINCORE_PATH}/lib/excludes" --filter="- content/**" --config="$rclone_config_file"
|
||||
fi
|
||||
|
||||
# Calculate folder size in bytes without apparent-size flag
|
||||
if [[ "$OSTYPE" == "linux-gnu" ]]; then
|
||||
folder_size=$( du -s --block-size=1 $path/${site}_${site_id}/${environment}/backup/ )
|
||||
folder_size=$( echo $folder_size | cut -d' ' -f 1 )
|
||||
fi
|
||||
|
||||
# Calculate folder size in bytes http://superuser.com/questions/22460/how-do-i-get-the-size-of-a-linux-or-mac-os-x-directory-from-the-command-line
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
folder_size=$( find $path/${site}_${site_id}/${environment}/backup/ -type f -print0 | xargs -0 stat -f%z | awk '{b+=$1} END {print b}' )
|
||||
fi
|
||||
|
||||
# Incremental backup upload to Restic
|
||||
if [[ $SKIP_REMOTE != true ]]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M') Storing $site to backup archive"
|
||||
if [[ $( restic snapshots --repo rclone:$rclone_backup/${site}_${site_id}/${environment}/restic-repo --password-file="${CAPTAINCORE_PATH}/data/restic.key" ) == "" ]]; then
|
||||
echo "Generating restic repo for $site"
|
||||
restic init --quiet --repo rclone:$rclone_backup/${site}_${site_id}/${environment}/restic-repo --password-file="${CAPTAINCORE_PATH}/data/restic.key"
|
||||
fi
|
||||
cd $path/${site}_${site_id}/${environment}/backup/
|
||||
restic backup . --quiet --repo rclone:$rclone_backup/${site}_${site_id}/${environment}/restic-repo --exclude-file="${CAPTAINCORE_PATH}/lib/restic-excludes" --password-file="${CAPTAINCORE_PATH}/data/restic.key"
|
||||
captaincore backup list-generate ${site}-${environment} --captain-id=$CAPTAIN_ID
|
||||
captaincore backup get-generate ${site}-${environment} --captain-id=$CAPTAIN_ID
|
||||
fi
|
||||
|
||||
captaincore usage-update ${site}-${environment} --captain-id=$CAPTAIN_ID
|
||||
|
||||
if [ -f "${path}/process-${process_id}-progress.log" ]; then
|
||||
echo -n "." >> ${path}/process-${process_id}-progress.log
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
run_command $@
|
|
@ -6,14 +6,16 @@
|
|||
# `captaincore site backup get <site> <backup-id>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -ne 2 ]; then
|
||||
if [ ${#@} -ne 2 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify <site> and <backup-id>."
|
||||
exit 1
|
||||
exit
|
||||
fi
|
||||
|
||||
site=$1
|
||||
|
@ -33,12 +35,12 @@ if [[ "$site" != *"-"* ]]; then
|
|||
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)"
|
||||
while read site_configs; do if [[ $site_configs == "" ]]; then continue; fi; declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain-id=$CAPTAIN_ID)"
|
||||
|
||||
backup_items="$path/${site}_${site_id}/${environment}/backups/snapshot-$backup_id.json"
|
||||
|
||||
if [ ! -f "$backup_items" ]; then
|
||||
captaincore site backup get-generate $site-$environment $backup_id --captain_id=$captain_id
|
||||
captaincore backup get-generate $site-$environment $backup_id --captain-id=$CAPTAIN_ID
|
||||
fi
|
||||
|
||||
cat $backup_items
|
|
@ -3,19 +3,21 @@
|
|||
#
|
||||
# Fetches backups for a site
|
||||
#
|
||||
# `captaincore site backup get-generate <site> <backup-id>`
|
||||
# `captaincore backup get-generate <site> <backup-id>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -eq 0 ]; then
|
||||
if [ ${#@} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify <site> and <backup-id>."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
site=$1
|
||||
backup_id=$2
|
||||
|
||||
|
@ -33,19 +35,19 @@ if [[ "$site" != *"-"* ]]; then
|
|||
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)"
|
||||
while read site_configs; do if [[ $site_configs == "" ]]; then continue; fi; declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain-id=$CAPTAIN_ID)"
|
||||
|
||||
cd ${root_path}data
|
||||
cd ${CAPTAINCORE_PATH}/data
|
||||
|
||||
if [[ "$backup_id" == "" ]] || [[ "$backup_id" == *"--"* ]]; then
|
||||
backup_id=$( wp eval-file ${root_path}lib/local-scripts/backups-get-latest.php site=$site site_id=$site_id environment=$environment captain_id=$captain_id )
|
||||
backup_id=$( wp eval-file ${CAPTAINCORE_PATH}/lib/local-scripts/backups-get-latest.php site=$site site_id=$site_id environment=$environment )
|
||||
echo "Backup id not selected. Generating response for latest ID $backup_id"
|
||||
fi
|
||||
|
||||
if [[ $( restic snapshots --repo rclone:$rclone_backup/${site}_${site_id}/${environment}/restic-repo --password-file="${root_path}data/restic.key" ) == "" ]]; then
|
||||
if [[ $( restic snapshots --repo="rclone:${rclone_backup}/${site}_${site_id}/${environment}/restic-repo" --password-file="${CAPTAINCORE_PATH}/data/restic.key" ) == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Backup repo not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
backup_snapshot="$path/${site}_${site_id}/${environment}/backups/snapshot-${backup_id}.json"
|
||||
wp eval-file ${root_path}lib/local-scripts/backups-get.php backup_id=$backup_id site=$site site_id=$site_id environment=$environment captain_id=$captain_id > $backup_snapshot
|
||||
wp eval-file ${CAPTAINCORE_PATH}/lib/local-scripts/backups-get.php backup_id=$backup_id site=$site site_id=$site_id environment=$environment > "$backup_snapshot"
|
49
app/backup/list
Normal file
49
app/backup/list
Normal file
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Fetches list of snapshots for a site from a backup repo
|
||||
#
|
||||
# `captaincore backup list <site>`
|
||||
#
|
||||
|
||||
if [ ${#@} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Requires a <site>"
|
||||
exit
|
||||
fi
|
||||
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
run_command() {
|
||||
|
||||
site=$1
|
||||
|
||||
# Extract environment
|
||||
if [[ "$site" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
fi
|
||||
|
||||
if [[ "$site" == *"-production"* ]]; then
|
||||
environment=production
|
||||
fi
|
||||
|
||||
if [[ "$site" != *"-"* ]]; then
|
||||
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)"
|
||||
|
||||
backup_list="$path/${site}_${site_id}/${environment}/backups/list.json"
|
||||
if [ ! -f "$backup_list" ]; then
|
||||
captaincore backup list-generate $site-$environment --captain-id=$CAPTAIN_ID
|
||||
fi
|
||||
cat "$backup_list"
|
||||
|
||||
}
|
||||
|
||||
run_command $@
|
55
app/backup/list-generate
Normal file
55
app/backup/list-generate
Normal file
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Generates list of snapshots for a site from a backup repo
|
||||
#
|
||||
# `captaincore backup list-generate <site>`
|
||||
#
|
||||
|
||||
if [ ${#@} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Requires a <site>"
|
||||
exit
|
||||
fi
|
||||
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
run_command() {
|
||||
|
||||
site=$1
|
||||
|
||||
# Extract environment
|
||||
if [[ "$site" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
fi
|
||||
|
||||
if [[ "$site" == *"-production"* ]]; then
|
||||
environment=production
|
||||
fi
|
||||
|
||||
if [[ "$site" != *"-"* ]]; then
|
||||
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)"
|
||||
|
||||
if [[ $( restic snapshots --repo rclone:$rclone_backup/${site}_${site_id}/${environment}/restic-repo ) == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Backup repo not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p $path/${site}_${site_id}/${environment}/backups/
|
||||
backup_list="$path/${site}_${site_id}/${environment}/backups/list.json"
|
||||
|
||||
cd ${CAPTAINCORE_PATH}/data
|
||||
wp eval-file ${CAPTAINCORE_PATH}/lib/local-scripts/backups-list.php site=$site site_id=$site_id environment=$environment > $backup_list
|
||||
|
||||
|
||||
}
|
||||
|
||||
run_command $@
|
66
app/bulk
66
app/bulk
|
@ -15,16 +15,40 @@
|
|||
# Number of sites to backup at same time
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
cmd=${arguments[1]}
|
||||
# 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})
|
||||
|
||||
# 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() {
|
||||
|
||||
sites=$@
|
||||
count=( $sites )
|
||||
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
|
||||
|
@ -34,8 +58,8 @@ run_command() {
|
|||
if [[ $parallel == "" ]]; then
|
||||
parallel=3
|
||||
fi
|
||||
|
||||
echo $sites | xargs -P $parallel -n 1 captaincore $cmd "${flags[@]}"
|
||||
|
||||
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
|
||||
|
@ -44,26 +68,4 @@ run_command() {
|
|||
|
||||
}
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#targets[*]} -eq 0 ] && [ ${#arguments[*]} -eq 1 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify one or more sites, or use a target @all, @production or @staging."
|
||||
exit
|
||||
fi
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#arguments[*]} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify <command>."
|
||||
exit
|
||||
fi
|
||||
|
||||
# Runs on specifed sites
|
||||
if [ ${#arguments[*]} -gt 1 ]; then
|
||||
unset 'arguments[1]'
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
|
||||
# Runs on targeted sites
|
||||
if [ ${#targets[*]} -gt 0 ]; then
|
||||
run_command $(captaincore site list ${targets[*]/targets=/@} --captain_id=$captain_id)
|
||||
fi
|
||||
|
||||
run_command
|
350
app/capture
350
app/capture
|
@ -15,9 +15,19 @@
|
|||
# Overrides pages to check. Defaults to site's `capture_pages` configuration.
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
if [ ${#@} -ne 1 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a <site>."
|
||||
exit
|
||||
fi
|
||||
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
site=$1
|
||||
|
||||
user_agent="captaincore/1.0 (CaptainCore Capture by CaptainCore.io)"
|
||||
|
||||
|
@ -35,157 +45,147 @@ urlencode() {
|
|||
|
||||
run_command() {
|
||||
|
||||
INDEX=0
|
||||
# Extract environment
|
||||
if [[ "$site" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
else
|
||||
environment=production
|
||||
fi
|
||||
|
||||
# Load site configs
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain-id=$CAPTAIN_ID)"
|
||||
|
||||
for website in "$@"; do
|
||||
# Return error if domain not found
|
||||
if [[ "$domain" == "" ]] || [[ "$site" == "" ]] || [[ "$provider" == "" ]]; then
|
||||
echo "Can't locate website for $site"
|
||||
continue
|
||||
fi
|
||||
|
||||
let INDEX=${INDEX}+1
|
||||
if [[ "$home_url" == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Site $domain is missing home_url. Recommend running sync-data first."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Extract environment
|
||||
if [[ "$website" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
else
|
||||
environment=production
|
||||
fi
|
||||
|
||||
# Load site configs
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $website --bash --captain_id=$captain_id)"
|
||||
if [[ "$pages" != "" ]]; then
|
||||
echo "Overidding default page selection."
|
||||
capture_pages=$pages
|
||||
fi
|
||||
|
||||
# Return error if domain not found
|
||||
if [[ "$domain" == "" ]] || [[ "$site" == "" ]] || [[ "$provider" == "" ]]; then
|
||||
echo "Can't locate website for $site"
|
||||
if [[ "$capture_pages" == "" ]]; then
|
||||
capture_pages="/"
|
||||
fi
|
||||
|
||||
echo "Capturing site ${site}-${environment} for pages $capture_pages"
|
||||
|
||||
# Define remote paths
|
||||
site_path=${site}_${site_id}/${environment}
|
||||
remote_path_captures=${site}_${site_id}/${environment}/captures
|
||||
remote_path_screenshots=${site}_${site_id}/${environment}/screenshots
|
||||
|
||||
if [[ "$captaincore_fleet" == "true" ]]; then
|
||||
remote_path_captures=${captain_id}/${remote_path_captures}
|
||||
remote_path_screenshots=${captain_id}/${remote_path_screenshots}
|
||||
fi
|
||||
|
||||
# Append trailing slash if home_directory exist
|
||||
if [ "$home_directory" != "" ]; then
|
||||
home_directory="${home_directory}/"
|
||||
fi
|
||||
|
||||
# Current timestamp
|
||||
timedate=$(date +%Y-%m-%d_%H-%M-%S)
|
||||
|
||||
# Prepare git repo
|
||||
mkdir -p $path/$site_path/captures/
|
||||
|
||||
cd $path/$site_path/captures/
|
||||
|
||||
# Create new git repo if needed
|
||||
if [ ! -d ".git" ]; then
|
||||
git init
|
||||
echo "/.screenshots" > .gitignore
|
||||
fi
|
||||
|
||||
# Remove current captures if needed
|
||||
current_capture_count=$( ls *.capture | wc -l )
|
||||
if [[ "$current_capture_count" != "0" ]]; then
|
||||
rm *.capture
|
||||
fi
|
||||
|
||||
# Create array of pages to capture
|
||||
IFS=',';pages=($capture_pages);unset IFS;
|
||||
|
||||
captured_pages=""
|
||||
|
||||
# Loop through and capture
|
||||
for i in `seq 1 ${#pages[@]}`; do
|
||||
selected=$( expr $i - 1 )
|
||||
page=${pages[$selected]}
|
||||
file_name="${page//\//#}.capture"
|
||||
echo "Capturing ${home_url}${page} to ${page//\//#}.capture"
|
||||
curl -L --max-time 30 --compressed --silent "${home_url}${page}" > "$file_name"
|
||||
|
||||
# Continue if no changes found
|
||||
check_status=$( git status "$file_name" -s )
|
||||
if [[ "$check_status" == "" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ "$home_url" == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Site $domain is missing home_url. Recommend running sync-data first."
|
||||
continue
|
||||
git add "$file_name"
|
||||
|
||||
check_status_again=$( git status "$file_name" -s )
|
||||
if [[ "$check_status_again" == "A"* || "$check_status_again" == "M"* || "$check_status_again" == "R"* ]]; then
|
||||
captured_pages="${captured_pages}${page},"
|
||||
mkdir -p ".screenshots/"
|
||||
query="url=$( urlencode "${home_url}${page}" )&full_page=true&viewport_width=1280&force=true&user_agent=$( urlencode "$user_agent" )&format=jpg&pixel_ratio=2"
|
||||
screenshots_cloud_token=$( printf '%s' "$query" | openssl sha1 -hmac "$screenshots_cloud_api_secret" | sed 's/^.* //' )
|
||||
echo "https://api.screenshots.cloud/v1/screenshot/$screenshots_cloud_api_key/$screenshots_cloud_token/?$query"
|
||||
curl "https://api.screenshots.cloud/v1/screenshot/$screenshots_cloud_api_key/$screenshots_cloud_token/?$query" > ".screenshots/${page//\//#}_working.jpg"
|
||||
fi
|
||||
|
||||
if [[ "$pages" != "" ]]; then
|
||||
echo "Overidding default page selection."
|
||||
capture_pages=$pages
|
||||
done
|
||||
|
||||
# Add all files to git repo
|
||||
git add -A
|
||||
|
||||
# Current git status
|
||||
git_status=$(git status -s)
|
||||
|
||||
if [[ "$git_status" == "" && "$force" != "true" ]]; then
|
||||
# Skip capture as nothing changed
|
||||
echo "No changes found."
|
||||
exit
|
||||
fi
|
||||
|
||||
# New commit
|
||||
git commit -m "Captured at $timedate"
|
||||
|
||||
# Save git hash
|
||||
git_commit=$(git log -n 1 --pretty=format:"%H") # Get hash of last commit (commit hash)
|
||||
git_commit_short=$(git log -n 1 --pretty=format:"%h")
|
||||
git_status=$(git show $git_commit --shortstat --format=)
|
||||
created_at=$(git show -s --pretty=format:"%ct" $git_commit) # Get date of last commit (UNIX timestamp)
|
||||
files_changed=$( git show $git_commit --name-status --format= )
|
||||
|
||||
# Organize new screenshots. Rename all files working_* to ${date}_${git_commit_short}_
|
||||
for image in $( ls .screenshots/*_working.jpg ); do
|
||||
new_ending="_${created_at}_${git_commit_short}"
|
||||
new_image_name=${image/_working/$new_ending}
|
||||
# Generate home page thumbnails
|
||||
if [[ "$image" == ".screenshots/#_working.jpg" ]]; then
|
||||
convert ".screenshots/#_working.jpg" -thumbnail 800 -gravity North -crop 800x500+0+0 ".screenshots/${created_at}_${git_commit_short}_thumb-800.jpg"
|
||||
convert ".screenshots/${created_at}_${git_commit_short}_thumb-800.jpg" -thumbnail 100 ".screenshots/${created_at}_${git_commit_short}_thumb-100.jpg"
|
||||
rclone move ".screenshots/${created_at}_${git_commit_short}_thumb-100.jpg" ${rclone_upload}${remote_path_screenshots}/ --fast-list --transfers=32 --no-update-modtime --progress
|
||||
rclone move ".screenshots/${created_at}_${git_commit_short}_thumb-800.jpg" ${rclone_upload}${remote_path_screenshots}/ --fast-list --transfers=32 --no-update-modtime --progress
|
||||
fi
|
||||
mv "$image" "$new_image_name"
|
||||
done
|
||||
|
||||
# Copy to remove storage
|
||||
rclone move .screenshots/ ${rclone_upload}${remote_path_captures}/ --fast-list --transfers=32 --no-update-modtime --progress
|
||||
|
||||
if [[ "$capture_pages" == "" ]]; then
|
||||
capture_pages="/"
|
||||
fi
|
||||
|
||||
echo "Capturing site ${INDEX}/$# for pages $capture_pages"
|
||||
|
||||
# Define remote paths
|
||||
site_path=${site}_${site_id}/${environment}
|
||||
remote_path_captures=${site}_${site_id}/${environment}/captures
|
||||
remote_path_screenshots=${site}_${site_id}/${environment}/screenshots
|
||||
|
||||
if [[ "$captaincore_fleet" == "true" ]]; then
|
||||
remote_path_captures=${captain_id}/${remote_path_captures}
|
||||
remote_path_screenshots=${captain_id}/${remote_path_screenshots}
|
||||
fi
|
||||
|
||||
# Append trailing slash if home_directory exist
|
||||
if [ "$home_directory" != "" ]; then
|
||||
home_directory="${home_directory}/"
|
||||
fi
|
||||
|
||||
echo "$(date +'%Y-%m-%d %H:%M') Begin capture for ${site}-${environment} (${INDEX}/$#)"
|
||||
|
||||
# Fetch new
|
||||
|
||||
# Current timestamp
|
||||
timedate=$(date +%Y-%m-%d_%H-%M-%S)
|
||||
|
||||
# Prepare git repo
|
||||
mkdir -p $path/$site_path/captures/
|
||||
|
||||
cd $path/$site_path/captures/
|
||||
|
||||
# Create new git repo if needed
|
||||
if [ ! -d ".git" ]; then
|
||||
git init
|
||||
echo "/.screenshots" > .gitignore
|
||||
fi
|
||||
|
||||
# Remove current captures if needed
|
||||
current_capture_count=$( ls *.capture | wc -l )
|
||||
if [[ "$current_capture_count" != "0" ]]; then
|
||||
rm *.capture
|
||||
fi
|
||||
|
||||
# Create array of pages to capture
|
||||
IFS=',';pages=($capture_pages);unset IFS;
|
||||
|
||||
captured_pages=""
|
||||
|
||||
# Loop through and capture
|
||||
for i in `seq 1 ${#pages[@]}`; do
|
||||
selected=$( expr $i - 1 )
|
||||
page=${pages[$selected]}
|
||||
file_name="${page//\//#}.capture"
|
||||
echo "Capturing ${home_url}${page} to ${page//\//#}.capture"
|
||||
curl -L --max-time 30 --compressed --silent "${home_url}${page}" > "$file_name"
|
||||
|
||||
# Continue if no changes found
|
||||
check_status=$( git status "$file_name" -s )
|
||||
if [[ "$check_status" == "" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
git add "$file_name"
|
||||
|
||||
check_status_again=$( git status "$file_name" -s )
|
||||
if [[ "$check_status_again" == "A"* || "$check_status_again" == "M"* || "$check_status_again" == "R"* ]]; then
|
||||
captured_pages="${captured_pages}${page},"
|
||||
mkdir -p ".screenshots/"
|
||||
query="url=$( urlencode "${home_url}${page}" )&full_page=true&viewport_width=1280&force=true&user_agent=$( urlencode "$user_agent" )&format=jpg&pixel_ratio=2"
|
||||
screenshots_cloud_token=$( printf '%s' "$query" | openssl sha1 -hmac "$screenshots_cloud_api_secret" | sed 's/^.* //' )
|
||||
echo "https://api.screenshots.cloud/v1/screenshot/$screenshots_cloud_api_key/$screenshots_cloud_token/?$query"
|
||||
curl "https://api.screenshots.cloud/v1/screenshot/$screenshots_cloud_api_key/$screenshots_cloud_token/?$query" > ".screenshots/${page//\//#}_working.jpg"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
# Add all files to git repo
|
||||
git add -A
|
||||
|
||||
# Current git status
|
||||
git_status=$(git status -s)
|
||||
|
||||
if [[ "$git_status" == "" && "$force" != "true" ]]; then
|
||||
# Skip capture as nothing changed
|
||||
echo "No changes found."
|
||||
continue
|
||||
fi
|
||||
|
||||
# New commit
|
||||
git commit -m "Captured at $timedate"
|
||||
|
||||
# Save git hash
|
||||
git_commit=$(git log -n 1 --pretty=format:"%H") # Get hash of last commit (commit hash)
|
||||
git_commit_short=$(git log -n 1 --pretty=format:"%h")
|
||||
git_status=$(git show $git_commit --shortstat --format=)
|
||||
created_at=$(git show -s --pretty=format:"%ct" $git_commit) # Get date of last commit (UNIX timestamp)
|
||||
files_changed=$( git show $git_commit --name-status --format= )
|
||||
|
||||
# Organize new screenshots. Rename all files working_* to ${date}_${git_commit_short}_
|
||||
for image in $( ls .screenshots/*_working.jpg ); do
|
||||
new_ending="_${created_at}_${git_commit_short}"
|
||||
new_image_name=${image/_working/$new_ending}
|
||||
# Generate home page thumbnails
|
||||
if [[ "$image" == ".screenshots/#_working.jpg" ]]; then
|
||||
convert ".screenshots/#_working.jpg" -thumbnail 800 -gravity North -crop 800x500+0+0 ".screenshots/${created_at}_${git_commit_short}_thumb-800.jpg"
|
||||
convert ".screenshots/${created_at}_${git_commit_short}_thumb-800.jpg" -thumbnail 100 ".screenshots/${created_at}_${git_commit_short}_thumb-100.jpg"
|
||||
rclone move ".screenshots/${created_at}_${git_commit_short}_thumb-100.jpg" ${rclone_upload}${remote_path_screenshots}/ --fast-list --transfers=32 --no-update-modtime --progress
|
||||
rclone move ".screenshots/${created_at}_${git_commit_short}_thumb-800.jpg" ${rclone_upload}${remote_path_screenshots}/ --fast-list --transfers=32 --no-update-modtime --progress
|
||||
fi
|
||||
mv "$image" "$new_image_name"
|
||||
done
|
||||
|
||||
# Copy to remove storage
|
||||
rclone move .screenshots/ ${rclone_upload}${remote_path_captures}/ --fast-list --transfers=32 --no-update-modtime --progress
|
||||
|
||||
# Build json for capture
|
||||
read -r -d '' capture << EOM
|
||||
# Build json for capture
|
||||
read -r -d '' capture << EOM
|
||||
{
|
||||
"git_commit":"$git_commit",
|
||||
"capture_pages":"$capture_pages",
|
||||
|
@ -194,10 +194,10 @@ run_command() {
|
|||
}
|
||||
EOM
|
||||
|
||||
echo "Git hash $git_commit"
|
||||
echo "Git hash $git_commit"
|
||||
|
||||
if [[ "$debug" == "true" ]]; then
|
||||
read -r -d '' VAR << EOM
|
||||
if [[ "$debug" == "true" ]]; then
|
||||
read -r -d '' VAR << EOM
|
||||
{
|
||||
"command": "new-capture",
|
||||
"site_id":"$site_id",
|
||||
|
@ -206,17 +206,17 @@ EOM
|
|||
"token":"$token"
|
||||
}
|
||||
EOM
|
||||
echo $VAR
|
||||
continue
|
||||
fi
|
||||
echo $VAR
|
||||
continue
|
||||
fi
|
||||
|
||||
# Adds capture to CaptainCore
|
||||
if [[ "$captaincore_dev" == true ]]; then
|
||||
curl_argument="-k"
|
||||
fi
|
||||
# Adds capture to CaptainCore
|
||||
if [[ "$captaincore_dev" == true ]]; then
|
||||
curl_argument="-k"
|
||||
fi
|
||||
|
||||
# Adds capture to CaptainCore
|
||||
curl ${curl_argument} --request POST "$captaincore_api" --header "Content-Type: application/json" --data @- << EOM
|
||||
# Adds capture to CaptainCore
|
||||
curl ${curl_argument} --request POST "$captaincore_api" --header "Content-Type: application/json" --data @- << EOM
|
||||
{
|
||||
"command": "new-capture",
|
||||
"site_id":"$site_id",
|
||||
|
@ -226,39 +226,23 @@ EOM
|
|||
}
|
||||
EOM
|
||||
|
||||
# Generate capture usage stats
|
||||
capture_count=$( git rev-list --all --count )
|
||||
# Generate capture usage stats
|
||||
capture_count=$( git rev-list --all --count )
|
||||
|
||||
# Sync site data, pull in new thumbnails
|
||||
captaincore site sync $site_id
|
||||
# Sync site data, pull in new thumbnails
|
||||
captaincore site sync $site_id
|
||||
|
||||
# Clear out variables
|
||||
site=''
|
||||
domain=''
|
||||
home_directory=''
|
||||
subsite=''
|
||||
response=''
|
||||
response_parsed=''
|
||||
|
||||
done
|
||||
# Clear out variables
|
||||
site=''
|
||||
domain=''
|
||||
home_directory=''
|
||||
subsite=''
|
||||
response=''
|
||||
response_parsed=''
|
||||
|
||||
# End logging
|
||||
echo "$(date +'%Y-%m-%d %H:%M') Finished capture"
|
||||
|
||||
}
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -gt 0 ]; then
|
||||
# Runs on specifed sites
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
|
||||
# Runs on targeted sites
|
||||
if [ ${#targets[*]} -gt 0 ]; then
|
||||
run_command $(captaincore site list ${targets[*]/targets=/@} --captain_id=$captain_id)
|
||||
fi
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#targets[*]} -eq 0 ] && [ ${#arguments[*]} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify one or more sites, or use a target @all, @production or @staging."
|
||||
fi
|
||||
run_command
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Captures website's pages visually over time based on quicksaves and html changes.
|
|
@ -29,7 +29,7 @@ run_command() {
|
|||
# Create Archive
|
||||
cd ~
|
||||
rm captaincore_backup.zip
|
||||
zip -r captaincore_backup.zip .captaincore-cli
|
||||
zip -r captaincore_backup.zip .captaincore
|
||||
|
||||
# Upload to remove
|
||||
rclone sync captaincore_backup.zip ${rclone_cli_backup}/
|
||||
|
|
|
@ -14,4 +14,4 @@ cd ${root_path}
|
|||
git pull
|
||||
|
||||
# Grant execute permissions
|
||||
find ~/.captaincore-cli/app/ -type f -exec chmod +x {} \;
|
||||
find ~/.captaincore/app/ -type f -exec chmod +x {} \;
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
version=`cat ${root_path}app/.version`
|
||||
echo "CaptainCore CLI v$version"
|
|
@ -1,31 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Get global configuration
|
||||
#
|
||||
# `captaincore configuration get`
|
||||
#
|
||||
# [--field=<field>]
|
||||
# Returns specific field
|
||||
#
|
||||
# [--bash]
|
||||
# Return in bash format
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
run_command() {
|
||||
|
||||
cd ${root_path}data
|
||||
|
||||
if [[ "$field" != "" ]]; then
|
||||
wp eval-file ${root_path}lib/local-scripts/configuration-get.php field=$field
|
||||
return
|
||||
fi
|
||||
|
||||
wp eval-file ${root_path}lib/local-scripts/configuration-get.php
|
||||
|
||||
}
|
||||
run_command ${arguments[*]}
|
|
@ -1,27 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Syncs default settings to CaptainCore CLI.
|
||||
#
|
||||
# `captaincore configuration-sync`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
run_command() {
|
||||
|
||||
# Remove leading "--" from flags
|
||||
for i in "${!flags[@]}"; do
|
||||
flags[$i]=`echo ${flags[$i]} | cut -c 3-`
|
||||
done
|
||||
|
||||
cd ${root_path}data
|
||||
wp eval-file ../lib/local-scripts/configuration-sync.php ${flags[@]}
|
||||
|
||||
}
|
||||
|
||||
if [ ${#arguments[*]} -eq 0 ]; then
|
||||
run_command ${arguments[*]}
|
||||
fi
|
135
app/deactivate
135
app/deactivate
|
@ -15,118 +15,51 @@
|
|||
# Custom link to display on deactivate page.
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
# Unique timestamp
|
||||
timestamp=$(date +%s)
|
||||
if [ ${#@} -ne 1 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a <site>."
|
||||
exit
|
||||
fi
|
||||
|
||||
# Must use WordPress deactivate plugin
|
||||
cat <<EOF > ~/Tmp/captaincore_deactivated_${timestamp}.php
|
||||
<?php
|
||||
|
||||
function captaincore_template_redirect() { ?><html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Website Deactivated</title>
|
||||
|
||||
<!-- Compiled and minified CSS -->
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
|
||||
|
||||
<!-- Compiled and minified JavaScript -->
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script>
|
||||
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css?family=Roboto');
|
||||
body {
|
||||
text-align: center;
|
||||
margin: 10% auto;
|
||||
padding: 0%;
|
||||
font-family: 'Roboto', sans-serif;
|
||||
overflow: hidden;
|
||||
display: block;
|
||||
max-width: 450px;
|
||||
background: #eeeeee;
|
||||
}
|
||||
p {
|
||||
margin-top: 3%;
|
||||
line-height: 1.4em;
|
||||
display: block;
|
||||
}
|
||||
img {
|
||||
margin-top: 1%;
|
||||
}
|
||||
a {
|
||||
color:#27c3f3;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="row">
|
||||
<div class="col s12">
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<span class="card-title">Website Deactivated</span>
|
||||
<p>This website is no longer active.</p>
|
||||
</div>
|
||||
<div class="card-content grey lighten-4">
|
||||
<p>Site owners contact <a href="${link}">${name}</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php
|
||||
|
||||
die();
|
||||
|
||||
}
|
||||
add_action( 'template_redirect', 'captaincore_template_redirect' );
|
||||
EOF
|
||||
site=$1
|
||||
|
||||
run_command() {
|
||||
|
||||
for website in "${arguments[*]}"; do
|
||||
# Extract environment
|
||||
if [[ "$website" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
else
|
||||
environment=production
|
||||
fi
|
||||
|
||||
# Extract environment
|
||||
if [[ "$website" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
else
|
||||
environment=production
|
||||
fi
|
||||
# Load site configs
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain-id=$CAPTAIN_ID)"
|
||||
|
||||
# Load site configs
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $website --bash --captain_id=$captain_id)"
|
||||
if [[ $domain == "" ]]; then
|
||||
echo "Domain not found"
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ $domain == "" ]]; then
|
||||
echo "Domain not found"
|
||||
continue
|
||||
fi
|
||||
read -r -d '' php_code << heredoc
|
||||
\$run_code = <<<PHPHEREDOC
|
||||
wp_content=$wp_content
|
||||
name=$FLAG_NAME
|
||||
link=$FLAG_LINK
|
||||
PHPHEREDOC;
|
||||
|
||||
# Define Rclone site name
|
||||
rclone_site_name=${captain_id}-${site}-${environment}
|
||||
echo base64_encode( \$run_code );
|
||||
heredoc
|
||||
|
||||
if [[ "$home_directory" != "" ]]; then
|
||||
home_directory="${home_directory}/"
|
||||
fi
|
||||
arguments=$( php -r "$php_code" )
|
||||
|
||||
# Upload deactivation plugin to mu-plugins
|
||||
rclone copyto ~/Tmp/captaincore_deactivated_${timestamp}.php sftp-${rclone_site_name}:${home_directory}${wp_content}/mu-plugins/captaincore_deactivated.php
|
||||
|
||||
echo "deactivated $domain"
|
||||
|
||||
done
|
||||
captaincore ssh $site-$environment --script=deactivate -- --arguments="$arguments"
|
||||
|
||||
}
|
||||
|
||||
# See if any specific sites are selected
|
||||
if [ $# -gt 0 ]; then
|
||||
# Run on selected site(s)
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
run_command
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Deploys custom deactivate mu-plugin on one or more sites.
|
|
@ -1 +0,0 @@
|
|||
[<site>...] [--name=<business-name>] [--link=<business-link>]
|
|
@ -1,92 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Shows file diff between Quicksaves.
|
||||
#
|
||||
# `captaincore quicksave-file-diff <site> --hash=<git_hash> --file=<file>`
|
||||
#
|
||||
# [--html]
|
||||
# HTML converted output
|
||||
#
|
||||
# Example: captaincore quicksave-file-diff sitename 4c43c16ae40f384e93573133282bb86a46d040fd versions/plugins.json
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
run_command() {
|
||||
|
||||
for website in "$@"; do
|
||||
|
||||
# Extract environment
|
||||
if [[ "$website" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
else
|
||||
environment=production
|
||||
fi
|
||||
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $website --bash --captain_id=$captain_id)"
|
||||
|
||||
# Return error if domain not found
|
||||
if [[ "$domain" == "" ]] || [[ "$site" == "" ]] || [[ "$provider" == "" ]]; then
|
||||
echo "Can't locate website for site $site"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -d "$path/${site}_${site_id}/${environment}/quicksave/" ]; then
|
||||
echo -e "Error: Unable to locate Quicksave."
|
||||
return
|
||||
fi
|
||||
|
||||
cd $path/${site}_${site_id}/${environment}/quicksave/
|
||||
|
||||
# capture all git commit into array
|
||||
git_commits=($( git log --pretty=format:"%H" ))
|
||||
|
||||
for i in ${!git_commits[@]}; do
|
||||
if [[ "${git_commits[$i]}" == "$hash" ]]; then
|
||||
current_index=$i
|
||||
fi
|
||||
done
|
||||
|
||||
git_hash_previous=${git_commits[ $(( $current_index + 1 )) ]}
|
||||
git_diff=$( git diff $git_hash_previous $hash -- $file )
|
||||
if [[ $html == "true" ]]; then
|
||||
|
||||
read -r -d '' php_code << heredoc
|
||||
<?php
|
||||
error_reporting(0);
|
||||
\$git_diff = <<<'PHPHEREDOC'
|
||||
$git_diff
|
||||
PHPHEREDOC;
|
||||
|
||||
echo htmlentities( \$git_diff );
|
||||
heredoc
|
||||
|
||||
echo -n "$php_code" > $path_tmp/${captain_id}-${hash}.php
|
||||
php $path_tmp/${captain_id}-${hash}.php
|
||||
|
||||
else
|
||||
echo "$git_diff"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -gt 0 ]; then
|
||||
# Runs on specifed sites
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
|
||||
# Runs on targeted sites
|
||||
if [ ${#targets[*]} -gt 0 ]; then
|
||||
run_command $(captaincore site list ${targets[*]/targets=/@} --captain_id=$captain_id)
|
||||
fi
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#targets[*]} -eq 0 ] && [ ${#arguments[*]} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify one or more sites, or use a target @all, @production or @staging."
|
||||
fi
|
|
@ -1 +0,0 @@
|
|||
Shows file diff between Quicksaves.
|
|
@ -1 +0,0 @@
|
|||
<site> <git_hash_current> <git_hash_previous> <file>
|
66
app/monitor
66
app/monitor
|
@ -23,29 +23,39 @@
|
|||
# Check a specific page. Example `--page=/wp-admin/`. Defaults to home page.
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
run_command() {
|
||||
if [[ ${#@} != "1" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Required <site> or <target>."
|
||||
return 1
|
||||
fi
|
||||
|
||||
urls_to_check=()
|
||||
|
||||
# Assign default retry
|
||||
if [[ $retry == "" ]]; then
|
||||
retry=3
|
||||
if [[ $RETRY == "" ]]; then
|
||||
RETRY=3
|
||||
fi
|
||||
|
||||
# Assign default parallel
|
||||
if [[ $parallel == "" ]]; then
|
||||
parallel=15
|
||||
if [[ $PARALLEL == "" ]]; then
|
||||
PARALLEL=15
|
||||
fi
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -gt 0 ]; then
|
||||
if [[ $@ != "@all" && $@ != "@production" && $@ != "@staging" ]]; then
|
||||
# Runs on specific sites
|
||||
for site in ${arguments[*]}; do
|
||||
url=$( captaincore site get $site --field=home_url --captain_id=$captain_id )
|
||||
for site in $@; do
|
||||
url=$( captaincore site get $site --field=home_url --captain-id=$CAPTAIN_ID )
|
||||
if [[ "$url" == "" ]]; then
|
||||
continue
|
||||
fi
|
||||
urls_to_check+=( ${url}${page},${site} )
|
||||
done
|
||||
urls_to_check=${urls_to_check[@]}
|
||||
|
@ -55,9 +65,8 @@ run_command() {
|
|||
urls_to_check=${urls}
|
||||
fi
|
||||
|
||||
if [ ${#targets[*]} -gt 0 ]; then
|
||||
# Runs on all sites
|
||||
urls=$( captaincore site list ${targets[*]/targets=/@} --field=home_url,site --captain_id=$captain_id )
|
||||
if [[ $@ == "@all" || $@ == "@production" || $@ == "@staging" ]]; then
|
||||
urls=$( captaincore site list $@ --field=home_url,site --captain-id=$CAPTAIN_ID )
|
||||
for item in ${urls[*]}; do
|
||||
url=${item%%,*}
|
||||
site_name=${item##*,}
|
||||
|
@ -71,12 +80,6 @@ run_command() {
|
|||
|
||||
orignal_urls_to_check=$urls_to_check
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#targets[*]} -eq 0 ] && [ ${#arguments[*]} -eq 0 ] && [[ ${#urls} == 0 ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify one or more sites, or use @production."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Generate random auth
|
||||
auth=''; for count in {0..6}; do auth+=$(printf "%x" $(($RANDOM%16)) ); done;
|
||||
|
||||
|
@ -91,20 +94,27 @@ run_command() {
|
|||
# Define monitor.json location
|
||||
monitor_file="$path/monitor.json"
|
||||
|
||||
if [[ "$urls_to_check" == "" ]]; then
|
||||
echo "${COLOR_RED}Error:${COLOR_NORMAL} Nothing to check"
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "logging to $log_file"
|
||||
|
||||
cd ${root_path}data
|
||||
cd "$HOME/.captaincore/data"
|
||||
|
||||
for attempt in $(seq 1 $retry); do
|
||||
for attempt in $(seq 1 $RETRY); do
|
||||
|
||||
# Wait before retrying failures
|
||||
sleep 10s
|
||||
if [[ "$attempt" != "1" ]]; then
|
||||
sleep 10s
|
||||
fi
|
||||
|
||||
# Run checks in parallel. Collect the results in log file.
|
||||
( echo $urls_to_check | xargs -P $parallel -n 1 captaincore monitor-check ) 2>&1 | tee $log_file
|
||||
( echo $urls_to_check | xargs -P $PARALLEL -n 1 captaincore monitor-check ) 2>&1 | tee $log_file
|
||||
|
||||
# Have local PHP handle error count
|
||||
error_count=$(php ${root_path}lib/local-scripts/monitor.php check $log_file $monitor_file)
|
||||
error_count=$( php $HOME/.captaincore/lib/local-scripts/monitor.php check $log_file $monitor_file )
|
||||
|
||||
# If no errors then skip the rest of the attempts.
|
||||
if [[ $error_count == "0" ]]; then
|
||||
|
@ -112,12 +122,12 @@ run_command() {
|
|||
fi
|
||||
|
||||
# Skip last attempt
|
||||
if [[ $attempt != $retry ]]; then
|
||||
if [[ $attempt != $RETRY ]]; then
|
||||
|
||||
echo "Attempt #${attempt} found $error_count errors. Checking those URLs again.";
|
||||
|
||||
# Fetch urls with errors for another another check
|
||||
urls_to_check=$(php ${root_path}lib/local-scripts/monitor.php process $log_file $monitor_file)
|
||||
urls_to_check=$( php $HOME/.captaincore/lib/local-scripts/monitor.php process $log_file $monitor_file )
|
||||
|
||||
# Empty space for formating
|
||||
echo "" >> $log_file
|
||||
|
@ -131,7 +141,7 @@ run_command() {
|
|||
done
|
||||
|
||||
# Build emails
|
||||
email_content=$(php ${root_path}lib/local-scripts/monitor.php generate $log_file $monitor_file "$orignal_urls_to_check" $captain_id)
|
||||
email_content=$( php $HOME/.captaincore/lib/local-scripts/monitor.php generate $log_file $monitor_file "$orignal_urls_to_check" $CAPTAIN_ID )
|
||||
|
||||
if [[ $email_content != "" ]]; then
|
||||
|
||||
|
@ -144,4 +154,4 @@ run_command() {
|
|||
fi
|
||||
|
||||
}
|
||||
run_command
|
||||
run_command $@
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Monitor check on a single valid HTTP url.
|
|
@ -1 +0,0 @@
|
|||
Monitor check one or more sites.
|
25
app/plugin-zip
Normal file
25
app/plugin-zip
Normal file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Generates plugin zips on a single site.
|
||||
#
|
||||
# `captaincore plugins-zip <site> <plugin>...`
|
||||
#
|
||||
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
if [ ${#@} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Requires a <site>"
|
||||
exit
|
||||
fi
|
||||
|
||||
site=$1
|
||||
count=( $@ )
|
||||
plugins=${@:2:${#@}}
|
||||
|
||||
captaincore ssh $site --script=plugins-zip -- --plugins="$plugins"
|
|
@ -1,16 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Generates plugin zips on a single site.
|
||||
#
|
||||
# `captaincore plugins-zip <site> <plugin>...`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
site=$1
|
||||
plugins=${arguments[@]/$site}
|
||||
|
||||
captaincore ssh $site --script=plugins-zip --plugins="$plugins" --captain_id=$captain_id
|
|
@ -1 +0,0 @@
|
|||
Generates plugin zips on a single site.
|
|
@ -1 +0,0 @@
|
|||
Generates quicksave for plugins and themes changes for one or more sites.
|
|
@ -1 +0,0 @@
|
|||
[<site>...] [@<target>] [--force] [--debug]
|
87
app/quicksave/file-diff
Normal file
87
app/quicksave/file-diff
Normal file
|
@ -0,0 +1,87 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Shows file diff between Quicksaves.
|
||||
#
|
||||
# `captaincore quicksave-file-diff <site> --hash=<git_hash> --file=<file>`
|
||||
#
|
||||
# [--html]
|
||||
# HTML converted output
|
||||
#
|
||||
# Example: captaincore quicksave-file-diff sitename 4c43c16ae40f384e93573133282bb86a46d040fd versions/plugins.json
|
||||
#
|
||||
|
||||
|
||||
if [ ${#@} -ne 3 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a <site> <commit-hash> <file>."
|
||||
exit
|
||||
fi
|
||||
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
site=$1
|
||||
commit=$2
|
||||
file=$3
|
||||
|
||||
run_command() {
|
||||
|
||||
# Extract environment
|
||||
if [[ "$website" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
else
|
||||
environment=production
|
||||
fi
|
||||
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain-id=$captain_id)"
|
||||
|
||||
# Return error if domain not found
|
||||
if [[ "$domain" == "" ]] || [[ "$site" == "" ]] || [[ "$provider" == "" ]]; then
|
||||
echo "Can't locate website for site $site"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -d "$path/${site}_${site_id}/${environment}/quicksave/" ]; then
|
||||
echo -e "Error: Unable to locate Quicksave."
|
||||
return
|
||||
fi
|
||||
|
||||
cd $path/${site}_${site_id}/${environment}/quicksave/
|
||||
|
||||
# capture all git commit into array
|
||||
git_commits=($( git log --pretty=format:"%H" ))
|
||||
|
||||
for i in ${!git_commits[@]}; do
|
||||
if [[ "${git_commits[$i]}" == "$commit" ]]; then
|
||||
current_index=$i
|
||||
fi
|
||||
done
|
||||
|
||||
git_hash_previous=${git_commits[ $(( $current_index + 1 )) ]}
|
||||
git_diff=$( git diff $git_hash_previous $commit -- $file )
|
||||
if [[ $FLAG_HTML == "true" ]]; then
|
||||
|
||||
read -r -d '' php_code << heredoc
|
||||
<?php
|
||||
error_reporting(0);
|
||||
\$git_diff = <<<'PHPHEREDOC'
|
||||
$git_diff
|
||||
PHPHEREDOC;
|
||||
|
||||
echo htmlentities( \$git_diff );
|
||||
heredoc
|
||||
|
||||
echo -n "$php_code" > $path_tmp/${captain_id}-${commit}.php
|
||||
php $path_tmp/${captain_id}-${commit}.php
|
||||
|
||||
else
|
||||
echo "$git_diff"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
run_command
|
82
app/quicksave → app/quicksave/generate
Executable file → Normal file
82
app/quicksave → app/quicksave/generate
Executable file → Normal file
|
@ -17,20 +17,25 @@
|
|||
# [--force]
|
||||
# Force even if no changes were made.
|
||||
#
|
||||
# [--skip-remote]
|
||||
# Skips backup to remote
|
||||
#
|
||||
# [--debug]
|
||||
# Debug mode
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
if [ ${#@} -ne 1 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a <site>."
|
||||
exit
|
||||
fi
|
||||
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
run_command() {
|
||||
|
||||
website=$@
|
||||
website=$1
|
||||
|
||||
# Extract environment
|
||||
if [[ "$website" == *"-staging"* ]]; then
|
||||
|
@ -40,7 +45,7 @@ run_command() {
|
|||
fi
|
||||
|
||||
# Load site configs
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $website --bash --captain_id=$captain_id)"
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $website --bash --captain-id=$CAPTAIN_ID)"
|
||||
|
||||
# Return error if domain not found
|
||||
if [[ "$domain" == "" ]] || [[ "$site" == "" ]] || [[ "$provider" == "" ]]; then
|
||||
|
@ -48,19 +53,21 @@ run_command() {
|
|||
exit
|
||||
fi
|
||||
|
||||
# Define Rclone site name
|
||||
rclone_site_name=${captain_id}-${site}-${environment}
|
||||
check_rclone=$( rclone config show sftp-$rclone_site_name )
|
||||
if [[ "$check_rclone" != *"type = sftp"* ]]; then
|
||||
echo "Rclone remote 'sftp-$rclone_site_name' not found."
|
||||
exit
|
||||
rclone_config_file="$path/${site}_${site_id}/rclone.conf"
|
||||
if [ ! -f "$rclone_config_file" ]; then
|
||||
captaincore site key-generate $site --captain-id=$CAPTAIN_ID
|
||||
fi
|
||||
|
||||
# Define site path
|
||||
site_path=${site}_${site_id}/${environment}
|
||||
# Lookup rclone
|
||||
remote_check=$( rclone config show $environment --config="$rclone_config_file" )
|
||||
|
||||
# captures FTP errors in $ftp_output and file listing to log file
|
||||
ftp_output=$( { rclone lsd sftp-$rclone_site_name:$home_directory; } 2>&1 )
|
||||
if [[ $remote_check == *"Couldn't find type of fs"* ]]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M') Generating rclone configs for $site"
|
||||
captaincore site key-generate $site --captain-id=$CAPTAIN_ID
|
||||
fi
|
||||
|
||||
# Captures FTP errors in $ftp_output and file listing to log file
|
||||
ftp_output=$( { rclone lsd ${environment}:$home_directory --config="$rclone_config_file" ; } 2>&1 )
|
||||
ftp_search_for_wordpress=$( echo "$ftp_output" | perl -wnE'say for /wp-admin/g' )
|
||||
|
||||
# Handle FTP errors
|
||||
|
@ -76,10 +83,12 @@ run_command() {
|
|||
|
||||
echo "$(date +'%Y-%m-%d %H:%M') Begin quicksave for ${site}-${environment}"
|
||||
|
||||
site_path="${site}_${site_id}/${environment}"
|
||||
|
||||
# Updates themes/plugins before Quicksave (Selective backup site locally)
|
||||
rclone sync sftp-$rclone_site_name:${home_directory}${wp_content}/themes/ $path/$site_path/backup/${wp_content}/themes/ --exclude .DS_Store --exclude *timthumb.txt
|
||||
rclone sync sftp-$rclone_site_name:${home_directory}${wp_content}/mu-plugins/ $path/$site_path/backup/${wp_content}/mu-plugins/ --exclude .DS_Store --exclude *timthumb.txt
|
||||
rclone sync sftp-$rclone_site_name:${home_directory}${wp_content}/plugins/ $path/$site_path/backup/${wp_content}/plugins/ --exclude .DS_Store --exclude *timthumb.txt
|
||||
rclone sync ${environment}:$home_directory${wp_content}/themes/ $path/$site_path/backup/${wp_content}/themes/ --exclude .DS_Store --exclude *timthumb.txt --config="$rclone_config_file"
|
||||
rclone sync ${environment}:$home_directory${wp_content}/mu-plugins/ $path/$site_path/backup/${wp_content}/mu-plugins/ --exclude .DS_Store --exclude *timthumb.txt --config="$rclone_config_file"
|
||||
rclone sync ${environment}:$home_directory${wp_content}/plugins/ $path/$site_path/backup/${wp_content}/plugins/ --exclude .DS_Store --exclude *timthumb.txt --config="$rclone_config_file"
|
||||
|
||||
# Sync to git repo
|
||||
mkdir -p $path/$site_path/quicksave/mu-plugins
|
||||
|
@ -98,18 +107,10 @@ run_command() {
|
|||
rsync -a --delete --exclude=.git --exclude="log-*.txt" --exclude="*.log.txt" --exclude="*.zip" --exclude=cache.json --exclude="*.log" --exclude="*.log.txt" $path/$site_path/backup/${wp_content}/plugins/ $path/$site_path/quicksave/plugins
|
||||
rsync -a --delete --exclude=.git --exclude="log-*.txt" --exclude="*.log.txt" --exclude="*.zip" --exclude=cache.json --exclude="*.log" --exclude="*.log.txt" $path/$site_path/backup/${wp_content}/themes/ $path/$site_path/quicksave/themes
|
||||
|
||||
cd ${root_path}data
|
||||
|
||||
# Remove leading "--" from flags
|
||||
for i in "${!flags[@]}"; do
|
||||
flags[$i]=`echo ${flags[$i]} | cut -c 3-`
|
||||
done
|
||||
cd ${CAPTAINCORE_PATH}/data
|
||||
|
||||
# Sync data
|
||||
wp eval-file ../lib/local-scripts/site-sync-data.php site=$site environment=$environment ${flags[@]}
|
||||
|
||||
# Add new quicksave
|
||||
wp eval-file ../lib/local-scripts/quicksave-add.php site=$site environment=$environment ${flags[@]}
|
||||
wp eval-file ../lib/local-scripts/site-sync-data.php site=$site environment=$environment
|
||||
wp eval-file ../lib/local-scripts/quicksave-add.php site=$site environment=$environment
|
||||
|
||||
if [ -f "${path}/process-${process_id}-progress.log" ]; then
|
||||
echo -n "." >> ${path}/process-${process_id}-progress.log
|
||||
|
@ -117,19 +118,4 @@ run_command() {
|
|||
|
||||
}
|
||||
|
||||
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 quicksave ${arguments[*]} ${flags[@]}
|
||||
fi
|
||||
|
||||
if [ ${#targets[*]} -gt 0 ] && [ ${#arguments[*]} -eq 0 ]; then
|
||||
captaincore bulk quicksave ${targets[*]/targets=/@} ${flags[@]}
|
||||
fi
|
||||
run_command $1
|
81
app/rollback → app/quicksave/rollback
Executable file → Normal file
81
app/rollback → app/quicksave/rollback
Executable file → Normal file
|
@ -14,15 +14,23 @@
|
|||
# [--all]
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
if [ ${#@} -ne 2 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a <site> and <commit>."
|
||||
exit
|
||||
fi
|
||||
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
site=$1
|
||||
commit=$2
|
||||
|
||||
run_command() {
|
||||
|
||||
site=$1
|
||||
commit=$2
|
||||
|
||||
# Requires <site> and <commit>
|
||||
if [[ $site == "" ]] || [[ $commit == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a site and a commit."
|
||||
|
@ -30,7 +38,7 @@ run_command() {
|
|||
fi
|
||||
|
||||
# Requires <site> and <commit>
|
||||
if [[ $plugin == "" ]] && [[ $theme == "" ]] && [[ $all == "" ]] && [[ $file == "" ]]; then
|
||||
if [[ $FLAG_PLUGIN == "" ]] && [[ $FLAG_THEME == "" ]] && [[ $all == "" ]] && [[ $FLAG_FILE == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a plugin, theme, file or --all."
|
||||
return 1
|
||||
fi
|
||||
|
@ -43,47 +51,62 @@ run_command() {
|
|||
fi
|
||||
|
||||
# Load site info
|
||||
while read site_configs; do if [[ $site_configs == "" ]]; then continue; fi; declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain_id=$captain_id)"
|
||||
while read site_configs; do if [[ $site_configs == "" ]]; then continue; fi; declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain-id=$CAPTAIN_ID)"
|
||||
|
||||
# Define Rclone site name
|
||||
rclone_site_name=${captain_id}-${site}-${environment}
|
||||
rclone_config_file="$path/${site}_${site_id}/rclone.conf"
|
||||
if [ ! -f "$rclone_config_file" ]; then
|
||||
captaincore site key-generate $site --captain-id=$CAPTAIN_ID
|
||||
fi
|
||||
|
||||
if [[ "$plugin" != "" ]]; then
|
||||
# Lookup rclone
|
||||
remote_check=$( rclone config show $environment --config="$rclone_config_file" )
|
||||
|
||||
echo "Rolling back plugin $plugin"
|
||||
if [[ $remote_check == *"Couldn't find type of fs"* ]]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M') Generating rclone configs for $site"
|
||||
captaincore site key-generate $site --captain-id=$CAPTAIN_ID
|
||||
fi
|
||||
|
||||
# Append trailing slash if home_directory exist
|
||||
if [ "$home_directory" != "" ]; then
|
||||
home_directory="${home_directory}/"
|
||||
fi
|
||||
|
||||
if [[ "$FLAG_PLUGIN" != "" ]]; then
|
||||
|
||||
echo "Rolling back plugin $FLAG_PLUGIN"
|
||||
cd $path/${site}_${site_id}/${environment}/quicksave/
|
||||
mkdir -p ~/Tmp/restore/$commit/
|
||||
git archive --format=zip $commit:plugins/$plugin/ > ~/Tmp/restore/$commit/$plugin.zip
|
||||
captaincore upload ${site}-${environment} ~/Tmp/restore/$commit/$plugin.zip --public --captain_id=$captain_id
|
||||
captaincore ssh ${site}-${environment} --command="rm -rf ${wp_content}/plugins/$plugin/; unzip $plugin.zip -d ${wp_content}/plugins/$plugin/; rm $plugin.zip" --captain_id=$captain_id
|
||||
git archive --format=zip $commit:plugins/$FLAG_PLUGIN/ > ~/Tmp/restore/$commit/$FLAG_PLUGIN.zip
|
||||
captaincore upload ${site}-${environment} ~/Tmp/restore/$commit/$FLAG_PLUGIN.zip --public --captain-id=$CAPTAIN_ID
|
||||
captaincore ssh ${site}-${environment} --command="rm -rf ${wp_content}/plugins/$FLAG_PLUGIN/; unzip $FLAG_PLUGIN.zip -d ${wp_content}/plugins/$FLAG_PLUGIN/; rm $FLAG_PLUGIN.zip" --captain-id=$CAPTAIN_ID
|
||||
rm -rf ~/Tmp/restore/$commit/
|
||||
|
||||
fi
|
||||
|
||||
if [[ "$theme" != "" ]]; then
|
||||
if [[ "$FLAG_THEME" != "" ]]; then
|
||||
|
||||
echo "Rolling back theme $theme"
|
||||
echo "Rolling back theme $FLAG_THEME"
|
||||
cd $path/${site}_${site_id}/${environment}/quicksave/
|
||||
mkdir -p ~/Tmp/restore/$commit/
|
||||
git archive --format=zip $commit:themes/$theme/ > ~/Tmp/restore/$commit/$theme.zip
|
||||
captaincore upload ${site}-${environment} ~/Tmp/restore/$commit/$theme.zip --public --captain_id=$captain_id
|
||||
captaincore ssh ${site}-${environment} --command="rm -rf ${wp_content}/themes/$theme/; unzip $theme.zip -d ${wp_content}/themes/$theme/; rm $theme.zip" --captain_id=$captain_id
|
||||
git archive --format=zip $commit:themes/$FLAG_THEME/ > ~/Tmp/restore/$commit/$FLAG_THEME.zip
|
||||
captaincore upload ${site}-${environment} ~/Tmp/restore/$commit/$FLAG_THEME.zip --public --captain-id=$CAPTAIN_ID
|
||||
captaincore ssh ${site}-${environment} --command="rm -rf ${wp_content}/themes/$FLAG_THEME/; unzip $FLAG_THEME.zip -d ${wp_content}/themes/$FLAG_THEME/; rm $FLAG_THEME.zip" --captain-id=$CAPTAIN_ID
|
||||
rm -rf ~/Tmp/restore/$commit/
|
||||
|
||||
fi
|
||||
|
||||
if [[ "$file" != "" ]]; then
|
||||
if [[ "$FLAG_FILE" != "" ]]; then
|
||||
|
||||
file_name=${file##*/}
|
||||
file_path=${file//$file_name/}
|
||||
echo "Rolling back file '$file'"
|
||||
file_name=${FLAG_FILE##*/}
|
||||
file_path=${FLAG_FILE//$file_name/}
|
||||
echo "Rolling back file '$FLAG_FILE'"
|
||||
cd $path/${site}_${site_id}/${environment}/quicksave/
|
||||
mkdir -p ~/Tmp/restore/$commit/$file_path
|
||||
git show $commit:$file > ~/Tmp/restore/$commit/$file
|
||||
git show $commit:$FLAG_FILE > ~/Tmp/restore/$commit/$FLAG_FILE
|
||||
if [[ "$home_directory" != "" ]]; then
|
||||
home_directory="${home_directory}/"
|
||||
fi
|
||||
rclone copyto ~/Tmp/restore/$commit/$file sftp-$rclone_site_name:${home_directory}${wp_content}/$file
|
||||
rclone copyto ~/Tmp/restore/$commit/$FLAG_FILE ${environment}:$home_directory${wp_content}/$FLAG_FILE --config="$rclone_config_file"
|
||||
rm -rf ~/Tmp/restore/$commit/
|
||||
|
||||
fi
|
||||
|
@ -94,11 +117,11 @@ run_command() {
|
|||
cd $path/${site}_${site_id}/${environment}/quicksave/
|
||||
mkdir -p ~/Tmp/restore/$commit/
|
||||
git archive --format=zip $commit: > ~/Tmp/restore/$commit/quicksave_${commit}_all.zip
|
||||
captaincore upload ${site}-${environment} ~/Tmp/restore/$commit/quicksave_${commit}_all.zip --public --captain_id=$captain_id
|
||||
echo '<?php $upgrading = time(); ?>' | captaincore ssh ${site}-${environment} --command="cat > .maintenance; rm -rf ${wp_content}/themes/; unzip -q -o quicksave_${commit}_all.zip 'themes/*' -d ${wp_content}/; rm -rf ${wp_content}/plugins/; unzip -q -o quicksave_${commit}_all.zip 'plugins/*' -d ${wp_content}/; rm -rf ${wp_content}/mu-plugins/; unzip -q -o quicksave_${commit}_all.zip 'mu-plugins/*' -d ${wp_content}/; rm .maintenance" --captain_id=$captain_id
|
||||
captaincore upload ${site}-${environment} ~/Tmp/restore/$commit/quicksave_${commit}_all.zip --public --captain-id=$CAPTAIN_ID
|
||||
echo '<?php $upgrading = time(); ?>' | captaincore ssh ${site}-${environment} --command="cat > .maintenance; rm -rf ${wp_content}/themes/; unzip -q -o quicksave_${commit}_all.zip 'themes/*' -d ${wp_content}/; rm -rf ${wp_content}/plugins/; unzip -q -o quicksave_${commit}_all.zip 'plugins/*' -d ${wp_content}/; rm -rf ${wp_content}/mu-plugins/; unzip -q -o quicksave_${commit}_all.zip 'mu-plugins/*' -d ${wp_content}/; rm .maintenance" --captain-id=$CAPTAIN_ID
|
||||
rm -rf ~/Tmp/restore/$commit/
|
||||
|
||||
fi
|
||||
|
||||
}
|
||||
run_command ${arguments[*]}
|
||||
run_command
|
52
app/quicksave/show-changes
Normal file
52
app/quicksave/show-changes
Normal file
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Shows file changes between Quicksaves.
|
||||
#
|
||||
# `captaincore view-changes <site> <commit-hash>`
|
||||
#
|
||||
|
||||
if [ ${#@} -ne 2 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a <site> and <commit-hash>."
|
||||
exit
|
||||
fi
|
||||
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
site=$1
|
||||
commit=$2
|
||||
|
||||
run_command() {
|
||||
|
||||
# Extract environment
|
||||
if [[ "$website" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
else
|
||||
environment=production
|
||||
fi
|
||||
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain-id=$captain_id)"
|
||||
|
||||
# Return error if domain not found
|
||||
if [[ "$domain" == "" ]] || [[ "$site" == "" ]] || [[ "$provider" == "" ]]; then
|
||||
echo "Can't locate website for site $site"
|
||||
return
|
||||
fi
|
||||
|
||||
if [ ! -d "$path/${site}_${site_id}/${environment}/quicksave/" ]; then
|
||||
echo -e "Error: Unable to locate Quicksave."
|
||||
return
|
||||
fi
|
||||
|
||||
cd $path/${site}_${site_id}/${environment}/quicksave/
|
||||
git_show=$( git show $commit --name-status --format= )
|
||||
echo "$git_show"
|
||||
|
||||
}
|
||||
|
||||
run_command
|
0
app/site/quicksave/store → app/quicksave/sync
Executable file → Normal file
0
app/site/quicksave/store → app/quicksave/sync
Executable file → Normal file
0
app/site/quicksave/usage-update → app/quicksave/usage-update
Executable file → Normal file
0
app/site/quicksave/usage-update → app/quicksave/usage-update
Executable file → Normal file
|
@ -1 +0,0 @@
|
|||
Rollback theme, plugin or file from a Quicksave on a site.
|
|
@ -1 +0,0 @@
|
|||
<site> <commit> [--plugin=<plugin>] [--theme=<theme>] [--all]
|
25
app/run
25
app/run
|
@ -6,19 +6,21 @@
|
|||
# `captaincore run <site> --code=<code>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -gt 0 ] && [[ "$code" != "" ]]; then
|
||||
if [ ${#@} -gt 0 ] && [[ "$CAPTAINCORE_CODE" != "" ]]; then
|
||||
# Generates receipe
|
||||
timestamp=$( date +'%Y-%m-%d' )
|
||||
recipe_file=$path_recipes/${captain_id}-${timestamp}-${code:0:8}.sh
|
||||
recipe_name=${timestamp}-${code:0:8}
|
||||
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
|
||||
$code
|
||||
$CAPTAINCORE_CODE
|
||||
PHPHEREDOC;
|
||||
|
||||
echo base64_decode( \$run_code );
|
||||
|
@ -28,10 +30,9 @@ heredoc
|
|||
echo -n "$code" > "${recipe_file}"
|
||||
|
||||
# Runs on specifed sites
|
||||
captaincore ssh ${arguments[*]} --recipe=$recipe_name --captain_id=$captain_id
|
||||
captaincore ssh $1 --recipe=$recipe_name --captain-id=$CAPTAIN_ID
|
||||
exit
|
||||
fi
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#arguments[*]} -eq 0 ] || [[ "$code" == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a <site> and --code=<code>."
|
||||
fi
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a <site> and --code=<code>."
|
|
@ -1 +0,0 @@
|
|||
Runs custom bash script or WP-CLI commands on a site.
|
|
@ -1,31 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Fetch running processes
|
||||
#
|
||||
# `captaincore running get <process-id>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
if [ ${#arguments[*]} -ne 1 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a <process-id>."
|
||||
exit
|
||||
fi
|
||||
if [ ! -f "${path}/process-$1-progress.log" ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Process $1 not found."
|
||||
exit
|
||||
fi
|
||||
if [[ "$json" == "true" ]]; then
|
||||
format=json
|
||||
fi
|
||||
php ${root_path}lib/local-scripts/process-track.php ${path}/process-$1-progress.log
|
||||
inotifywait -q -m -e close_write -e delete_self ${path}/process-$1-progress.log | while read -r filename event; do
|
||||
if [[ "$event" == "DELETE_SELF" ]]; then
|
||||
kill $$
|
||||
exit
|
||||
fi
|
||||
php ${root_path}lib/local-scripts/process-track.php $filename $format
|
||||
done
|
|
@ -1,18 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Fetch running processes
|
||||
#
|
||||
# `captaincore running list`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
if [ ${#arguments[*]} -ne 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Unexpected arguments passed to `captaincore running list`."
|
||||
exit
|
||||
fi
|
||||
|
||||
php ${root_path}lib/local-scripts/process-list.php "${path}/running.json"
|
|
@ -1,24 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Fetch running processes
|
||||
#
|
||||
# `captaincore running listen`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
for log in $( find ${path}/ -maxdepth 1 -name 'process-*-progress.log' ); do
|
||||
php ${root_path}lib/local-scripts/process-track.php $log "json"
|
||||
done
|
||||
|
||||
inotifywait -q -m -e create -e close_write -e close -e delete -e delete_self ${path} | while read -r dir event file; do
|
||||
if [[ "$event" == "DELETE" ]]; then
|
||||
process_id=${filename//process-/}
|
||||
fi
|
||||
if [[ "$event" == "CLOSE_WRITE"* ]]; then
|
||||
php ${root_path}lib/local-scripts/process-track.php ${dir}$file "json"
|
||||
fi
|
||||
done
|
|
@ -12,56 +12,40 @@
|
|||
# Target groups of sites like @all @production or @staging. Use `captaincore update @production.updates-on` to target production sites marked for automatic updates.
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
run_command() {
|
||||
|
||||
# Remove leading "--" from flags
|
||||
for i in "${!flags[@]}"; do
|
||||
flags[$i]=`echo ${flags[$i]} | cut -c 3-`
|
||||
done
|
||||
|
||||
cd ${root_path}data
|
||||
|
||||
INDEX=0
|
||||
website=$@
|
||||
|
||||
let INDEX=${INDEX}+1
|
||||
|
||||
# Extract environment
|
||||
if [[ "$website" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
else
|
||||
environment=production
|
||||
fi
|
||||
|
||||
# Load site configs
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $website --bash --captain_id=$captain_id)"
|
||||
|
||||
# Scans for errors
|
||||
wp eval-file ../lib/local-scripts/site-scan-errors-in-console.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."
|
||||
if [ ${#@} -ne 1 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Requires a <site>"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ ${#arguments[*]} -eq 1 ] && [ ${#targets[*]} -eq 0 ]; then
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
if [ ${#arguments[*]} -gt 1 ] && [ ${#targets[*]} -eq 0 ]; then
|
||||
captaincore bulk scan-errors ${arguments[*]} ${flags[@]}
|
||||
fi
|
||||
site=$1
|
||||
|
||||
if [ ${#targets[*]} -gt 0 ] && [ ${#arguments[*]} -eq 0 ]; then
|
||||
captaincore bulk scan-errors ${targets[*]/targets=/@} ${flags[@]}
|
||||
fi
|
||||
run_command() {
|
||||
|
||||
cd ${CAPTAINCORE_PATH}/data
|
||||
|
||||
if [[ "$website" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
else
|
||||
environment=production
|
||||
fi
|
||||
|
||||
# Load site configs
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain-id=$CAPTAIN_ID)"
|
||||
|
||||
# Scans for errors
|
||||
wp eval-file ../lib/local-scripts/site-scan-errors-in-console.php site=$site environment=$environment
|
||||
|
||||
if [ -f "${path}/process-${process_id}-progress.log" ]; then
|
||||
echo -n "." >> ${path}/process-${process_id}-progress.log
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
run_command
|
|
@ -1,87 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Takes screenshot of one or more sites
|
||||
#
|
||||
# `captaincore screenshot`
|
||||
#
|
||||
# [<site>...]
|
||||
# One or more sites.
|
||||
#
|
||||
# [@<target>]
|
||||
# Target groups of sites like @all @production or @staging.
|
||||
#
|
||||
# [--parallel=<number-of-checks>]
|
||||
# Number of monitor checks to run at same time. Defaults to 5.
|
||||
#
|
||||
# [--page=<page-url>]
|
||||
# Check a specific page. Example `--page=/wp-admin/`. Defaults to home page.
|
||||
#
|
||||
# [--debug]
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
|
||||
if [[ "$( gowitness version )" == *"not found"* ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} `gowitness` not found. Install from https://github.com/sensepost/gowitness/releases and make sure Chrome is installed."
|
||||
exit
|
||||
fi
|
||||
|
||||
run_command() {
|
||||
|
||||
# Format: Screenshot folder,HTTP url to check,Remote Send
|
||||
urls_to_check=""
|
||||
|
||||
# Assign default parallel if needed
|
||||
if [[ $parallel == "" ]]; then
|
||||
parallel=4
|
||||
fi
|
||||
|
||||
echo "Preparing to take screenshots"
|
||||
|
||||
for website in "$@"; do
|
||||
|
||||
# Extract environment
|
||||
if [[ "$website" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
else
|
||||
environment=production
|
||||
fi
|
||||
|
||||
# Load site configs
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $website --bash --captain_id=$captain_id)"
|
||||
|
||||
if [[ "$home_url" != "" ]]; then
|
||||
mkdir -p $path/${site}_${site_id}/${environment}/screenshots/
|
||||
urls_to_check+="\"$path/${site}_${site_id}/${environment}/screenshots/,${home_url},${rclone_screenshots}${site}_${site_id}/${environment}/\"\n"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
if [[ "$debug" == true ]]; then
|
||||
echo -e "URLs to check: $urls_to_check"
|
||||
fi
|
||||
|
||||
# Run checks in parallel. Collect the results in log file.
|
||||
( echo -e $urls_to_check | xargs -P $parallel -n 1 captaincore screenshot-runner ) 2>&1 | tee $log_file
|
||||
|
||||
}
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -gt 0 ]; then
|
||||
# Runs on specifed sites
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
|
||||
# Runs on targeted sites
|
||||
if [ ${#targets[*]} -gt 0 ]; then
|
||||
run_command $(captaincore site list ${targets[*]/targets=/@} --captain_id=$captain_id)
|
||||
fi
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#targets[*]} -eq 0 ] && [ ${#arguments[*]} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify one or more sites, or use a target @all, @production or @staging."
|
||||
fi
|
|
@ -1,49 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Screenshots a single valid HTTP url.
|
||||
#
|
||||
# `captaincore screenshot-runner <path-to-screenshot-folder>,<site-url>`
|
||||
#
|
||||
# Used by `captaincore screenshot`. Not to be used directly.
|
||||
#
|
||||
|
||||
|
||||
arguments=$( echo $1 | tr , '\n' )
|
||||
|
||||
# Vars
|
||||
path=$( echo "$arguments" | head -n 1 )
|
||||
url=$( echo "$arguments" | head -n 2 | tail -n 1 )
|
||||
remote=$( echo "$arguments" | head -n 3 | tail -n 1 )
|
||||
|
||||
run_command() {
|
||||
|
||||
echo "Generating screenshot for $url"
|
||||
bash_output=$( ( gowitness single --url="$url" --log-format=json --timeout=60 --disable-db --destination="$path" ) 2>&1 | cat )
|
||||
|
||||
# PHP script to parse and base64
|
||||
read -r -d '' php_code << heredoc
|
||||
\$raw = <<< EOT
|
||||
$bash_output
|
||||
EOT;
|
||||
\$array = explode("\n", \$raw );
|
||||
foreach( \$array as \$line ) {
|
||||
\$json = json_decode( \$line );
|
||||
if ( \$json->msg == "Screenshot taken" ) {
|
||||
echo \$json->destination;
|
||||
}
|
||||
}
|
||||
heredoc
|
||||
|
||||
new_screenshot=$( php -r "$php_code" )
|
||||
if [[ -f $new_screenshot ]]; then
|
||||
mv $new_screenshot "${path}screenshot.png"
|
||||
convert "${path}screenshot.png" -resize 100 "${path}screenshot-100.png"
|
||||
convert "${path}screenshot.png" -resize 800 "${path}screenshot-800.png"
|
||||
rclone move "${path}screenshot-100.png" "$remote"
|
||||
rclone move "${path}screenshot-800.png" "$remote"
|
||||
fi
|
||||
|
||||
}
|
||||
run_command
|
||||
|
|
@ -1 +0,0 @@
|
|||
Takes screenshot of a single site.
|
|
@ -1 +0,0 @@
|
|||
Takes screenshot of one or more sites.
|
|
@ -1,60 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Shows file changes between Quicksaves.
|
||||
#
|
||||
# `captaincore view-changes <site> --hash=<git_hash>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
run_command() {
|
||||
|
||||
for website in "$@"; do
|
||||
|
||||
# Extract environment
|
||||
if [[ "$website" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
else
|
||||
environment=production
|
||||
fi
|
||||
|
||||
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $website --bash --captain_id=$captain_id)"
|
||||
|
||||
# Return error if domain not found
|
||||
if [[ "$domain" == "" ]] || [[ "$site" == "" ]] || [[ "$provider" == "" ]]; then
|
||||
echo "Can't locate website for site $site"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -d "$path/${site}_${site_id}/${environment}/quicksave/" ]; then
|
||||
echo -e "Error: Unable to locate Quicksave."
|
||||
return
|
||||
fi
|
||||
|
||||
cd $path/${site}_${site_id}/${environment}/quicksave/
|
||||
git_show=`git show $hash --name-status --format=`
|
||||
echo "$git_show"
|
||||
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -gt 0 ]; then
|
||||
# Runs on specifed sites
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
|
||||
# Runs on targeted sites
|
||||
if [ ${#targets[*]} -gt 0 ]; then
|
||||
run_command $(captaincore site list ${targets[*]/targets=/@} --captain_id=$captain_id)
|
||||
fi
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#targets[*]} -eq 0 ] && [ ${#arguments[*]} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify one or more sites, or use a target @all, @production or @staging."
|
||||
fi
|
|
@ -1 +0,0 @@
|
|||
Shows file changes between Quicksaves.
|
|
@ -1 +0,0 @@
|
|||
<site> <git_hash>
|
|
@ -1 +0,0 @@
|
|||
Adds or removes a site
|
|
@ -1,58 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Fetches list of snapshots for a site from a backup repo
|
||||
#
|
||||
# `captaincore site backup list <site>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
run_command() {
|
||||
|
||||
INDEX=1
|
||||
for site in "$@"; do
|
||||
|
||||
# Extract environment
|
||||
if [[ "$site" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
fi
|
||||
|
||||
if [[ "$site" == *"-production"* ]]; then
|
||||
environment=production
|
||||
fi
|
||||
|
||||
if [[ "$site" != *"-"* ]]; then
|
||||
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)"
|
||||
|
||||
backup_list="$path/${site}_${site_id}/${environment}/backups/list.json"
|
||||
if [ ! -f "$backup_list" ]; then
|
||||
captaincore site backup list-generate $site-$environment --captain_id=$captain_id
|
||||
fi
|
||||
cat "$backup_list"
|
||||
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -gt 0 ]; then
|
||||
# Runs on specifed sites
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
|
||||
# Runs on targeted sites
|
||||
if [ ${#targets[*]} -gt 0 ]; then
|
||||
run_command $(captaincore site list ${targets[*]/targets=/@} --captain_id=$captain_id)
|
||||
fi
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#targets[*]} -eq 0 ] && [ ${#arguments[*]} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify one or more sites, or use a target @all, @production or @staging."
|
||||
fi
|
|
@ -1,63 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Generates list of snapshots for a site from a backup repo
|
||||
#
|
||||
# `captaincore site backup list-generate <site>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
run_command() {
|
||||
|
||||
INDEX=1
|
||||
for site in "$@"; do
|
||||
|
||||
# Extract environment
|
||||
if [[ "$site" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
fi
|
||||
|
||||
if [[ "$site" == *"-production"* ]]; then
|
||||
environment=production
|
||||
fi
|
||||
|
||||
if [[ "$site" != *"-"* ]]; then
|
||||
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)"
|
||||
|
||||
if [[ $( restic snapshots --repo rclone:$rclone_backup/${site}_${site_id}/${environment}/restic-repo ) == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Backup repo not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p $path/${site}_${site_id}/${environment}/backups/
|
||||
backup_list="$path/${site}_${site_id}/${environment}/backups/list.json"
|
||||
|
||||
cd ${root_path}data
|
||||
wp eval-file ${root_path}lib/local-scripts/backups-list.php site=$site site_id=$site_id environment=$environment captain_id=$captain_id > $backup_list
|
||||
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -gt 0 ]; then
|
||||
# Runs on specifed sites
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
|
||||
# Runs on targeted sites
|
||||
if [ ${#targets[*]} -gt 0 ]; then
|
||||
run_command $(captaincore site list ${targets[*]/targets=/@} --captain_id=$captain_id)
|
||||
fi
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#targets[*]} -eq 0 ] && [ ${#arguments[*]} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify one or more sites, or use a target @all, @production or @staging."
|
||||
fi
|
|
@ -1,46 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Adds a site to CaptainCore CLI.
|
||||
#
|
||||
# `captaincore site add <site>`
|
||||
#
|
||||
# --id=<id> --domain=<domain> --username=<username> --password=<password> --address=<address> --protocol=<protocol> --port=<port> --staging_username=<staging_username> --staging_password=<staging_password> --staging_address=<staging_address> --staging_protocol=<staging_protocol> --staging_port=<staging_port> [--preloadusers=<preloadusers>] [--home_directory=<home_directory>] [--offload_provider=<offload_provider>] [--offload_access_key=<offload_access_key>] [--offload_secret_key=<offload_secret_key>] [--offload_bucket=<offload_bucket>] [--offload_path=<offload_path>] [--captain_id=<id>]
|
||||
# Example: captaincore site add <site> --id=1234 --domain=sitename.com --username=sitename --password=random --address=sitename.wpengine.com --protocol=sftp --port=2222 --staging_username=sitename-staging --staging_password=randompassword --staging_address=sitename.wpengine.com --staging_protocol=sftp --staging_port=2222 --preloadusers=1737
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
run_command() {
|
||||
|
||||
# Remove leading "--" from flags
|
||||
for i in "${!flags[@]}"; do
|
||||
flags[$i]=`echo ${flags[$i]} | cut -c 3-`
|
||||
done
|
||||
|
||||
cd ${root_path}data
|
||||
wp eval-file ../lib/local-scripts/site-add.php site=$1 ${flags[@]}
|
||||
|
||||
# Load site configs
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $1 --bash --captain_id=$captain_id)"
|
||||
|
||||
# Generate rclone keys
|
||||
captaincore site rclone-configs $site --captain_id=$captain_id
|
||||
|
||||
# Update configs
|
||||
captaincore configs update-websites --captain_id=$captain_id
|
||||
|
||||
}
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -eq 1 ]; then
|
||||
# Runs on specifed sites
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#arguments[*]} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a site."
|
||||
fi
|
|
@ -1,45 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Removes a site from CaptainCore CLI.
|
||||
#
|
||||
# `captaincore site delete <site>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
run_command() {
|
||||
|
||||
site=$1
|
||||
cd ${root_path}data
|
||||
|
||||
# Requires <site>
|
||||
if [[ "$site" == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify one a site."
|
||||
return 1
|
||||
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)"
|
||||
|
||||
if [[ "$site" != "" ]] && [[ "$site_id" != "" ]]; then
|
||||
wp eval-file ../lib/local-scripts/site-delete.php site=$site id=$site_id captain_id=$captain_id
|
||||
fi
|
||||
|
||||
# Update configs
|
||||
captaincore configs update-websites --captain_id=$captain_id
|
||||
|
||||
}
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -eq 1 ]; then
|
||||
# Runs on specifed sites
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#arguments[*]} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a site."
|
||||
fi
|
|
@ -1,44 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Updates a site in CaptainCore CLI.
|
||||
#
|
||||
# `captaincore site update <site> --id=<id> --domain=<domain> --username=<username> --password=<password> --address=<address> --protocol=<protocol> --port=<port> --staging_username=<staging_username> --staging_password=<staging_password> --staging_address=<staging_address> --staging_protocol=<staging_protocol> --staging_port=<staging_port> [--preloadusers=<preloadusers>] [--home_directory=<home_directory>] [--s3accesskey=<s3accesskey>] [--s3secretkey=<s3secretkey>] [--s3bucket=<s3bucket>] [--s3path=<s3path>]`
|
||||
#
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
run_command() {
|
||||
|
||||
# Remove leading "--" from flags
|
||||
for i in "${!flags[@]}"; do
|
||||
flags[$i]=`echo ${flags[$i]} | cut -c 3-`
|
||||
done
|
||||
|
||||
cd ${root_path}data
|
||||
wp eval-file ../lib/local-scripts/site-update.php site=$1 ${flags[@]}
|
||||
|
||||
# Load site configs
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $1 --bash --captain_id=$captain_id)"
|
||||
|
||||
# Generate rclone keys
|
||||
captaincore site rclone-configs $site --captain_id=$captain_id
|
||||
|
||||
# Update configs
|
||||
captaincore configs update-websites --captain_id=$captain_id
|
||||
|
||||
}
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -eq 1 ]; then
|
||||
# Runs on specifed sites
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#arguments[*]} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a site."
|
||||
fi
|
|
@ -6,9 +6,10 @@
|
|||
# `captaincore site delete <site>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
if [ ${#@} -ne 1 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a site."
|
||||
exit
|
||||
fi
|
||||
|
||||
run_command() {
|
||||
|
||||
|
@ -22,7 +23,7 @@ run_command() {
|
|||
return 1
|
||||
fi
|
||||
|
||||
verify=$( captaincore site get $site --captain_id=$captain_id )
|
||||
verify=$( captaincore site get $site --captain-id=$captain_id )
|
||||
|
||||
if [[ "$verify" == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Site '$site' not found in CaptainCore."
|
||||
|
@ -30,27 +31,18 @@ run_command() {
|
|||
fi
|
||||
|
||||
# Final snapshot then remove site related files
|
||||
captaincore snapshot $site --delete-after-snapshot --email=$captaincore_admin_email --captain_id=$captain_id
|
||||
captaincore snapshot $site --delete-after-snapshot --email=$captaincore_admin_email --captain-id=$captain_id
|
||||
|
||||
# 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)"
|
||||
while read site_configs; do if [[ $site_configs == "" ]]; then continue; fi; declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain-id=$captain_id)"
|
||||
|
||||
if [[ "$site" != "" ]] && [[ "$site_id" != "" ]]; then
|
||||
wp eval-file ../lib/local-scripts/site-delete.php site_id=$site_id captain_id=$captain_id
|
||||
wp eval-file ../lib/local-scripts/site-delete.php site_id=$site_id captain-id=$captain_id
|
||||
fi
|
||||
|
||||
# Update configs
|
||||
captaincore configs update-websites --captain_id=$captain_id
|
||||
captaincore configs update-websites --captain-id=$captain_id
|
||||
|
||||
}
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -eq 1 ]; then
|
||||
# Runs on specifed sites
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#arguments[*]} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a site."
|
||||
fi
|
||||
run_command $1
|
|
@ -1 +0,0 @@
|
|||
<site>
|
|
@ -1,64 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Deploy default plugins/themes/settings for website
|
||||
#
|
||||
# `captaincore deploy-defaults`
|
||||
#
|
||||
# [<site>...]
|
||||
# One or more sites.
|
||||
#
|
||||
# [--global-only]
|
||||
#
|
||||
# [@<target>]
|
||||
# Target groups of sites like @all @production or @staging.
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
run_command() {
|
||||
|
||||
echo "Deploying defaults to $# sites"
|
||||
|
||||
# Remove leading "--" from flags
|
||||
for i in "${!flags[@]}"; do
|
||||
flags[$i]=`echo ${flags[$i]} | cut -c 3-`
|
||||
done
|
||||
|
||||
cd ${root_path}data;
|
||||
|
||||
for website in "$@"; do
|
||||
|
||||
# Extract environment
|
||||
if [[ "$website" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
else
|
||||
environment=production
|
||||
fi
|
||||
|
||||
# Load site configs
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $website --bash --captain_id=$captain_id)"
|
||||
|
||||
wp eval-file ../lib/local-scripts/site-deploy-defaults.php site=$site environment=$environment ${flags[@]}
|
||||
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -gt 0 ]; then
|
||||
# Runs on specifed sites
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
|
||||
# Runs on targeted sites
|
||||
if [ ${#targets[*]} -gt 0 ]; then
|
||||
run_command $(captaincore site list ${targets[*]/targets=/@} --captain_id=$captain_id)
|
||||
fi
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#targets[*]} -eq 0 ] && [ ${#arguments[*]} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify one or more sites, or use a target @all, @production or @staging."
|
||||
fi
|
|
@ -6,13 +6,22 @@
|
|||
# `captaincore deploy keys <site>`
|
||||
#
|
||||
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
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
|
||||
|
||||
run_command() {
|
||||
|
||||
website=$1
|
||||
|
||||
# Extract environment
|
||||
if [[ "$website" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
|
@ -21,15 +30,22 @@ run_command() {
|
|||
fi
|
||||
|
||||
# Load site vars
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $website --bash --captain_id=$captain_id)"
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain-id=$CAPTAIN_ID)"
|
||||
|
||||
# Define Rclone site name
|
||||
rclone_site_name=${captain_id}-${site}-${environment}
|
||||
if [[ "$domain" == "" ]]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
# Define Rclone config file
|
||||
rclone_config_file="$path/${site}_${site_id}/rclone.conf"
|
||||
if [ ! -f "$rclone_config_file" ]; then
|
||||
captaincore site key-generate $site --captain-id=$CAPTAIN_ID
|
||||
fi
|
||||
|
||||
if [[ $provider == "kinsta" ]]; then
|
||||
|
||||
# Check for authorized_keys using rclone's JSON
|
||||
check_for_keys=$( rclone lsjson sftp-${rclone_site_name}:.ssh/authorized_keys --no-modtime )
|
||||
check_for_keys=$( rclone lsjson ${environment}:.ssh/authorized_keys --no-modtime --config="$rclone_config_file" )
|
||||
|
||||
# PHP script to read JSON value
|
||||
read -r -d '' php_code << heredoc
|
||||
|
@ -48,21 +64,21 @@ heredoc
|
|||
|
||||
# No authorized_keys found, generate new one
|
||||
if [[ "$found_authorized_keys" != "authorized_keys" ]]; then
|
||||
echo local_public_key | rclone rcat sftp-${rclone_site_name}:.ssh/authorized_keys
|
||||
echo local_public_key | rclone rcat ${environment}:.ssh/authorized_keys --config="$rclone_config_file"
|
||||
fi
|
||||
|
||||
# Examine existing authorized_keys file
|
||||
if [[ "$found_authorized_keys" == "authorized_keys" ]]; then
|
||||
|
||||
# Fetch current authorized_keys
|
||||
authorized_keys=$( rclone cat sftp-${rclone_site_name}:.ssh/authorized_keys )
|
||||
authorized_keys=$( rclone cat ${environment}:.ssh/authorized_keys --config="$rclone_config_file" )
|
||||
|
||||
# Check if key is already added
|
||||
if [ -z "${authorized_keys##*$local_public_key*}" ]; then
|
||||
echo "Key already added."
|
||||
else
|
||||
echo "Adding key."
|
||||
printf "$authorized_keys\n$local_public_key\n" | rclone rcat sftp-${rclone_site_name}:.ssh/authorized_keys
|
||||
printf "$authorized_keys\n$local_public_key\n" | rclone rcat ${environment}:.ssh/authorized_keys --config="$rclone_config_file"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
@ -75,13 +91,4 @@ fi
|
|||
|
||||
}
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -eq 1 ]; then
|
||||
# Runs on specifed sites
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#arguments[*]} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a site."
|
||||
fi
|
||||
run_command
|
|
@ -1,19 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Lists environments for a site
|
||||
#
|
||||
# `captaincore site environment list <site>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
# Remove leading "--" from flags
|
||||
for i in "${!flags[@]}"; do
|
||||
flags[$i]=$( echo ${flags[$i]} | cut -c 3- )
|
||||
done
|
||||
|
||||
cd ${root_path}data
|
||||
wp eval-file ${root_path}lib/local-scripts/site-environment-list.php site=$1
|
|
@ -6,11 +6,19 @@
|
|||
# `captaincore site fetch-token <site>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
site=${arguments[1]}
|
||||
if [ ${#@} -ne 1 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a site."
|
||||
exit
|
||||
fi
|
||||
|
||||
site=$1
|
||||
|
||||
# Extract environment
|
||||
if [[ "$site" == *"-staging"* ]]; then
|
||||
|
@ -20,7 +28,7 @@ else
|
|||
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)"
|
||||
while read site_configs; do if [[ $site_configs == "" ]]; then continue; fi; declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain-id=$CAPTAIN_ID)"
|
||||
|
||||
if [ -f $path/${site}_${site_id}/${environment}/backup/wp-config.php ]; then
|
||||
|
||||
|
|
59
app/site/get
59
app/site/get
|
@ -1,59 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Get details about a site.
|
||||
#
|
||||
# `captaincore site get <site>`
|
||||
#
|
||||
# [--field=<field>]
|
||||
# Returns specific field
|
||||
#
|
||||
# [--bash]
|
||||
# Return in bash format
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
run_command() {
|
||||
|
||||
site=$1
|
||||
cd ${root_path}data
|
||||
|
||||
# Requires <site>
|
||||
if [[ "$site" == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify one a site."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Detect if provider passed into <site>
|
||||
if [[ "$site" == *"@"* ]]; then
|
||||
provider=$(echo $site | awk -F@ '{print $2}')
|
||||
site=$(echo $site | awk -F@ '{print $1}')
|
||||
fi
|
||||
|
||||
# Extract environment
|
||||
if [[ "$site" == *"-staging" ]] || [[ "$site" == *"-staging@" ]]; then
|
||||
environment=staging
|
||||
fi
|
||||
|
||||
if [[ ! "$site" == *"-"* ]] || [[ "$site" == *"-production" ]] || [[ "$site" == *"-production@" ]]; then
|
||||
environment=production
|
||||
fi
|
||||
|
||||
site=$(echo $site | awk -F- '{print $1}')
|
||||
|
||||
if [[ "$bash" == "true" ]]; then
|
||||
# Output bash format
|
||||
wp eval-file ${root_path}lib/local-scripts/site-get.php site=$site provider=$provider environment=$environment format=bash field=$field
|
||||
elif [[ "$field" != "" ]]; then
|
||||
# Output raw format
|
||||
wp eval-file ${root_path}lib/local-scripts/site-get.php site=$site provider=$provider environment=$environment format=json field=$field
|
||||
else
|
||||
# Output json format
|
||||
wp eval-file ${root_path}lib/local-scripts/site-get.php site=$site provider=$provider environment=$environment format=json field=$field
|
||||
fi
|
||||
|
||||
}
|
||||
run_command ${arguments[*]}
|
|
@ -1 +0,0 @@
|
|||
<site> [--field=<field>] [--bash]
|
59
app/site/key-generate
Normal file
59
app/site/key-generate
Normal file
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Generates rclone configs based on site credentials
|
||||
#
|
||||
# `captaincore site rclone-configs <site>`
|
||||
#
|
||||
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
run_command() {
|
||||
|
||||
site=$1
|
||||
|
||||
# Load site vars
|
||||
while read site_configs; do if [[ $site_configs == "" ]]; then continue; fi; declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain-id=$CAPTAIN_ID)"
|
||||
|
||||
# Domain not found
|
||||
if [[ $domain == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Domain not found."
|
||||
return
|
||||
fi
|
||||
|
||||
rclone_config_file="$path/${site}_${site_id}/rclone.conf"
|
||||
mkdir -p "$path/${site}_${site_id}/"
|
||||
echo "" > "$rclone_config_file"
|
||||
|
||||
environments=( $( captaincore environment list $site --captain-id=$CAPTAIN_ID ) )
|
||||
|
||||
for environment in ${environments[@]}; do
|
||||
|
||||
while read site_configs; do if [[ $site_configs == "" ]]; then continue; fi; declare "$site_configs"; done <<< "$(captaincore site get $site-$environment --bash --captain-id=$CAPTAIN_ID)"
|
||||
|
||||
if [[ "$key" != "use_password" ]]; then
|
||||
if [[ $key == "" ]]; then
|
||||
key=$( captaincore configuration get --field=default_key )
|
||||
fi
|
||||
ssh_file="$path_keys/${CAPTAIN_ID}/${key}"
|
||||
echo "Generating rclone configs for ${site}-${environment} with SSH key"
|
||||
quiet=$( rclone config create $environment $protocol host $address user $username port $port key_file $ssh_file --config="$rclone_config_file" )
|
||||
fi
|
||||
|
||||
if [[ "$key" == "use_password" ]]; then
|
||||
password=$( captaincore site get ${site}-${environment} --field=password --captain-id=$CAPTAIN_ID )
|
||||
rclone_pass=$( rclone obscure $password )
|
||||
echo "Generating rclone configs for ${site}-${environment} with password"
|
||||
quiet=$( rclone config create $environment $protocol host $address user $username port $port pass --config="$rclone_config_file" -- $rclone_pass )
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
run_command $1
|
|
@ -1,21 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Lists sites
|
||||
#
|
||||
# `captaincore site list`
|
||||
#
|
||||
# [@<target>] [--provider=<provider>] [--filter=<themes|plugins|core>] [--filter-name=<name>] [--filter-version=<version>] [--filter-status=<active|inactive|dropin|must-use>] [--field=<field>]
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
# Remove leading "--" from flags
|
||||
for i in "${!flags[@]}"; do
|
||||
flags[$i]=$( echo ${flags[$i]} | cut -c 3- )
|
||||
done
|
||||
|
||||
cd ${root_path}data
|
||||
wp eval-file ${root_path}lib/local-scripts/site-list.php ${targets[@]} ${flags[@]}
|
|
@ -1 +0,0 @@
|
|||
[<@target> [--provider=<provider>] [--filter=<theme|plugin|core>] [--filter-name=<name>] [--filter-version=<version>] [--filter-status=<active|inactive|dropin|must-use>] [--field=<field>]
|
|
@ -6,45 +6,36 @@
|
|||
# `captaincore site prepare <site>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
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)"
|
||||
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 site environment list $site --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
|
||||
|
||||
# Define Rclone site name
|
||||
rclone_site_name="sftp-${captain_id}-${site}-${environment}"
|
||||
|
||||
# Captures FTP errors in $ftp_output and file listing to log file
|
||||
ftp_output=$( { rclone lsd $rclone_site_name:$home_directory ; } 2>&1 )
|
||||
ftp_search_for_wordpress=$( echo "$ftp_output" | perl -wnE'say for /wp-admin/g' )
|
||||
|
||||
# Handle FTP errors
|
||||
if [[ $ftp_search_for_wordpress != "wp-admin" ]]; then
|
||||
echo "Error: $site missing WordPress."
|
||||
exit
|
||||
fi
|
||||
|
||||
# Append trailing slash if home_directory exist
|
||||
if [ "$home_directory" != "" ]; then
|
||||
home_directory="${home_directory}/"
|
||||
fi
|
||||
captaincore site deploy-keys ${site}-${environment} --captain-id=$CAPTAIN_ID
|
||||
|
||||
# Pull down wp-config.php
|
||||
rclone copy $rclone_site_name:${home_directory}wp-config.php $path/${site}_${site_id}/${environment}/backup/
|
||||
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/
|
||||
|
||||
# Generate token
|
||||
token_key=$(captaincore site fetch-token $site-$environment --captain_id=$captain_id)
|
||||
token_key=$(captaincore site fetch-token $site-$environment --captain-id=$CAPTAIN_ID)
|
||||
|
||||
if [[ "$captaincore_dev" == true ]]; then
|
||||
curl_argument="-k"
|
||||
|
@ -61,20 +52,17 @@ for environment in ${environments[@]}; do
|
|||
EOF
|
||||
|
||||
# Set permalink to 'Post name' format if not set
|
||||
captaincore ssh ${site}-${environment} --script=rewrite-prep --captain_id=$captain_id
|
||||
captaincore ssh ${site}-${environment} --script=rewrite-prep --captain-id=$CAPTAIN_ID
|
||||
|
||||
# Deploy helper plugin
|
||||
captaincore ssh ${site}-${environment} --script=deploy-helper --wp_content=$wp_content --captain_id=$captain_id
|
||||
captaincore ssh ${site}-${environment} --script=deploy-helper --wp_content=$wp_content --captain-id=$CAPTAIN_ID
|
||||
|
||||
# Generate new Fathom code if needed
|
||||
if [[ $captaincore_tracker != "" ]] && [[ $fathom == "" ]]; then
|
||||
# Generate new Fathom tracking code, if needed
|
||||
captaincore site stats-generate ${site}-${environment} --captain_id=$captain_id
|
||||
captaincore site stats-generate ${site}-${environment} --captain-id=$CAPTAIN_ID
|
||||
fi
|
||||
|
||||
captaincore sync-data ${site}-${environment} --captain_id=$captain_id
|
||||
captaincore sync-data ${site}-${environment} --captain-id=$CAPTAIN_ID
|
||||
|
||||
done
|
||||
|
||||
# Update configs
|
||||
captaincore configs update-websites --captain_id=$captain_id
|
|
@ -1 +0,0 @@
|
|||
<site> [--skip-deployment]
|
|
@ -1,60 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Generates rclone configs based on site credentials
|
||||
#
|
||||
# `captaincore site rclone-configs <site>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
site=$1
|
||||
|
||||
run_command() {
|
||||
|
||||
# Load site vars
|
||||
while read site_configs; do if [[ $site_configs == "" ]]; then continue; fi; declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain_id=$captain_id)"
|
||||
|
||||
# Domain not found
|
||||
if [[ $domain == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Domain not found."
|
||||
return
|
||||
fi
|
||||
|
||||
site_name=$site
|
||||
|
||||
# Adjust path if fleet mode enabled
|
||||
if [[ "$captaincore_fleet" == "true" ]]; then
|
||||
site_name=${captain_id}-${site}
|
||||
fi
|
||||
|
||||
environments=( $( captaincore site environment list $site --captain_id=$captain_id ) )
|
||||
|
||||
for environment in ${environments[@]}; do
|
||||
|
||||
while read site_configs; do if [[ $site_configs == "" ]]; then continue; fi; declare "$site_configs"; done <<< "$(captaincore site get $site-$environment --bash --captain_id=$captain_id)"
|
||||
|
||||
rclone config delete sftp-${site_name}-${environment}
|
||||
|
||||
if [[ "$key" != "use_password" ]]; then
|
||||
if [[ $key == "" ]]; then
|
||||
key=$( captaincore configuration get --field=default_key )
|
||||
fi
|
||||
ssh_file="$path_keys/${captain_id}/${key}"
|
||||
echo "Generating rclone configs for ${site}-${environment} with SSH key"
|
||||
quiet=$( rclone config create sftp-${site_name}-${environment} $protocol host $address user $username port $port key_file $ssh_file )
|
||||
fi
|
||||
|
||||
if [[ "$key" == "use_password" ]]; then
|
||||
password=$(captaincore site get ${site}-${environment} --field=password --captain_id=$captain_id)
|
||||
rclone_pass=$(rclone obscure $password)
|
||||
echo "Generating rclone configs for ${site}-${environment} with password"
|
||||
quiet=$( rclone config create sftp-${site_name}-${environment} $protocol host $address user $username port $port pass -- $rclone_pass )
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
}
|
||||
run_command
|
|
@ -1 +0,0 @@
|
|||
<site>
|
|
@ -1,40 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Flag site with SSH failure.
|
||||
#
|
||||
# `captaincore site ssh-fail <site>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
run_command() {
|
||||
|
||||
site=$1
|
||||
|
||||
# Remove leading "--" from flags
|
||||
for i in "${!flags[@]}"; do
|
||||
flags[$i]=`echo ${flags[$i]} | cut -c 3-`
|
||||
done
|
||||
|
||||
cd ${root_path}data
|
||||
|
||||
# Extract environment
|
||||
if [[ "$website" == *"-staging"* ]]; then
|
||||
environment=staging
|
||||
else
|
||||
environment=production
|
||||
fi
|
||||
|
||||
# Load site configs
|
||||
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain_id=$captain_id)"
|
||||
|
||||
if [[ "$protocol" == "sftp" ]]; then
|
||||
echo "SSH failed $site"
|
||||
wp eval-file ../lib/local-scripts/site-ssh-failed.php site=$site environment=$environment ${flags[@]}
|
||||
fi
|
||||
|
||||
}
|
||||
run_command ${arguments[*]}
|
|
@ -1,15 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Generates Fathom Tracker
|
||||
#
|
||||
# `captaincore stats-generate <site>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
cd ${root_path}data
|
||||
|
||||
wp eval-file ${root_path}lib/local-scripts/stats-generate.php site=$1 captain_id=$captain_id
|
|
@ -6,50 +6,37 @@
|
|||
# `captaincore site sync <site_id>`
|
||||
#
|
||||
# [--update-extras]
|
||||
#
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
# Error if no sites specifed
|
||||
if [ ${#@} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a site."
|
||||
exit
|
||||
fi
|
||||
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
site_id=$1
|
||||
|
||||
run_command() {
|
||||
|
||||
site_id=$1
|
||||
|
||||
# Remove leading "--" from flags
|
||||
for i in "${!flags[@]}"; do
|
||||
flags[$i]=`echo ${flags[$i]} | cut -c 3-`
|
||||
done
|
||||
|
||||
cd ${root_path}data
|
||||
wp eval-file ../lib/local-scripts/site-sync.php site_id=$site_id ${flags[@]}
|
||||
cd ${CAPTAINCORE_PATH}/data
|
||||
wp eval-file ../lib/local-scripts/site-sync.php site_id=$site_id
|
||||
|
||||
# Generate rclone keys
|
||||
captaincore site rclone-configs $site_id --captain_id=$captain_id
|
||||
|
||||
if [ "$update_extras" ]; then
|
||||
|
||||
# Prepare site
|
||||
captaincore site prepare $site_id --captain_id=$captain_id
|
||||
|
||||
# Deploy global defaults
|
||||
captaincore site deploy-defaults ${site_id}-production --global-only
|
||||
|
||||
# Capture screenshot
|
||||
captaincore capture ${site_id}-production
|
||||
captaincore site key-generate $site_id --captain-id=$CAPTAIN_ID
|
||||
|
||||
if [ "$CAPTAINCORE_UPDATE_EXTRAS" ]; then
|
||||
captaincore site prepare $site_id --captain-id=$CAPTAIN_ID
|
||||
captaincore site deploy-defaults ${site_id}-production --global-only --captain-id=$CAPTAIN_ID
|
||||
captaincore capture ${site_id}-production --captain-id=$CAPTAIN_ID
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -eq 1 ]; then
|
||||
# Runs on specifed sites
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#arguments[*]} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a site."
|
||||
fi
|
||||
run_command
|
87
app/size
87
app/size
|
@ -3,83 +3,50 @@
|
|||
#
|
||||
# Calculates size of one or more sites.
|
||||
#
|
||||
# `captaincore size`
|
||||
# `captaincore size <site>`
|
||||
#
|
||||
# [<site>...]
|
||||
# One or more sites.
|
||||
#
|
||||
# [@<target>]
|
||||
# Target groups of sites like @all @production or @staging.
|
||||
#
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
run_command() {
|
||||
|
||||
INDEX=1
|
||||
for site in "$@"; do
|
||||
site=$@
|
||||
|
||||
# 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)"
|
||||
# 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)"
|
||||
|
||||
if [ -z "$domain" ]; then
|
||||
echo "Domain not found"
|
||||
return
|
||||
fi
|
||||
if [ -z "$domain" ]; then
|
||||
echo "Domain not found"
|
||||
return
|
||||
fi
|
||||
|
||||
# Define Rclone site name
|
||||
rclone_site_name=${captain_id}-${site}
|
||||
# Define Rclone site name
|
||||
rclone_site_name=${captain_id}-${site}
|
||||
|
||||
if [ "$home_directory" != "" ]; then
|
||||
home_directory="${home_directory}/"
|
||||
fi
|
||||
|
||||
json="["
|
||||
size_production=$(rclone size sftp-${rclone_site_name}-production:$home_directory --json)
|
||||
size_staging=$(rclone size sftp-${rclone_site_name}-staging:$home_directory --json)
|
||||
json+="{\"name\":\"$site\","${size_production:1:${#size_production}}
|
||||
if [[ "$size_staging" != "" ]]; then
|
||||
json+=","
|
||||
fi
|
||||
json+="{\"name\":\"$site-staging\","${size_staging:1:${#size_staging}}
|
||||
json+="]"
|
||||
if [ "$home_directory" != "" ]; then
|
||||
home_directory="${home_directory}/"
|
||||
fi
|
||||
|
||||
echo $json
|
||||
json="["
|
||||
size_production=$(rclone size sftp-${rclone_site_name}-production:$home_directory --json)
|
||||
size_staging=$(rclone size sftp-${rclone_site_name}-staging:$home_directory --json)
|
||||
json+="{\"name\":\"$site\","${size_production:1:${#size_production}}
|
||||
if [[ "$size_staging" != "" ]]; then
|
||||
json+=","
|
||||
fi
|
||||
json+="{\"name\":\"$site-staging\","${size_staging:1:${#size_staging}}
|
||||
json+="]"
|
||||
|
||||
# Clear out variables
|
||||
domain=''
|
||||
username=''
|
||||
password=''
|
||||
address=''
|
||||
protocol=''
|
||||
port=''
|
||||
home_directory=''
|
||||
remoteserver=''
|
||||
s3bucket=''
|
||||
s3path=''
|
||||
subsite=''
|
||||
echo $json
|
||||
|
||||
let INDEX=${INDEX}+1
|
||||
|
||||
done
|
||||
let INDEX=${INDEX}+1
|
||||
|
||||
}
|
||||
|
||||
# See if any sites are specifed
|
||||
if [ ${#arguments[*]} -gt 0 ]; then
|
||||
if [ ${#arguments[*]} -eq 1 ]; then
|
||||
# Runs on specifed sites
|
||||
run_command ${arguments[*]}
|
||||
exit
|
||||
fi
|
||||
|
||||
# Runs on targeted sites
|
||||
if [ ${#targets[*]} -gt 0 ]; then
|
||||
run_command $(captaincore site list ${targets[*]/targets=/@} --captain_id=$captain_id)
|
||||
fi
|
||||
|
||||
# Error if no sites specifed
|
||||
if [ ${#targets[*]} -eq 0 ] && [ ${#arguments[*]} -eq 0 ]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify one or more sites, or use a target @all, @production or @staging."
|
||||
fi
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a <site>."
|
|
@ -1 +0,0 @@
|
|||
Calculates size of one or more sites.
|
180
app/ssh
180
app/ssh
|
@ -26,175 +26,31 @@
|
|||
# [--debug]
|
||||
# Outputs SSH command for debug purposes
|
||||
#
|
||||
read -r -d '' php_code << heredoc
|
||||
\$arguments = <<<PHPHEREDOC
|
||||
$@
|
||||
PHPHEREDOC;
|
||||
echo base64_encode( \$arguments );
|
||||
heredoc
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
arguments=$( php -r "$php_code" )
|
||||
|
||||
run_command() {
|
||||
|
||||
site=$1
|
||||
before_ssh=""
|
||||
|
||||
# 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)"
|
||||
|
||||
if [ -f "${path}/process-${process_id}-progress.log" ]; then
|
||||
echo -n "." >> ${path}/process-${process_id}-progress.log
|
||||
fi
|
||||
|
||||
if [[ "$address" == "" && "$captaincore_master" != "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Site $site not found."
|
||||
exit
|
||||
fi
|
||||
|
||||
if [[ "$protocol" != "sftp" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} SSH not supported (Protocol is $protocol)."
|
||||
exit
|
||||
fi
|
||||
|
||||
if [[ "$provider" == "kinsta" && "$address" == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Missing Kinsta site."
|
||||
exit
|
||||
fi
|
||||
|
||||
if [[ "$provider" == "wpengine" && "$environment" == "staging" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Missing WP Engine site."
|
||||
exit
|
||||
fi
|
||||
|
||||
if [[ "$environment_vars" != "" ]]; then
|
||||
environment_vars="$environment_vars &&"
|
||||
fi
|
||||
|
||||
remote_options="-oStrictHostKeyChecking=no"
|
||||
|
||||
if [[ $key != 'use_password' ]]; then
|
||||
remote_options="$remote_options -oPreferredAuthentications=publickey"
|
||||
fi
|
||||
if [[ $key != 'use_password' ]]; then
|
||||
if [[ $key == "" ]]; then
|
||||
key=$( captaincore configuration get --field=default_key )
|
||||
fi
|
||||
remote_options="$remote_options -i $path_keys/${captain_id}/${key}"
|
||||
fi
|
||||
if [[ $key == 'use_password' ]]; then
|
||||
before_ssh="sshpass -p '$(captaincore site get $site --captain_id=$captain_id --field=password)'"
|
||||
fi
|
||||
|
||||
# If website on Kinsta then prepare their format
|
||||
if [[ "$provider" == "kinsta" ]]; then
|
||||
|
||||
# Kinsta's command prep
|
||||
command_prep="$environment_vars cd public/ &&"
|
||||
remote_server="$remote_options $username@$address -p $port"
|
||||
|
||||
if [[ "$use_staging" == "true" ]]; then
|
||||
remote_server="$remote_options $username_staging@$address_staging -p $port_staging"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# If website on WP Engine then prepare their format
|
||||
if [[ "$provider" == "wpengine" ]]; then
|
||||
|
||||
command_prep="$environment_vars rm ~/.wp-cli/config.yml; cd sites/* &&"
|
||||
remote_server="$remote_options ${site}@${site}.ssh.wpengine.net"
|
||||
|
||||
if [[ "$use_staging" == "true" ]]; then
|
||||
remote_server="$remote_options ${site_staging}@${site_staging}.ssh.wpengine.net"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
if [[ "$remote_server" == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} $domain website host provider not recognized."
|
||||
exit
|
||||
fi
|
||||
|
||||
if [[ "$command_prep" == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} $domain website host provider not recognized."
|
||||
exit
|
||||
|
||||
fi
|
||||
|
||||
# Runs ssh with recipe
|
||||
if [[ "$recipe" != "" ]]; then
|
||||
recipe_file="$path_recipes/${captain_id}-${recipe}.sh"
|
||||
# Check for file
|
||||
if [ -f "$recipe_file" ]; then
|
||||
# Pass all arguments found after --script=<script> argument into remote script
|
||||
$before_ssh ssh $remote_server "$command_prep bash -s -- --site=$site ${flags[@]}" < $recipe_file || captaincore site ssh-fail $site --captain_id=$captain_id
|
||||
fi
|
||||
exit
|
||||
fi
|
||||
|
||||
# Runs ssh with script
|
||||
if [ -n "$script" ]; then
|
||||
# Check for file
|
||||
if [ -f "$script" ]; then
|
||||
# Pass all arguments found after --script=<script> argument into remote script
|
||||
$before_ssh ssh $remote_server "$command_prep bash -s -- --site=$site ${flags[@]}" < $script || captaincore site ssh-fail $site --captain_id=$captain_id
|
||||
exit
|
||||
fi
|
||||
|
||||
# Not found so attempt to run a local script
|
||||
script_file=${root_path}lib/remote-scripts/$script
|
||||
if [ ! -f "$script_file" ]; then
|
||||
echo "Error: Can't locate script $script"
|
||||
exit
|
||||
fi
|
||||
|
||||
$before_ssh ssh $remote_server "$command_prep bash -s -- --site=$site ${flags[@]}" < $script_file || captaincore site ssh-fail $site --captain_id=$captain_id
|
||||
exit
|
||||
|
||||
fi
|
||||
|
||||
# Runs ssh with command
|
||||
if [ -n "$command" ]; then
|
||||
$before_ssh ssh $remote_server "$command_prep $command" || captaincore site ssh-fail $site --captain_id=$captain_id
|
||||
exit
|
||||
fi
|
||||
|
||||
if [[ "$direct" == "true" ]]; then
|
||||
$before_ssh ssh -T $remote_server || captaincore site ssh-fail $site --captain_id=$captain_id
|
||||
exit
|
||||
fi
|
||||
|
||||
if [[ "$debug" == "true" ]]; then
|
||||
echo "$before_ssh ssh $remote_server"
|
||||
fi
|
||||
|
||||
# Runs ssh
|
||||
$before_ssh ssh $remote_server
|
||||
|
||||
}
|
||||
|
||||
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."
|
||||
if [[ "$1" == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Requires a <site>."
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ ${#arguments[*]} -eq 1 ] && [ ${#targets[*]} -eq 0 ]; then
|
||||
run_command ${arguments[*]}
|
||||
fi
|
||||
cd "$HOME/.captaincore/data"
|
||||
|
||||
if [ ${#arguments[*]} -gt 1 ] && [ ${#targets[*]} -eq 0 ] && [[ "$command" == "" ]] && [[ "$script" == "" ]] && [[ "$recipe" == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} For bulk sites please specify a [--command=<command>], [--script=<script>] or [--recipe=<recipe>]."
|
||||
if [[ "$CAPTAINCORE_DEBUG" == "true" ]]; then
|
||||
wp eval-file ../lib/local-scripts/ssh.php arguments=$arguments
|
||||
echo ""
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ ${#arguments[*]} -gt 1 ] && [ ${#targets[*]} -eq 0 ]; then
|
||||
captaincore bulk ssh ${arguments[*]} "${flags[@]}" --captain_id=$captain_id
|
||||
run_ssh=$( wp eval-file ../lib/local-scripts/ssh.php arguments=$arguments )
|
||||
if [[ "$run_ssh" == *"Error:"* ]]; then
|
||||
echo $run_ssh
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ ${#targets[*]} -gt 0 ] && [ ${#arguments[*]} -eq 0 ]; then
|
||||
captaincore bulk ssh ${targets[*]/targets=/@} "${flags[@]}" --captain_id=$captain_id
|
||||
fi
|
||||
eval $run_ssh
|
|
@ -1 +0,0 @@
|
|||
SSH connection to one or more sites.
|
|
@ -1 +0,0 @@
|
|||
<site>... [--command=<commands>] [--script=<name|file>] [--<script-argument-name>=<script-argument-value>]
|
26
app/stats
26
app/stats
|
@ -1,26 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Stats (Supports WordPress.com stats and selfhosted Fathom Analytics)
|
||||
#
|
||||
# `captaincore stats <site>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
run_command() {
|
||||
|
||||
site=$1
|
||||
|
||||
if [[ "$site" == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a <site>."
|
||||
return
|
||||
fi
|
||||
|
||||
cd ${root_path}data
|
||||
wp eval-file ../lib/local-scripts/site-stats-fetch.php site=$site captain_id=$captain_id
|
||||
|
||||
}
|
||||
run_command ${arguments[*]}
|
|
@ -1,78 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Generates and deploys Fathom tracker
|
||||
#
|
||||
# `captaincore stats-deploy <site> <fathom-site-id>`
|
||||
#
|
||||
# For multisite networks mutiple tracking codes can be WordPress passed in the following JSON format
|
||||
# '[{"domain":"site123.com","code":"ABCDE"},{"domain":"site346.com","code":"ABCDF"}]'
|
||||
#
|
||||
# [--debug]
|
||||
# Debug mode
|
||||
#
|
||||
|
||||
# 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)"
|
||||
|
||||
code=$( echo $2 | sed "s/'//g" )
|
||||
|
||||
if [[ $site == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a site."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ $code == "" ]]; then
|
||||
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a fathom site id."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ $tracker == "" ]]; then
|
||||
tracker=$captaincore_tracker
|
||||
fi
|
||||
|
||||
# Workaround inconstancy when passing JSON as an argument with WPE. Use Base64 to preserve line breaks through SSH as argument.
|
||||
fathom_arguments="tracker=$tracker\n id=$code\n branding_author=$captaincore_branding_author\n branding_author_uri=$captaincore_branding_author_uri\n branding_slug=$captaincore_branding_slug"
|
||||
|
||||
read -r -d '' php_code << heredoc
|
||||
\$arguments = <<<PHPHEREDOC
|
||||
$fathom_arguments
|
||||
PHPHEREDOC;
|
||||
|
||||
echo base64_encode( \$arguments );
|
||||
heredoc
|
||||
|
||||
fathom_arguments=$( php -r "$php_code" )
|
||||
|
||||
if [[ "$debug" == "true" ]]; then
|
||||
echo "captaincore ssh $site-$environment --script=deploy-fathom --wp_content=$wp_content --fathom_arguments="$fathom_arguments" --captain_id=$captain_id"
|
||||
return 1
|
||||
fi
|
||||
|
||||
captaincore ssh $site-$environment --script=deploy-fathom --wp_content=$wp_content --fathom_arguments="$fathom_arguments" --captain_id=$captain_id
|
||||
|
||||
# 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)"
|
||||
|
||||
cd ${root_path}data
|
||||
|
||||
# Store updated info in WordPress datastore
|
||||
wp eval-file ../lib/local-scripts/site-update-fathom.php site=$site environment=$environment code=$2
|
||||
|
||||
}
|
||||
run_command ${arguments[*]}
|
|
@ -1 +0,0 @@
|
|||
Generates and deploys Fathom tracker to a single site.
|
|
@ -1 +0,0 @@
|
|||
Shows last 12 months of visitors.
|
|
@ -1 +0,0 @@
|
|||
<site>
|
|
@ -6,12 +6,15 @@
|
|||
# `captaincore store-snapshot <url|file>`
|
||||
#
|
||||
|
||||
# Load configuration
|
||||
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
||||
source ${root_path}lib/arguments
|
||||
|
||||
zip=$1
|
||||
|
||||
while read config; do
|
||||
if [[ "$config" == "Error:"* ]]; then
|
||||
continue
|
||||
fi
|
||||
declare "$config"
|
||||
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
||||
|
||||
run_command() {
|
||||
|
||||
if [ -e $zip ]; then
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Moves zip to rclone remote for cold storage.
|
|
@ -1 +0,0 @@
|
|||
<url|file>
|
|
@ -1 +0,0 @@
|
|||
Sync website data for one or more sites.
|
|
@ -1 +0,0 @@
|
|||
[<site>...] [@<target>]
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue