Postman for L2GW and L2GWConnection
[netvirt.git] / resources / openstack / sethostname.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2013 Cisco Systems, Inc.
4 #
5 # This program and the accompanying materials are made available under the
6 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 # and is available at http://www.eclipse.org/legal/epl-v10.html
8 #
9 # Authors : Thomas Bachman
10
11 #
12 #  Set the hostname
13 #
14 currname=`cat /etc/hostname`
15 echo "Current hostname: $currname"
16
17 echo -n "Enter new hostname: "
18 read -a newname
19
20 #
21 # Update /etc/hosts & /etc/hostname with new hostname
22 #
23 if [ "$newname" != "$currname" ]; then
24     res=`sed -i "s/$currname/$newname/g" /etc/hosts`
25     if [ $? -ne 0 ]; then
26         echo "failed to update /etc/hosts"
27     fi
28     res=`sed -i "s/$currname/$newname/g" /etc/hostname`
29     if [ $? -ne 0 ]; then
30         echo "failed to update /etc/hostname"
31     fi
32     res=`hostname $newname`
33     if [ $? -ne 0 ]; then
34         echo "failed to update hostname"
35     else
36         echo "Your new hostname is $newname"
37     fi
38 else
39     echo "hostname already set to $newname"
40 fi