3 # Read the list of operating systems and ask the user to choose
5 # auto param: 0 = always ask user
6 # 1 = automatic, give up if fails
7 # 2 = automatic, ask user if fails
8 # 3 = automatic, ask user if fails and if a TTY
12 ($oslist, $out, $auto) = @ARGV;
13 open(OS, $oslist) || die "failed to open $oslist : $!";
16 if (/^([^\t]+)\t+([^\t]+)\t+([^\t]+)\t+([^\t]+)\t*(.*)$/) {
17 push(@list, [ $1, $2, $3, $4, $5 ]);
18 push(@names, $1) if (!$donename{$1}++);
19 $names_to_real{$1} ||= $3;
25 # Try to guess the OS name and version
26 if (-r "/etc/.issue") {
27 $etc_issue = `cat /etc/.issue`;
29 elsif (-r "/etc/issue") {
30 $etc_issue = `cat /etc/issue`;
32 $uname = `uname -a 2>/dev/null`;
34 if ($o->[4] && eval "$o->[4]") {
35 # Got a match! Resolve the versions
37 if ($ver->[1] =~ /\$/) {
38 $ver->[1] = eval "($o->[4]); $ver->[1]";
40 if ($ver->[3] =~ /\$/) {
41 $ver->[3] = eval "($o->[4]); $ver->[3]";
46 print STDERR "Error parsing $o->[4]\n";
53 print "Failed to detect operating system\n";
58 local $rv = system("tty >/dev/null 2>&1");
60 print "Failed to detect operating system\n";
75 if (0 && &has_command("dialog")) {
76 # call the dialog command to ask for the OS (disabled for now)
77 $cmd = "dialog --menu \"Please select your operating system type from the list below\" 20 60 12";
78 for($i=0; $i<@names; $i++) {
79 $cmd .= " ".($i+1)." '$names[$i]'";
81 $tmp_base = $ENV{'tempdir'} || "/tmp/.webmin";
82 $temp = "$tmp_base/dialog.out";
83 system("$cmd 2>$temp");
88 print "ERROR: No operating system selected\n\n";
92 # call the dialog command to ask for the version
93 $name = $names[$osnum-1];
94 @vers = grep { $_->[0] eq $name } @list;
95 $cmd = "dialog --menu \"Please select your operating system's version from the list below\" 20 60 12";
96 for($i=0; $i<@vers; $i++) {
97 $cmd .= " ".($i+1)." '$name $vers[$i]->[1]'";
99 system("$cmd 2>$temp");
104 print "ERROR: No operating system version selected\n\n";
107 $ver = $vers[$vnum-1];
110 # ask for the operating system name ourselves
113 For Webmin to work properly, it needs to know which operating system
114 type and version you are running. Please select your system type by
115 entering the number next to it from the list below
118 for($i=0; $i<@names; $i++) {
119 printf " %2d) %-20.20s ", $i+1, $names[$i];
120 print "\n" if ($i%3 == 2);
122 print "\n" if ($i%3);
124 print "Operating system: ";
125 chop($osnum = <STDIN>);
126 if ($osnum !~ /^\d+$/) {
127 print "ERROR: You must enter the number next to your operating\n";
128 print "system, not its name or version number.\n\n";
131 if ($osnum < 1 || $osnum > @names) {
132 print "ERROR: $osnum is not a valid operating system number.\n\n";
137 # Ask for the operating system version
138 $name = $names[$osnum-1];
140 Please enter the version of $name you are running
143 chop($vnum = <STDIN>);
144 if ($vnum !~ /^\S+$/) {
145 print "ERROR: An operating system number cannot contain\n\n";
146 print "spaces. It must be like 2.1 or ES4.0.\n";
150 $ver = [ $name, $vnum,
151 $names_to_real{$name}, $vnum ];
155 # Write the name, version and real name and version to a file
157 print OUT "os_type='",$ver->[2],"'\n";
158 print OUT "os_version='",$ver->[3],"'\n";
159 print OUT "real_os_type='",$ver->[0],"'\n";
160 print OUT "real_os_version='",$ver->[1],"'\n";
163 # has_command(command)
164 # Returns the full path if some command is in the path, undef if not
168 if (!$_[0]) { return undef; }
170 if ($_[0] =~ /^\//) {
171 $rv = (-x $_[0]) ? $_[0] : undef;
174 foreach $d (split(/:/ , $ENV{PATH})) {
175 if (-x "$d/$_[0]") { $rv = "$d/$_[0]"; last; }