forked from IncomeStreamSurfer/wordpress-claude-code-wizard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_ssh_and_deploy.sh
More file actions
executable file
·86 lines (73 loc) · 2.36 KB
/
setup_ssh_and_deploy.sh
File metadata and controls
executable file
·86 lines (73 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# Setup SSH keys and deploy WordPress to Digital Ocean
set -e
echo "================================================"
echo "WordPress Automated Deployment Setup"
echo "================================================"
# Generate SSH key if it doesn't exist
SSH_KEY_PATH="$HOME/.ssh/wordpress_deploy"
if [ ! -f "$SSH_KEY_PATH" ]; then
echo "Generating SSH key..."
ssh-keygen -t ed25519 -f "$SSH_KEY_PATH" -N "" -C "wordpress-deploy"
echo "✅ SSH key generated at $SSH_KEY_PATH"
fi
# Read the public key
PUBLIC_KEY=$(cat "$SSH_KEY_PATH.pub")
# Add SSH key to Digital Ocean via API
echo "Adding SSH key to Digital Ocean..."
python3 << EOF
import requests
import json
import os
# Load API token
api_token = os.getenv('DO_API_TOKEN')
if not api_token:
with open('.env', 'r') as f:
for line in f:
if line.startswith('DO_API_TOKEN='):
api_token = line.split('=')[1].strip()
break
headers = {
'Authorization': f'Bearer {api_token}',
'Content-Type': 'application/json'
}
# Check if key already exists
response = requests.get('https://api.digitalocean.com/v2/account/keys', headers=headers)
ssh_keys = response.json().get('ssh_keys', [])
public_key = """$PUBLIC_KEY"""
key_name = "wordpress-deploy-key"
# Find existing key
key_id = None
for key in ssh_keys:
if key['name'] == key_name:
key_id = key['id']
print(f"SSH key already exists with ID: {key_id}")
break
# Add key if it doesn't exist
if not key_id:
data = {
'name': key_name,
'public_key': public_key
}
response = requests.post('https://api.digitalocean.com/v2/account/keys', headers=headers, json=data)
if response.status_code == 201:
key_id = response.json()['ssh_key']['id']
print(f"✅ SSH key added with ID: {key_id}")
else:
print(f"❌ Failed to add SSH key: {response.text}")
exit(1)
# Save key ID
with open('.ssh_key_id', 'w') as f:
f.write(str(key_id))
EOF
echo ""
echo "================================================"
echo "SSH Setup Complete!"
echo "================================================"
echo ""
echo "Now you can create droplets with SSH access:"
echo "1. Run: python3 create_droplet_with_ssh.py"
echo "2. The droplet will have your SSH key pre-installed"
echo "3. Migration will work automatically"
echo ""
echo "SSH Key: $SSH_KEY_PATH"