-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup-backend.sh
executable file
·49 lines (38 loc) · 2.14 KB
/
setup-backend.sh
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
#!/bin/bash
# setup-backend.sh
# HS-Fulda - sebastian.rieger@informatik.hs-fulda.de
#
# changelog:
# V0.1 initial version
# V0.2 fixed ssh-copy-id parameter to work with Ubuntu 16.04 (GNS3 2.1) and Ubuntu 18.04 (GNS3 2.2)
# usage
if [ ! $# -eq 2 ] ; then
echo -e "usage: $0 <gns3 proxy config file> <ip address of backend to configure>, e.g.:\n"
echo "$0 ./gns3_proxy_config.ini 192.168.0.100"
exit -1
fi
GNS3_PROXY_CONFIG_FILE=$1
BACKEND_IP_ADDRESS=$2
BACKEND_USERNAME=$(cat $GNS3_PROXY_CONFIG_FILE | grep backend_user | cut -d "=" -f 2)
BACKEND_PASSWORD=$(cat $GNS3_PROXY_CONFIG_FILE | grep backend_password | cut -d "=" -f 2)
BACKEND_PORT=$(cat $GNS3_PROXY_CONFIG_FILE | grep backend_port | cut -d "=" -f 2)
if [ ! -f "config-templates/gns3_server.conf" ]; then
echo "ERROR: no config-templates found! Make sure that config-templates/gns3_server.conf from gns3_proxy repository is available in current working directory."
exit -1
fi
if [ ! -f "$HOME/.ssh/id_rsa" ]; then
echo "Current user has no ssh key. Creating ssh key in ~/.ssh/id_rsa"
ssh-keygen -q -f $HOME/.ssh/id_rsa -N ""
fi
echo "Copying ssh pub key to new backend server..."
echo "User username gns3 to login to the backend server at $BACKEND_IP_ADDRESS, please enter the password of this user on the backend (default: gns3)."
ssh-copy-id gns3@$BACKEND_IP_ADDRESS
# modify and copy gns3_server.conf template
sed s/"<BACKEND_IP_ADDRESS>"/"$BACKEND_IP_ADDRESS"/g config-templates/gns3_server.conf >config-templates/gns3_server.conf.$BACKEND_IP_ADDRESS
sed -i s/"<BACKEND_PORT>"/"$BACKEND_PORT"/g config-templates/gns3_server.conf.$BACKEND_IP_ADDRESS
sed -i s/"<BACKEND_USERNAME>"/"$BACKEND_USERNAME"/g config-templates/gns3_server.conf.$BACKEND_IP_ADDRESS
sed -i s/"<BACKEND_PASSWORD>"/"$BACKEND_PASSWORD"/g config-templates/gns3_server.conf.$BACKEND_IP_ADDRESS
ssh gns3@$BACKEND_IP_ADDRESS cp -a /home/gns3/.config/GNS3/2.2/gns3_server.conf /home/gns3/.config/GNS3/2.2/gns3_server.conf.bak
scp config-templates/gns3_server.conf.$BACKEND_IP_ADDRESS gns3@$BACKEND_IP_ADDRESS:/home/gns3/.config/GNS3/2.2/gns3_server.conf
# restart gns3 done
ssh gns3@$BACKEND_IP_ADDRESS sudo service gns3 restart