captaincore/app/upload
2026-03-05 18:56:33 -05:00

74 lines
2.1 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 <<< "$(captaincore config fetch --captain-id=$CAPTAIN_ID)"
site=$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
IFS=$'\n'$'\r'; for line in $(captaincore site get $site --bash --captain-id=$CAPTAIN_ID); do declare "$line"; done; unset IFS
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