Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 115 lines (88 sloc) 2.521 kb
fb6e967 Initial import of code into subversion.
pdibowitz authored
1 #!/usr/bin/perl -w
2
3 # -*- mode: perl; cperl-continued-brace-offset: -4; indent-tabs-mode: nil; -*-
4 # vim:shiftwidth=2:tabstop=8:expandtab:textwidth=78:softtabstop=4:ai:
5
9d7a17c Properly set svn:keywords
pdibowitz authored
6 # $Id$
fb6e967 Initial import of code into subversion.
pdibowitz authored
7
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #
21 # (C) Copyright Ticketmaster, Inc. 2007
22 #
23
24 use strict;
25
47903a1 Subject: Rename spine to spine-mgmt
cfb authored
26 use lib qw(/usr/lib/spine-mgmt);
fb6e967 Initial import of code into subversion.
pdibowitz authored
27
28 use Getopt::Long;
29 use Spine::Util;
30
31 my %options;
32 GetOptions(
33 \%options,
34 'hostname=s'
35 );
36
37 my $cmdline_hostname = $options{hostname};
38
39 my $DIALOG = qq(/usr/bin/dialog);
40 my $VMCMD = qq(/usr/local/vmware-tools/sbin/vmware-guestd);
41
42 while (1)
43 {
44 my $hostname = get_hostname();
45 my $pass_regex = check_hostname($hostname);
46 my $does_resolve = Spine::Util::resolve_address($hostname);
47
48 unless ($pass_regex)
49 {
50 msgbox_error("Invalid hostname format \[$hostname\]");
51 next;
52 }
53
54 unless ($does_resolve)
55 {
56 msgbox_error("Could not resolve \[$hostname\]");
57 next;
58 }
59
60 print "NEWHOSTNAME=" . $hostname . "\n";
61 last;
62 }
63
64
65 sub get_hostname
66 {
67
68 my $hostname;
69 my $dialogcmd = "$DIALOG --stdout --nocancel "
70 . "--inputbox \"Hostname\" 9 55";
71
72 # Try three different methods for determining the hostname:
73 # user supplied via command line, whether we are a VM
74 # in which case we ask the host server, or prompt the
75 # user via dialog box.
76
fbb6687 Should fix issue 36
rtilder authored
77 open(LSPCI, "/sbin/lspci |");
fb6e967 Initial import of code into subversion.
pdibowitz authored
78 if ($cmdline_hostname)
79 {
80 $hostname = $cmdline_hostname;
81 $cmdline_hostname = undef;
82 }
fbb6687 Should fix issue 36
rtilder authored
83 elsif ( grep(/VMware Inc/i, <LSPCI>) && (-x "$VMCMD") )
fb6e967 Initial import of code into subversion.
pdibowitz authored
84 {
85 $hostname = `$VMCMD --cmd machine.id.get 2>/dev/null`;
86 if ($? > 0 ) { $hostname = `$dialogcmd`; }
87 }
88
89 else
90 {
91 $hostname = `$dialogcmd`;
92 }
93
94 $hostname = lc($hostname);
95
fbb6687 Should fix issue 36
rtilder authored
96 close(LSPCI);
fb6e967 Initial import of code into subversion.
pdibowitz authored
97 return $hostname;
98 }
99
100
101 sub check_hostname
102 {
e50f74e A hardcoded dns_schema has irritated me for the last time
rtilder authored
103 return 1;
fb6e967 Initial import of code into subversion.
pdibowitz authored
104 }
105
106
107 sub msgbox_error
108 {
109 my $errormsg = shift;
110 my $dialogcmd = "$DIALOG --stdout --msgbox \"$errormsg\" 6 55";
111
112 `$dialogcmd`;
113 return 1;
114 }
Something went wrong with that request. Please try again.