2 # Read the list of operating systems and ask the user to choose
4 # auto param: 0 = always ask user
5 # 1 = automatic, give up if fails
6 # 2 = automatic, ask user if fails
7 # 3 = automatic, ask user if fails and if a TTY
11 ($oslist, $out, $auto) = @ARGV;
12 open(OS, $oslist) || die "failed to open $oslist : $!";
15 if (/^([^\t]+)\t+([^\t]+)\t+([^\t]+)\t+([^\t]+)\t*(.*)$/) {
16 push(@list, [ $1, $2, $3, $4, $5 ]);
17 push(@names, $1) if (!$donename{$1}++);
18 $names_to_real{$1} ||= $3;
24 # Try to guess the OS name and version
25 if (-r "/etc/.issue") {
26 $etc_issue = `cat /etc/.issue`;
28 elsif (-r "/etc/issue") {
29 $etc_issue = `cat /etc/issue`;
31 $uname = `uname -a 2>/dev/null`;
33 if ($o->[4] && eval "$o->[4]") {
34 # Got a match! Resolve the versions
36 if ($ver->[1] =~ /\$/) {
37 $ver->[1] = eval "($o->[4]); $ver->[1]";
39 if ($ver->[3] =~ /\$/) {
40 $ver->[3] = eval "($o->[4]); $ver->[3]";
45 print STDERR "Error parsing $o->[4]\n";
52 print "Failed to detect operating system\n";
57 local $rv = system("tty >/dev/null 2>&1");
59 print "Failed to detect operating system\n";
74 if (0 && &has_command("dialog")) {
75 # call the dialog command to ask for the OS (disabled for now)
76 $cmd = "dialog --menu \"Please select your operating system type from the list below\" 20 60 12";
77 for($i=0; $i<@names; $i++) {
78 $cmd .= " ".($i+1)." '$names[$i]'";
80 $tmp_base = $ENV{'tempdir'} || "/tmp/.webmin";
81 $temp = "$tmp_base/dialog.out";
82 system("$cmd 2>$temp");
87 print "ERROR: No operating system selected\n\n";
91 # call the dialog command to ask for the version
92 $name = $names[$osnum-1];
93 @vers = grep { $_->[0] eq $name } @list;
94 $cmd = "dialog --menu \"Please select your operating system's version from the list below\" 20 60 12";
95 for($i=0; $i<@vers; $i++) {
96 $cmd .= " ".($i+1)." '$name $vers[$i]->[1]'";
98 system("$cmd 2>$temp");
103 print "ERROR: No operating system version selected\n\n";
106 $ver = $vers[$vnum-1];
109 # ask for the operating system name ourselves
112 For Webmin to work properly, it needs to know which operating system
113 type and version you are running. Please select your system type by
114 entering the number next to it from the list below
117 for($i=0; $i<@names; $i++) {
118 printf " %2d) %-20.20s ", $i+1, $names[$i];
119 print "\n" if ($i%3 == 2);
121 print "\n" if ($i%3);
123 print "Operating system: ";
124 chop($osnum = <STDIN>);
125 if ($osnum !~ /^\d+$/) {
126 print "ERROR: You must enter the number next to your operating\n";
127 print "system, not its name or version number.\n\n";
130 if ($osnum < 1 || $osnum > @names) {
131 print "ERROR: $osnum is not a valid operating system number.\n\n";
136 # Ask for the operating system version
137 $name = $names[$osnum-1];
139 Please enter the version of $name you are running
142 chop($vnum = <STDIN>);
143 if ($vnum !~ /^\S+$/) {
144 print "ERROR: An operating system number cannot contain\n\n";
145 print "spaces. It must be like 2.1 or ES4.0.\n";
149 $ver = [ $name, $vnum,
150 $names_to_real{$name}, $vnum ];
154 # Write the name, version and real name and version to a file
156 print OUT "os_type='",$ver->[2],"'\n";
157 print OUT "os_version='",$ver->[3],"'\n";
158 print OUT "real_os_type='",$ver->[0],"'\n";
159 print OUT "real_os_version='",$ver->[1],"'\n";
162 # has_command(command)
163 # Returns the full path if some command is in the path, undef if not
167 if (!$_[0]) { return undef; }
169 if ($_[0] =~ /^\//) {
170 $rv = (-x $_[0]) ? $_[0] : undef;
173 foreach $d (split(/:/ , $ENV{PATH})) {
174 if (-x "$d/$_[0]") { $rv = "$d/$_[0]"; last; }