*.sh: remove hard-coded bits with config.pl
[girocco/ztw.git] / config.pl
blob2df132ddcf8f0245538f84048b27e1d591f769c2
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 my $home_path = '/data/work/repo.or.cz/site';
7 my @config = (
8 site_admin => 'pasky@ucw.cz',
9 site_domain => 'repo.or.cz',
11 bin_path => "$home_path/bin",
12 jail_path => "$home_path/jail",
13 repomgr_path => "$home_path/repomgr",
14 repodata_path => "$home_path/repodata",
15 repo_path => "$home_path/repos",
17 group_file => '/etc/group',
18 user_file => '/etc/passwd',
19 sshkeys_path => '/etc/sshkeys',
21 my @keys = map { $config[$_ * 2] } 0 .. (@config / 2 - 1);
23 my $config = 'config.txt';
24 my $update = @ARGV && $ARGV[0] eq '-u';
26 sub read_config {
27 open F, "<$config" or die $!;
28 my %config;
29 for (<F>) {
30 chomp;
31 next if /^\s*$/ || /^#/;
32 my ( $key, $value ) = split(/=/, $_);
33 $config{$key} = $value;
35 close F or die $!;
36 %config
39 my %config = @config;
40 my $settings = read_config if -f $config;
42 if ($update || ! -f $config ) {
43 open F, ">$config" or die $!;
44 print F "# repository manager site parameters\n";
45 print F $_, "=", $config{$_}, "\n" for @keys;
46 close F or die $!;
47 exit
49 read_config;
51 sub substitute {
52 my $line = shift;
53 $line =~ s/\@$_\@/$config{$_}/ for @keys;
54 $line
57 while (<STDIN>) { print STDOUT substitute($_); }