| 1 |
#! /usr/bin/perl |
| 2 |
# |
| 3 |
######################################################################### |
| 4 |
# This Perl script is Copyright (c) 2003, Peter J Billam # |
| 5 |
# c/o P J B Computing, www.pjb.com.au # |
| 6 |
# # |
| 7 |
# This script is free software; you can redistribute it and/or # |
| 8 |
# modify it under the same terms as Perl itself. # |
| 9 |
######################################################################### |
| 10 |
|
| 11 |
use Term::Clui; |
| 12 |
use Term::Clui::FileSelect; |
| 13 |
$debug = 0; |
| 14 |
$hostname = `hostname`; $hostname =~ s/[\r\n]*//; |
| 15 |
@PATH = split (":", $ENV{PATH}); |
| 16 |
my $daemon_d; |
| 17 |
my @system_configs; |
| 18 |
my $crond = &first_existing('/var/spool/cron/crontabs','/var/spool/cron'); |
| 19 |
my $squidlogd = &first_existing('/usr/local/squid/logs','/var/squid/logs'); |
| 20 |
my $squidconfd = &first_existing('/usr/local/squid/etc','/etc/squid'); |
| 21 |
my $squid = &first_existing('/usr/local/squid/sbin/squid','/usr/sbin/squid'); |
| 22 |
my $sambalogd = &first_existing('/usr/local/samba/var','/var/log/samba'); |
| 23 |
my $sambaconfd = &first_existing('/usr/local/samba/lib','/etc/samba'); |
| 24 |
my $tracd = &first_existing('/var/www/trac'); |
| 25 |
my $svnd = &first_existing('/usr/local/svn'); |
| 26 |
my $lshw = &first_existing('/usr/local/bin/lshw','/usr/bin/lshw'); |
| 27 |
my $apacheconfd = &first_existing( '/usr/local/apache/conf', |
| 28 |
'/usr/local/apache2/conf','/etc/apache2','/etc/apache'); |
| 29 |
my $dirvishconf = &first_existing('/etc/dirvish.conf', |
| 30 |
'/usr/local/dirvish/etc/master.conf','/etc/dirvish/master.conf'); |
| 31 |
my $lsmod = &which('lsmod'); |
| 32 |
my $modinfo = &which('modinfo'); |
| 33 |
@tasks = &tasks(); |
| 34 |
if (! @tasks) { die "Sorry, no administration tasks are available\n"; } |
| 35 |
while () { |
| 36 |
$task = &choose("Administrating $hostname", @tasks); |
| 37 |
if (! $task) { exit; |
| 38 |
} elsif ($task eq "Become superuser") { exec "su - -c $0"; |
| 39 |
} elsif ($task eq "adduser") { &adduser(); |
| 40 |
} elsif ($task eq "aptitude") { system "aptitude"; |
| 41 |
} elsif ($task eq "base-config") { system "base-config"; |
| 42 |
} elsif ($task eq "chpass") { system "chpass"; |
| 43 |
} elsif ($task eq "chkconfig") { &chkconfig(); |
| 44 |
} elsif ($task eq "lshw") { system "lshw | less"; |
| 45 |
} elsif ($task eq "mii-tool") { system "mii-tool"; |
| 46 |
} elsif ($task eq "system-config") { &system_config(); |
| 47 |
} elsif ($task eq "trac-admin") { &trac_admin(); |
| 48 |
} elsif ($task eq "update-rc.d") { &update_rcd(); |
| 49 |
} elsif ($task eq "vipw") { system "vipw"; system "vipw -s"; |
| 50 |
} elsif ($task eq "visudo") { system "visudo"; |
| 51 |
} elsif ($task eq "Apache") { &apache(); |
| 52 |
} elsif ($task eq "Crontab") { &crontab(); |
| 53 |
} elsif ($task eq "Daemons") { &daemons(); |
| 54 |
} elsif ($task eq "Dirvish") { &dirvish(); |
| 55 |
} elsif ($task eq "Modules") { &modules(); |
| 56 |
} elsif ($task eq "Network ports") { &ports(); |
| 57 |
} elsif ($task eq "Samba") { &samba(); |
| 58 |
} elsif ($task eq "Squid") { &squid(); |
| 59 |
} elsif (-f $task) { &edit ($task); |
| 60 |
} elsif (-d $task) { |
| 61 |
$file = &select_file(-TextFile=>1, -TopDir=>$task); |
| 62 |
if ($file) { &edit ($file) }; |
| 63 |
} |
| 64 |
} |
| 65 |
sub tasks { |
| 66 |
my @tasks; |
| 67 |
if (! $>) { # root stuff |
| 68 |
foreach $f ( |
| 69 |
qw(adduser aptitude base-config chkconfig chpass lshw mii-tool |
| 70 |
sax sax2 trac-admin update-rc.d vipw visudo yast yast2)) { |
| 71 |
if (&which($f)) { push @tasks, $f; } |
| 72 |
} |
| 73 |
if (opendir D, '/usr/bin') { |
| 74 |
@system_configs = sort grep /^system-config-/,readdir D; closedir D; |
| 75 |
if (@system_configs) { push @tasks, 'system-config'; } |
| 76 |
foreach (@system_configs) { s/^system-config-//; } |
| 77 |
} |
| 78 |
} else { push @tasks, 'Become superuser'; |
| 79 |
} |
| 80 |
foreach ( |
| 81 |
'/etc/inittab', |
| 82 |
'/etc/sysconfig', |
| 83 |
'/etc/xinetd.d', |
| 84 |
'/etc/resolv.conf', |
| 85 |
'/etc/iptables.up.rules', |
| 86 |
'/etc', |
| 87 |
) { if (-d $_ || -f $_) { push @tasks, $_; } } |
| 88 |
if (-d $apacheconfd) { push @tasks, 'Apache'; } |
| 89 |
if (-d $crond) { push @tasks, 'Crontab'; } |
| 90 |
if (! $>) { |
| 91 |
foreach ('/etc/rc.d/init.d','/etc/init.d') { |
| 92 |
if (-d $_) {$daemon_d = $_; push @tasks, 'Daemons'; last} |
| 93 |
} |
| 94 |
} |
| 95 |
if (-e $dirvishconf) { push @tasks, 'Dirvish'; } |
| 96 |
if ($lsmod && $modinfo) { push @tasks, 'Modules'; } |
| 97 |
push @tasks, 'Network ports'; |
| 98 |
if (-d $squidlogd) { push @tasks, 'Squid'; } |
| 99 |
if (-d $sambaconfd) { push @tasks, 'Samba'; } |
| 100 |
return @tasks; |
| 101 |
} |
| 102 |
sub squid { |
| 103 |
my @tasks = ( 'tail -f access.log', 'tail -f access.log | grep', |
| 104 |
'tail -f cache.log'); |
| 105 |
if ($squid && !$>) { push @tasks, 'Reconfigure'; } |
| 106 |
my $task = &choose('Squid ?', @tasks); |
| 107 |
return unless $task; |
| 108 |
if ($task =~ /(\w+\.log)$/) { system "tail -f $squidlogd/$1"; |
| 109 |
} elsif ($task =~ /grep$/) { |
| 110 |
my $s = &ask ('look for what regexp ?'); |
| 111 |
next unless $s; |
| 112 |
system "tail -f $squidlogd/access.log | grep '$s'"; |
| 113 |
} elsif ($task eq 'Reconfigure') { |
| 114 |
if (! chdir $squidconfd) { |
| 115 |
&sorry("can't chdir $squidconfd: $!"); return; |
| 116 |
} |
| 117 |
&edit ('squid.conf'); |
| 118 |
if (&confirm ('OK to "squid -k reconfigure" ?')) { |
| 119 |
system "$squid -k reconfigure"; |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
sub samba { |
| 124 |
my $sambabind = "/usr/bin"; |
| 125 |
if (-d "/usr/local/samba/bin") { $sambabind = "/usr/local/samba/bin"; } |
| 126 |
|
| 127 |
my @tasks = ('log.smbd','log.winbindd'); |
| 128 |
if (!$>) { push @tasks, 'smb.conf'; } |
| 129 |
if (-w "$sambaconfd/username.map") { push @tasks, 'username.map'; } |
| 130 |
my $task = &choose('Samba ?', @tasks); |
| 131 |
return unless $task; |
| 132 |
if ($task =~ /log/) { system "tail -f $sambalogd/$task"; |
| 133 |
} elsif ($task =~ /grep$/) { |
| 134 |
my $s = &ask ('look for what regexp ?'); |
| 135 |
next unless $s; |
| 136 |
system "tail -f $sambalogd/log | grep '$s'"; |
| 137 |
} elsif ($task eq 'smb.conf' || $task eq 'username.map') { |
| 138 |
if (! chdir $sambaconfd) { |
| 139 |
&sorry("can't chdir sambaconfd: $!"); return; |
| 140 |
} |
| 141 |
while (1) { |
| 142 |
&edit ($task); |
| 143 |
my $retval = system "$sambabind/testparm"; |
| 144 |
if ($? == -1) { |
| 145 |
&sorry("can't run testparm: $!\n"); return; |
| 146 |
} elsif ($? & 127) { |
| 147 |
&sorry (sprintf "testparm died with signal %d, %s coredump\n", |
| 148 |
($? & 127), ($? & 128)?'with':'without'); return; |
| 149 |
} else { |
| 150 |
# $retval >> 8; |
| 151 |
if (! $retval) { |
| 152 |
if (&confirm ('OK to Reload Config ?')) { |
| 153 |
system "$sambabind/smbcontrol smbd reload-config"; |
| 154 |
system "$sambabind/smbcontrol nmbd reload-config"; |
| 155 |
} |
| 156 |
last; |
| 157 |
} else { |
| 158 |
warn "That didn't work, you'll need to re-edit smb.conf ...\n"; |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
sub apache { |
| 165 |
my $d = $apacheconfd; |
| 166 |
my $file; my $apachectl; |
| 167 |
my @tasks = (); |
| 168 |
my $enabled = &first_existing("$d/sites-enabled","$d/vhosts.d","$d/conf.d"); |
| 169 |
if ($enabled) { push @tasks, "Edit a site"; } |
| 170 |
my $a2ensite = &which('a2ensite'); |
| 171 |
if ($a2ensite) { push @tasks, 'Enable a site'; } |
| 172 |
my $a2dissite = &which('a2dissite'); |
| 173 |
if ($a2dissite) { push @tasks, 'Disable a site'; } |
| 174 |
my $a2enmod = &which('a2enmod'); |
| 175 |
if ($a2enmod) { push @tasks, 'Enable a module'; } |
| 176 |
my $a2dismod = &which('a2dismod'); |
| 177 |
if ($a2dismod) { push @tasks, 'Disable a module'; } |
| 178 |
my $conff = &first_existing("$d/apache2.conf","$d/httpd.conf"); |
| 179 |
if ($conff) { push @tasks, "Edit main config file"; } |
| 180 |
if (! @tasks) { return; } |
| 181 |
my $task = &choose("which apache task ?", @tasks); |
| 182 |
return unless $task; |
| 183 |
if ($task eq 'Edit a site') { |
| 184 |
my $site = &select_file |
| 185 |
(-Title=>'which site ?', -TextFile=>1, -TopDir=>$enabled, -Chdir=>0); |
| 186 |
return unless $site; |
| 187 |
&edit ($site); |
| 188 |
} elsif ($task eq 'Enable a site') { |
| 189 |
my $site = &select_file (-Title=>'which site ?', -TextFile=>1, |
| 190 |
-TopDir=>"$d/sites-available", -Chdir=>0); |
| 191 |
$site =~ s/^.*\///; |
| 192 |
return unless $site; |
| 193 |
system "$a2ensite $site"; |
| 194 |
} elsif ($task eq 'Disable a site') { |
| 195 |
my $site = &select_file (-Title=>'which site ?', -TextFile=>1, |
| 196 |
-TopDir=>"$enabled", -Chdir=>0); |
| 197 |
$site =~ s/^.*\///; |
| 198 |
return unless $site; |
| 199 |
system "$a2dissite $site"; |
| 200 |
} elsif ($task eq 'Enable a module') { |
| 201 |
my $module = &select_file (-Title=>'which module ?', -FPat=>'*.load', |
| 202 |
-TopDir=>"$d/mods-available", -Chdir=>0); |
| 203 |
$module =~ s/^.*\///; |
| 204 |
return unless $module; |
| 205 |
system "$a2enmod $module"; |
| 206 |
} elsif ($task eq 'Disable a module') { |
| 207 |
my $module = &select_file (-Title=>'which module ?', -FPat=>'*.load', |
| 208 |
-TopDir=>"$d/mods-enabled", -Chdir=>0); |
| 209 |
$module =~ s/^.*\///; |
| 210 |
return unless $module; |
| 211 |
system "$a2dismod $module"; |
| 212 |
} elsif ($task eq 'Edit main config file') { |
| 213 |
&edit ($conff); |
| 214 |
} |
| 215 |
my $apachectl = &which('apache2ctl') || &which('apachectl') |
| 216 |
|| '/usr/local/apache/bin/apachectl'; |
| 217 |
if (&confirm ('OK to Restart Apache ?')) { system "$apachectl restart"; } |
| 218 |
} |
| 219 |
sub dirvish { |
| 220 |
if (!open(F,$dirvishconf)) { die "can't open $dirvishconf: $!\n"; } |
| 221 |
my $ary; my $Banks; my @Vaults; |
| 222 |
while (<F>) { |
| 223 |
if (/^#/) { next; |
| 224 |
} elsif (/^bank:/i) { $ary = \@Banks; |
| 225 |
} elsif (/^Runall:/i) { $ary = \@Vaults; |
| 226 |
} elsif (/^\w/) { $ary = 0; |
| 227 |
} elsif (/^\s+(\S+)/ && ref $ary) { push @$ary, $1; |
| 228 |
} |
| 229 |
} |
| 230 |
close F; |
| 231 |
my @tasks = (); |
| 232 |
push @tasks, $dirvishconf; |
| 233 |
foreach my $vault (sort @Vaults) { |
| 234 |
my $bank; |
| 235 |
foreach (@Banks) { if (-d "$_/$vault") { $bank = $_; last; } } |
| 236 |
if (!$bank) { warn "can't find vault $vault in banks @Banks\n"; next;} |
| 237 |
|
| 238 |
my $backupd = "$bank/$vault"; |
| 239 |
$BackupDirs{$vault} = $backupd; |
| 240 |
if (!-d "$backupd/dirvish") {warn "$backupd/dirvish not found\n";next;} |
| 241 |
if (!-f "$backupd/dirvish/default.conf") { |
| 242 |
open (F, ">$backupd/dirvish/default.conf"); close F; |
| 243 |
} |
| 244 |
push @tasks, "$backupd/dirvish/default.conf"; |
| 245 |
} |
| 246 |
if (@Vaults) { |
| 247 |
push @tasks, "Re-run last night's backup"; |
| 248 |
} |
| 249 |
if (1 < @Vaults) { |
| 250 |
push @tasks, "Re-run a particular vault"; |
| 251 |
} |
| 252 |
|
| 253 |
my $task = &choose('which dirvish task ?', @tasks); |
| 254 |
if ($task eq "Re-run last night's backup") { |
| 255 |
system "dirvish-runall"; |
| 256 |
} elsif ($task eq "Re-run a particular vault") { |
| 257 |
my $vault = &choose('which vault ?', sort @Vaults); |
| 258 |
next unless $vault; |
| 259 |
system "dirvish --vault $vault --image-time 21:00 &"; |
| 260 |
} elsif (-f $task) { |
| 261 |
&edit($task); |
| 262 |
} |
| 263 |
} |
| 264 |
sub modules { |
| 265 |
if (! open (P, "$lsmod |")) { &sorry("can't run $lsmod: $!"); return 0; } |
| 266 |
my %mod2lsmod = (); |
| 267 |
my $title = ''; |
| 268 |
while (<P>) { |
| 269 |
if (/^([a-z]\w+)\s/) { $mod2lsmod{$1}=$_; |
| 270 |
} elsif (/^[A-Z]/) { $title = $_; |
| 271 |
} |
| 272 |
} |
| 273 |
close P; |
| 274 |
my $mod = &choose('Which module ?', sort keys %mod2lsmod); |
| 275 |
return(0) unless $mod; |
| 276 |
print $title, $mod2lsmod{$mod}, "\n"; |
| 277 |
system "$modinfo $mod"; |
| 278 |
} |
| 279 |
sub ports { |
| 280 |
if (! open (P, "netstat -a |")) { |
| 281 |
&sorry("can't run netstat -a: $!"); return 0; |
| 282 |
} |
| 283 |
my @lines; while (<P>) { if (/LISTEN|ESTABLISH/) { push @lines, $_; } } |
| 284 |
close P; |
| 285 |
if (! open (P, "iptables -L |")) { |
| 286 |
&sorry("can't run iptables -L: $!"); |
| 287 |
} else { |
| 288 |
push @lines, "\n", "Iptables:\n"; |
| 289 |
while (<P>) { s/ state/state/ ; push @lines, $_; } |
| 290 |
close P; |
| 291 |
} |
| 292 |
&view ("Ports", join('', @lines)); |
| 293 |
} |
| 294 |
sub daemons { |
| 295 |
my $task = &choose('Task ?','start','restart','stop'); |
| 296 |
return unless $task; |
| 297 |
my $daemon = &select_file |
| 298 |
(-Title=>'which daemon ?', -TextFile=>1, -TopDir=>$daemon_d, -Chdir=>0); |
| 299 |
return unless $daemon; |
| 300 |
system "sh $daemon $task"; |
| 301 |
} |
| 302 |
sub crontab { |
| 303 |
if ($>) { system "crontab -e"; return 0; } |
| 304 |
if (! opendir(D,$crond)) { warn "can't opendir $crond: \n"; return 0; } |
| 305 |
my @users = sort grep { !/^\./ } readdir(D); |
| 306 |
closedir D; |
| 307 |
if (! @users) { warn "no crontabs found in $crond\n"; return 0; } |
| 308 |
my $task = &choose('crontab task ?', 'View', 'Edit', 'Manual'); |
| 309 |
return unless $task; |
| 310 |
if ($task eq 'Manual') { system 'man 5 crontab'; return; } |
| 311 |
my $user = &choose ("$task which user ?", @users); |
| 312 |
return unless $user; |
| 313 |
my $useropt = '-u '; if ($^O =~ /solaris/) { $useropt = ''; } |
| 314 |
if ($task eq 'Edit') { system "crontab -e $useropt $user"; |
| 315 |
} else { system "crontab -l $useropt $user"; |
| 316 |
} |
| 317 |
} |
| 318 |
sub chkconfig { |
| 319 |
if (! open (P, "chkconfig --list |")) { |
| 320 |
&sorry("can't run chkconfig --list: $!"); return 0; |
| 321 |
} |
| 322 |
my @l; my @xinetdl; while (<P>) { |
| 323 |
chop; |
| 324 |
if (/^\s/ || /based services/) { push @xinetdl, $_; |
| 325 |
} else { push @l, $_; |
| 326 |
} |
| 327 |
} |
| 328 |
if (open (F, '/etc/inittab')) { |
| 329 |
while (<F>) { |
| 330 |
if (/^\w+:(\d):initdefault:/) {warn " default run-level $1\n"; last;} |
| 331 |
} |
| 332 |
close F; |
| 333 |
} |
| 334 |
my $r = `who -r 2>/dev/null`; $r =~ s/^\s*(\S+\s+\d+).*$/$1/; |
| 335 |
if ($r) { warn("currently $r"); } |
| 336 |
my $task = &choose('chkconfig task ?', 'View', 'Edit'); |
| 337 |
return unless $task; |
| 338 |
if ($task eq 'Edit') { |
| 339 |
my %services; |
| 340 |
foreach (@l) { /^(\S+)\s+(.*)$/; $services{$1}=$2; } |
| 341 |
my $service = &choose('Edit which service ?', sort keys %services); |
| 342 |
return unless $service; |
| 343 |
&inform ($services{$service}); |
| 344 |
my @runlevels = &choose('at which runlevels ?','1','2','3','4','5'); |
| 345 |
return unless @runlevels; |
| 346 |
my $onoff = |
| 347 |
&choose("$service at runlevels ".join(",",@runlevels),'on','off'); |
| 348 |
return unless $onoff; |
| 349 |
system "chkconfig --level ".join('',@runlevels)." $service $onoff"; |
| 350 |
} else { |
| 351 |
&view('chkconfig --list', join("\n", (sort @l ),@xinetdl)); |
| 352 |
} |
| 353 |
&view ('Daemon configuration', $s); |
| 354 |
} |
| 355 |
sub trac_admin { |
| 356 |
if (! opendir(D, $tracd)) { warn "can't opendir $tracd: $!\n"; return; } |
| 357 |
@dirs = grep { !/^\./ && -d "$tracd/$_" } readdir(D); |
| 358 |
closedir D; |
| 359 |
if (! @dirs) { warn "no projects found in $tracd\n"; return; } |
| 360 |
my $dir = &choose("which project ?", @dirs); |
| 361 |
return unless $dir; |
| 362 |
system "trac-admin $tracd/$dir"; |
| 363 |
if ($svnd && -f "$svnd/conf/svnpolicy") { &edit("$svnd/conf/svnpolicy"); } |
| 364 |
} |
| 365 |
sub update_rcd { |
| 366 |
my $r = `who -r`; $r =~ s/^\s*(\S+\s+\d+).*$/$1/; warn("currently $r"); |
| 367 |
my $task = &choose('update-rc.d task ?', 'View', 'Edit'); |
| 368 |
return unless $task; |
| 369 |
if ($task eq 'Edit') { |
| 370 |
if (! opendir(D, '/etc/init.d')) { |
| 371 |
&sorry("can't opendir /etc/init.d: $!"); return 0; |
| 372 |
} |
| 373 |
my @l = sort grep |
| 374 |
{ !/^\.|^README|\.sh$|S$|^single$|^halt$|^reboot$/ } readdir(D); |
| 375 |
closedir D; |
| 376 |
my $service = &choose('Edit which service ?', @l); |
| 377 |
return unless $service; |
| 378 |
system "cd /etc ; ls rc[12345].d/S*$service*"; |
| 379 |
my $onoff = &choose("$service at runlevels 2,3,4,5",'on','off'); |
| 380 |
return unless $onoff; |
| 381 |
if ($onoff eq 'on') { |
| 382 |
my $startnumber = &choose("start-order number ?", 20 .. 99); |
| 383 |
system "update-rc.d $service defaults $startnumber"; |
| 384 |
} elsif ($onoff eq 'off') { |
| 385 |
system "update-rc.d -f $service remove"; |
| 386 |
} |
| 387 |
} else { |
| 388 |
local $/; |
| 389 |
&view('ls /etc/rc[2345].d', `ls -C --tabsize=75 /etc/rc[2345].d`); |
| 390 |
} |
| 391 |
} |
| 392 |
sub system_config { |
| 393 |
my $task = &choose('which system-config ?', @system_configs); |
| 394 |
return unless $task; |
| 395 |
system "/usr/bin/system-config-$task"; |
| 396 |
} |
| 397 |
sub adduser { |
| 398 |
my $name = &ask('new username ?'); |
| 399 |
if (getpwnam($name)) { &sorry("user $name already exists"); return 0; } |
| 400 |
my @groups = &choose('groups ?', &groups()); |
| 401 |
my $group; my @secondary_groups=(); |
| 402 |
if (1 < scalar @groups) { |
| 403 |
$group = &choose('primary group ?', @groups); |
| 404 |
foreach (@groups) { if ($_ ne $group) { push @secondary_groups, $_; } } |
| 405 |
} else { |
| 406 |
$group = $groups[0]; |
| 407 |
} |
| 408 |
return unless $group; |
| 409 |
my $fullname = &ask('full name ?'); |
| 410 |
my $shell = &choose('login shell ?', &shells()); |
| 411 |
my $cmd = &which("adduser") . " -g $group"; |
| 412 |
if (@secondary_groups) { $cmd .= " -G " . join(",",@secondary_groups) ; } |
| 413 |
if ($fullname) { $cmd .= " -c '$fullname'"; } |
| 414 |
if ($shell) { $cmd .= " -s $shell"; } |
| 415 |
$cmd .= " $name"; |
| 416 |
&confirm("OK to $cmd ?") && system $cmd; |
| 417 |
} |
| 418 |
# ------------------------- infrastructure ---------------------- |
| 419 |
sub groups { |
| 420 |
my @groups=(); my $n; |
| 421 |
setgrent; while ($n = getgrent()) { push @groups, $n; } endgrent; |
| 422 |
sort @groups; |
| 423 |
} |
| 424 |
sub shells { |
| 425 |
my @shells; my $d; my $x; |
| 426 |
foreach $d ('/bin','/usr/bin') { |
| 427 |
if (! opendir(D,$d)) { &sorry("can't opendir $d: $!\n"); return ; } |
| 428 |
while ($_ = readdir D) { |
| 429 |
if (/sh$/ && !/ssh$/ && !/\.sh$/ && !/splash$/ && !/flash$/) { |
| 430 |
push @shells, "$d/$_"; |
| 431 |
} |
| 432 |
} |
| 433 |
closedir D; |
| 434 |
} |
| 435 |
sort @shells; |
| 436 |
} |
| 437 |
sub first_existing { |
| 438 |
my $f = ''; foreach (@_) { if (-e $_) { $f = $_; last; } } |
| 439 |
return $f; |
| 440 |
} |
| 441 |
sub which { my $f; |
| 442 |
foreach $d (@PATH) { $f="$d/$_[0]"; return $f if -x $f; } |
| 443 |
} |