forked from jasontibbitts/majordomo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
installbin
70 lines (61 loc) · 2.5 KB
/
installbin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
$^W = 1;
use Config;
use Fcntl qw(:flock :DEFAULT);
use File::Copy;
$config = eval {require "./.mj_config"};
die "Invalid .mj_config" unless $config;
my $uid = getpwnam($config->{'uid'});
my $gid = getgrnam($config->{'gid'});
my $domains = join(" ",@{$config->{'domains'}});
$start = "#!$config->{'startperl'}";
while (($src,$dst) = splice(@ARGV,0,2)) {
# We just copy the file if we're moving a wrapper
if ($src =~ /wrappers/) {
copy($src, $dst);
}
# but if we're moving a script, we need to wedge in some constants.
else {
open(SRC,"<$src") || die "Cannot open $src:$!";
chmod(0755,$dst) if (-f $dst);
open(DST,">$dst") || die "Cannot open $dst:$!";
while (defined($line = <SRC>)) {
$line =~ s/^#!\s*\S+/$start/;
$line =~ s!(^ \$::CONFFILE\s*= ).*!$1\"$config->{'majordomocf'}\";!;
$line =~ s!(^ \$::BINDIR\s*= ).*!$1\"$config->{'install_dir'}/bin\";!;
$line =~ s!(^ \$::LIBDIR\s*= ).*!$1\"$config->{'install_dir'}/lib\";!;
$line =~ s!(^ \$::LISTDIR\s*= ).*!$1\"$config->{'lists_dir'}\";!;
$line =~ s!(^ \$::UMASK\s*= ).*!$1\"$config->{'umask'}\";!;
$line =~ s!(^ \$::TMPDIR\s*= ).*!$1\"$config->{'tmpdir'}\";!;
$line =~ s!(^ \$::LOCKDIR\s*= ).*!$1\"$config->{'lockdir'}\";!;
$line =~ s!(^ \$::WTMPDIR\s*= ).*!$1\"$config->{'wtmpdir'}\";!;
$line =~ s!(^ \$::UID\s*= ).*!$1\"$uid\";!;
$line =~ s!(^ \$::GID\s*= ).*!$1\"$gid\";!;
$line =~ s!(^ \$::TIMEOUT\s*= ).*!$1$config->{'queue_timeout'};!
if $config->{'queue_timeout'};
$line =~ s!(^ \$::CONCURRENCY\s*= ).*!$1$config->{'queue_concurrency'};!
if $config->{'queue_concurrency'};
$line =~ s!(^ \$::SIG_CHLD_IGNORE\s*= ).*!$1$config->{'queue_chld_ignore'};!
if defined($config->{'queue_chld_ignore'});
# Fcntl and flock constants hardcoded for speed
$lock_ex = LOCK_EX; $lock_nb = LOCK_NB; $lock_un = LOCK_UN;
$line =~ s!(^ \$::LOCK_EX\s*= ).*!$1$lock_ex;!;
$line =~ s!(^ \$::LOCK_NB\s*= ).*!$1$lock_nb;!;
$line =~ s!(^ \$::LOCK_UN\s*= ).*!$1$lock_un;!;
$o_wronly = O_WRONLY; $o_creat = O_CREAT; $o_excl = O_EXCL;
$line =~ s!(^ \$::O_WRONLY\s*= ).*!$1$o_wronly;!;
$line =~ s!(^ \$::O_CREAT\s*= ).*!$1$o_creat;!;
$line =~ s!(^ \$::O_EXCL\s*= ).*!$1$o_excl;!;
print DST $line;
}
close(SRC);
close(DST);
chmod(0555,$dst);
}
print "installbin $src => $dst\n";
}
#^L
### Local Variables: ***
### mode:cperl ***
### cperl-indent-level:2 ***
### cperl-label-offset:-1 ***
### End: ***