File tree Expand file tree Collapse file tree 2 files changed +30
-157
lines changed Expand file tree Collapse file tree 2 files changed +30
-157
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ # This script creates two instances on Scaleway and updates the SSH config file to include them.
3+
14set -euxo pipefail
25
36INSTANCE_TYPE=" DEV1-L"
@@ -7,5 +10,31 @@ for i in $(seq 1 2); do
710 INSTANCE_NAME=" k8s-$i "
811 echo " Creating instance $INSTANCE_NAME ..."
912
10- scw instance server create zone=" fr-par-1" image=$DISTRIBUTION type=" $INSTANCE_TYPE " name=$INSTANCE_NAME
13+ scw instance server create zone=" fr-par-1" image=$DISTRIBUTION type=" $INSTANCE_TYPE " ip=" $ip_id " name=$INSTANCE_NAME
14+ instance_id=$( scw instance server list | grep $INSTANCE_NAME | awk ' {print $1}' )
15+ ip_address=$( scw instance server wait " $instance_id " | grep PublicIP.Address | awk ' {print $2}' )
16+
17+ CONFIG=~ /.ssh/config
18+ HOST_ENTRY=" Host $INSTANCE_NAME "
19+ HOSTNAME_LINE=" HostName $ip_address "
20+ USER_LINE=" User ubuntu"
21+
22+ # Update ~/.ssh/config to add the new instance
23+ if grep -q " ^Host $INSTANCE_NAME \$ " " $CONFIG " ; then
24+ # Update HostName line for existing Host entry
25+ awk -v host=" $INSTANCE_NAME " -v hostname=" $HOSTNAME_LINE " '
26+ $0 == "Host "host {print; inhost=1; next}
27+ inhost && $1 == "HostName" {$0=hostname; inhost=0}
28+ {print}
29+ ' " $CONFIG " > " $CONFIG .tmp" && mv " $CONFIG .tmp" " $CONFIG "
30+ else
31+ # Add new Host entry
32+ {
33+ echo " $HOST_ENTRY "
34+ echo " $HOSTNAME_LINE "
35+ echo " $USER_LINE "
36+ } >> " $CONFIG "
37+ fi
38+
39+ echo " Updated ~/.ssh/config for $INSTANCE_NAME "
1140done
You can’t perform that action at this time.
0 commit comments