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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
#!/usr/bin/env perl
use strict;
use warnings;
use Config;
use File::Find::Rule;
use File::Copy::Recursive qw(fcopy);
use Getopt::Long qw(:config no_ignore_case bundling);
use Pod::Man;
# files to be installed
my %files = (
bin => [ "dizzy" ],
sbin => [ "dizzy-render" ],
lib => [ File::Find::Rule->file()->name("*.pm")->in("lib") ],
man => [ ], # filled by manpage generator
);
my %man_sources = (
6 => { "dizzy" => "dizzy" },
8 => { "dizzy-render" => "dizzy-render" },
);
my %options = (
dry_run => 0,
install_xscreensaver => 0,
set => "site",
prefix => undef,
install_root => "",
bin_path => undef,
sbin_path => undef,
lib_path => undef,
man_path => undef,
xss_lib_path => "/usr/lib/xscreensaver",
xss_share_path => "/usr/share/xscreensaver",
);
GetOptions(\%options,
'dry_run|dry-run|n+',
'install_xscreensaver|install-xscreensaver|X+',
'set=s',
'prefix=s',
'install_root|install-root=s',
'bin_path|bin-path=s',
'sbin_path|sbin-path=s',
'lib_path|lib-path=s',
'man_path|man-path=s',
'xss_lib_path|xss-lib-path=s',
'xss_share_path|xss-share-path=s',
);
# fill in the paths that were not overridden by user
if (defined($options{prefix})) {
$options{bin_path} //= "$options{prefix}/bin";
$options{sbin_path} //= "$options{prefix}/sbin";
$options{lib_path} //= "$options{prefix}/share/perl5";
$options{man_path} //= "$options{prefix}/share/man";
} else {
die("Argument to --set must be site or vendor") if ($options{set} !~ /^(site|vendor)$/);
$options{bin_path} //= $Config{"install$options{set}bin"};
if (!defined($options{sbin_path})) {
$options{sbin_path} = $Config{"install$options{set}bin"};
$options{sbin_path} =~ s{/bin$}{/sbin};
}
$options{lib_path} //= $Config{"install$options{set}lib"};
if (!defined($options{man_path})) {
$options{man_path} = $Config{"install$options{set}man1dir"};
$options{man_path} =~ s{/man1$}{};
}
}
# generate manpages
print STDERR "Generating manpages... ";
mkdir("_manpages") unless ($options{dry_run});
foreach my $section (keys(%man_sources)) {
mkdir("_manpages/man$section") unless ($options{dry_run});
while (my ($in, $out) = each(%{$man_sources{$section}})) {
Pod::Man
->new(section => $section)
->parse_from_file($in, "_manpages/man$section/$out.$section")
unless ($options{dry_run});
push(@{$files{man}}, "_manpages/man$section/$out.$section");
}
}
print STDERR "done.\n";
# now actually install the files
sub install {
my ($in, $out) = @_;
$in =~ s@/+@/@g;
$out =~ s@/+@/@g;
printf("%-40s -> %s\n", $in, $out);
if ($options{dry_run}) {
return 1;
} else {
fcopy($in, $out) or die("Couldn't install to $out: $! - installation aborted");
}
}
# prefixes to be stripped from input file names before appending them to install dirs.
my %install_prefixes = (
bin => "^.*/",
sbin => "^.*/",
lib => "^lib/",
man => "^_manpages/",
);
foreach my $set (keys(%files)) {
foreach my $from (@{$files{$set}}) {
my $to = $from; $to =~ s@$install_prefixes{$set}@@;
install($from, $options{install_root} . "/" . $options{$set . "_path"} . "/" . $to);
}
}
if ($options{install_xscreensaver}) {
install("dizzy-xscreensaver", "$options{install_root}/$options{xss_lib_path}/dizzy");
install("dizzy.xml", "$options{install_root}/$options{xss_share_path}/config/dizzy.xml");
}
if ($options{dry_run}) {
print STDERR "Dry run complete, now run without -n to install files.\n";
} else {
print STDERR "All files installed successfully.\n";
}
exit(0);
__END__
=head1 NAME
B<install_dizzy> - Dizzy's configuration and installation script
=head1 SYNOPSIS
B<install_dizzy> [B<-n>] [B<--set> I<vendor|site>] [B<--install-root> I<prefix>] ...
=head1 DESCRIPTION
B<install_dizzy> is the tool that is used to install Dizzy. The motivation for
using this self-written script instead of something existing could best be
described as "special needs" (or "laziness"). At least it works.
When run, the tool will generate manpages from embedded POD and install
libraries, binaries, and manpages to the system.
See the options described below for controlling the location Dizzy will be
installed (by default, this is something like /usr/local).
=head1 OPTIONS
=over
=item B<-n>
=item B<--dry-run>
Don't actually install anything, just print what would be done.
=item B<-X>
=item B<--install-xscreensaver>
Install the XScreenSaver version of Dizzy. It will by default be installed to
F</usr/lib/xscreensaver> and not to something specified by B<--prefix> because
XScreenSaver only looks in that folder. Override with B<--xss-path> if necessary.
=item B<--set> I<vendor|site>
Set default install paths according to what L<Config> thinks about this set.
Typically, I<vendor> means something like F</usr> and I<site> means something
like F</usr/local>. The default is I<site>.
=item B<--prefix> I<path>
Set default install paths to be under I<path>. This will install binaries to
F<path/bin>, superuser binaries to F<path/sbin>, libraries to F<path/share/perl5>,
and manpages to F<path/share/man>, unless overridden by one of the five B<--*-path>
options.
=item B<--install-root> I<path>
Prefix I<path> to all paths that will be written to. This is useful for scripts
of package managers, which install software into a directory and then pack this
directory. Example: F</build/dizzy-0.2.0/debian/dizzy> (will create
F</build/dizzy-0.2.0/debian/dizzy/usr/bin/dizzy> and so on.) This option is
unset by default, which means all files will be installed into the system.
=item B<--bin-path> I<bin-path>
=item B<--sbin-path> I<sbin-path>
=item B<--lib-path> I<lib-path>
=item B<--man-path> I<man-path>
=item B<--xss-lib-path> I<xss-lib-path>
=item B<--xss-share-path> I<xss-share-path>
Set different install paths for some elements. I<bin-path> specifies where
the F<dizzy> binary is installed, I<sbin-path> for F<dizzy-render>, I<lib-path>
for all the modules under F<lib> and I<man-path> for all documentation.
I<xss-lib-path> is the location where the XScreenSaver version is installed if
B<-X> is given. The default values for these options are specified by the B<--set>
or B<--prefix> options, the default for I<xss-lib-path> is F</usr/lib/xscreensaver>
and that for I<xss-share-path> is F</usr/share/xscreensaver>.
A sensible value for I<bin-path> might be F</usr/games>.
=back
=head1 EXAMPLE
A command line like this is used in Debian build scripts:
./install_dizzy --set vendor --bin-path /usr/games --install-root ./debian/dizzy --install-xscreensaver
|