blob: 2c6f089aee17f64cc66c9dcfe4bd7584485f3333 [file] [log] [blame]
Filip Kujawa5bdc75f2023-11-26 08:35:18 -08001#!/bin/bash
2
3# This script sets up SSH configuration for tunnel forwarding so you can
4# build and deploy code without having the code locally.
5# It creates or appends to the local SSH config file (~/.ssh/config)
6# and connects to the build server to create or append the remote SSH config.
7# It prompts the user for their SSH username, the name of the local identity file,
8# and the name of the remote identity file.
9
10# Instructions:
11# 1. Run this script locally on your machine.
12# 2. Make the script executable: chmod +x setup_ssh_configs.sh
13# 3. Run the script: ./setup_ssh_configs.sh
14
15# Note: Ensure that the local and remote SSH config template files are
16# in the same directory as this script.
17
18# TODO: Use jinja for better templating
19# TODO: Use python to also support windows devices.
20
21# Get the script's directory
22script_dir=$(dirname "$(realpath "$0")")
23
24# Prompt for user input
25read -p "Enter your username for SSH connection: " username
26read -p "Enter the name of the local identity file (e.g., id_971_ed25519): " local_identity_file
27read -p "Enter the name of the remote identity file (e.g., id_971_ed25519): " remote_identity_file
28
29local_ssh_config_template="$script_dir/local_config_template.txt"
30remote_ssh_config_template="$script_dir/remote_config_template.txt"
31
32
33local_ssh_config_content=$(cat "$local_ssh_config_template" | sed -e "s/{{username}}/$username/g" -e "s/{{identity_file}}/$local_identity_file/g")
34local_ssh_config="$HOME/.ssh/config"
35
36# Check if the local SSH config file already exists
37if [ -f "$local_ssh_config" ]; then
38 # Append
39 echo "$local_ssh_config_content" >> "$local_ssh_config"
40else
41 echo "$local_ssh_config_content" > "$local_ssh_config"
42 chmod 600 "$local_ssh_config"
43fi
44
45remote_ssh_config_content=$(cat "$remote_ssh_config_template" | sed -e "s/{{username}}/$username/g" -e "s/{{identity_file}}/$remote_identity_file/g")
46remote_ssh_config="~/.ssh/config"
47
48ssh "frc971" "echo '$remote_ssh_config_content' >> $remote_ssh_config"
49
50echo "SSH configuration for tunnel forwarding has been set up locally and on the build server."