captaincore/app/upload
2024-01-17 18:34:56 -05:00

74 lines
2.2 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# Uploads file to site over ssh
#
# `captaincore upload <site> <file>`
#
# [--public]
# Uploads to public. Defaults to private folder.
#
while read config; do
if [[ "$config" == "Error:"* ]]; then
continue
fi
declare "$config"
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
website=$1
remote_options=""
default_key=$( captaincore configuration get --field=default_key --captain-id=$CAPTAIN_ID )
remote_options="-oIdentityFile=$path_keys/${CAPTAIN_ID}/${default_key}"
# Load site configs
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $website --bash --captain-id=$CAPTAIN_ID)"
if [[ $key != "" ]]; then
remote_options="-oIdentityFile=$path_keys/${CAPTAIN_ID}/${key}"
fi
# Site found, start the backup
if ! [ -z "$domain" ]; then
## If website on Kinsta then connect SSH using their format
if [[ "$provider" == "kinsta" ]]; then
if [ -n "$2" ]; then
if [[ "$FLAG_PUBLIC" == "true" ]]; then
scp $remote_options -o StrictHostKeyChecking=no -P $port $2 $username@$address:public/
else
scp $remote_options -o StrictHostKeyChecking=no -P $port $2 $username@$address:private/
fi
else
echo 'Missing argument. Ex: captaincore upload sitename1 "~/Download/migration.zip'
fi
else ## If not Kinsta then try connecting using WP Engine's format
echo "Uploading..."
if [ -n "$2" ]; then
if [[ "$FLAG_PUBLIC" == "true" ]]; then
scp $remote_options -o StrictHostKeyChecking=no -P 22 "$2" $1@$1.ssh.wpengine.net:sites/$1/
else
scp $remote_options -o StrictHostKeyChecking=no -P 22 "$2" $1@$1.ssh.wpengine.net:sites/$1/_wpeprivate/
fi
else
echo 'Missing argument. Ex: captaincore upload sitename1 "~/Download/migration.zip'
fi
fi
else ## not recognized so attempt WP Engine's format
if [ -n "$2" ]; then
if [[ "$FLAG_PUBLIC" == "true" ]]; then
scp $remote_options -o StrictHostKeyChecking=no -P 22 $2 $1@$1.ssh.wpengine.net:sites/$1/
else
scp $remote_options -o StrictHostKeyChecking=no -P 22 $2 $1@$1.ssh.wpengine.net:sites/$1/_wpeprivate/
fi
else
echo 'Missing argument. Ex: captaincore upload sitename1 "~/Download/migration.zip'
fi
fi