Spaces:
No application file
No application file
Jacob Molnia
commited on
Commit
•
4394adb
1
Parent(s):
1ee9b02
controller test2
Browse files
deployment/02_deploy_to_controller/scripts/initial_ssh_config.sh
CHANGED
@@ -26,19 +26,22 @@ if [ -z "$TAILSCALE_KEY" ]; then
|
|
26 |
usage
|
27 |
fi
|
28 |
|
|
|
|
|
|
|
29 |
# Function to test SSH connection
|
30 |
test_ssh_connection() {
|
31 |
-
ssh -o BatchMode=yes -o ConnectTimeout=5 -J turing.wpi.edu app echo "SSH connection successful" >/dev/null 2>&1
|
32 |
}
|
33 |
|
34 |
# Backup the existing authorized_keys file
|
35 |
-
ssh -i /opt/CS_553/keys/student-admin-key -J turing.wpi.edu app <<EOF || handle_error "Failed to backup authorized_keys"
|
36 |
cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys.bak || handle_error "Failed to create backup of authorized_keys"
|
37 |
echo "Backup of authorized_keys created"
|
38 |
EOF
|
39 |
|
40 |
# Update authorized_keys file with the new key while keeping existing keys
|
41 |
-
ssh -i /opt/CS_553/keys/student-admin-key -J turing.wpi.edu app <<EOF || handle_error "Failed to update authorized_keys"
|
42 |
NEW_KEY="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIARTYgwoPW+VpBofWGYuHIldh18EUo42PHF/e08Dzcyp admin key CS553"
|
43 |
if ! grep -q "\$NEW_KEY" ~/.ssh/authorized_keys; then
|
44 |
echo "\$NEW_KEY" >> ~/.ssh/authorized_keys || handle_error "Failed to append new key to authorized_keys"
|
@@ -52,7 +55,7 @@ if test_ssh_connection; then
|
|
52 |
echo "SSH connection with new key successful"
|
53 |
else
|
54 |
echo "SSH connection with new key failed. Restoring backup..."
|
55 |
-
ssh -i /opt/CS_553/keys/student-admin-key -J turing.wpi.edu app <<EOF || handle_error "Failed to restore authorized_keys backup"
|
56 |
cp ~/.ssh/authorized_keys.bak ~/.ssh/authorized_keys || handle_error "Failed to restore backup of authorized_keys"
|
57 |
chmod 600 ~/.ssh/authorized_keys || handle_error "Failed to set permissions on restored authorized_keys"
|
58 |
echo "Backup of authorized_keys restored"
|
@@ -61,9 +64,14 @@ EOF
|
|
61 |
fi
|
62 |
|
63 |
# Install Tailscale and set up with provided key
|
64 |
-
ssh -J turing.wpi.edu app <<EOF || handle_error "Failed to set up Tailscale"
|
65 |
-
#
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
# Run Tailscale with the provided auth key
|
69 |
sudo tailscale up --authkey "$TAILSCALE_KEY" || handle_error "Failed to run Tailscale"
|
|
|
26 |
usage
|
27 |
fi
|
28 |
|
29 |
+
# SSH options to avoid known hosts issues and prompts
|
30 |
+
SSH_OPTIONS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR"
|
31 |
+
|
32 |
# Function to test SSH connection
|
33 |
test_ssh_connection() {
|
34 |
+
ssh $SSH_OPTIONS -o BatchMode=yes -o ConnectTimeout=5 -J turing.wpi.edu student-admin@app echo "SSH connection successful" >/dev/null 2>&1
|
35 |
}
|
36 |
|
37 |
# Backup the existing authorized_keys file
|
38 |
+
ssh $SSH_OPTIONS -i /opt/CS_553/keys/student-admin-key -J turing.wpi.edu student-admin@app <<EOF || handle_error "Failed to backup authorized_keys"
|
39 |
cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys.bak || handle_error "Failed to create backup of authorized_keys"
|
40 |
echo "Backup of authorized_keys created"
|
41 |
EOF
|
42 |
|
43 |
# Update authorized_keys file with the new key while keeping existing keys
|
44 |
+
ssh $SSH_OPTIONS -i /opt/CS_553/keys/student-admin-key -J turing.wpi.edu student-admin@app <<EOF || handle_error "Failed to update authorized_keys"
|
45 |
NEW_KEY="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIARTYgwoPW+VpBofWGYuHIldh18EUo42PHF/e08Dzcyp admin key CS553"
|
46 |
if ! grep -q "\$NEW_KEY" ~/.ssh/authorized_keys; then
|
47 |
echo "\$NEW_KEY" >> ~/.ssh/authorized_keys || handle_error "Failed to append new key to authorized_keys"
|
|
|
55 |
echo "SSH connection with new key successful"
|
56 |
else
|
57 |
echo "SSH connection with new key failed. Restoring backup..."
|
58 |
+
ssh $SSH_OPTIONS -i /opt/CS_553/keys/student-admin-key -J turing.wpi.edu student-admin@app <<EOF || handle_error "Failed to restore authorized_keys backup"
|
59 |
cp ~/.ssh/authorized_keys.bak ~/.ssh/authorized_keys || handle_error "Failed to restore backup of authorized_keys"
|
60 |
chmod 600 ~/.ssh/authorized_keys || handle_error "Failed to set permissions on restored authorized_keys"
|
61 |
echo "Backup of authorized_keys restored"
|
|
|
64 |
fi
|
65 |
|
66 |
# Install Tailscale and set up with provided key
|
67 |
+
ssh $SSH_OPTIONS -J turing.wpi.edu student-admin@app <<EOF || handle_error "Failed to set up Tailscale"
|
68 |
+
# Check if Tailscale is already installed
|
69 |
+
if ! command -v tailscale &> /dev/null; then
|
70 |
+
echo "Tailscale not found. Installing..."
|
71 |
+
curl -fsSL https://tailscale.com/install.sh | sudo sh || handle_error "Failed to install Tailscale"
|
72 |
+
else
|
73 |
+
echo "Tailscale is already installed."
|
74 |
+
fi
|
75 |
|
76 |
# Run Tailscale with the provided auth key
|
77 |
sudo tailscale up --authkey "$TAILSCALE_KEY" || handle_error "Failed to run Tailscale"
|