watch: add 'watch' support
[girocco/ztw.git] / config.pl
blob4e61b5e5fc5ba552996bacbb0ffa63ce61b80ae7
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 web_path => "$home_path/www",
12 log_path => "/var/log/apache2",
14 bin_path => "$home_path/bin",
15 jail_path => "$home_path/jail",
16 repomgr_path => "$home_path/repomgr",
17 repodata_path => "$home_path/repodata",
18 repo_path => "$home_path/repos",
20 group_file => '/etc/group',
21 user_file => '/etc/passwd',
22 sshkeys_path => '/etc/sshkeys',
24 doghouse_path => '/etc/watchdogs',
26 my @keys = map { $config[$_ * 2] } 0 .. (@config / 2 - 1);
28 my $config = 'config.txt';
29 my $update = @ARGV && $ARGV[0] eq '-u';
31 sub read_config {
32 open F, "<$config" or die $!;
33 my %config;
34 for (<F>) {
35 chomp;
36 next if /^\s*$/ || /^#/;
37 my ( $key, $value ) = split(/=/, $_);
38 $config{$key} = $value;
40 close F or die $!;
41 %config
44 my %config = @config;
45 my $settings = read_config if -f $config;
47 if ($update || ! -f $config ) {
48 open F, ">$config" or die $!;
49 print F "# repository manager site parameters\n";
50 print F $_, "=", $config{$_}, "\n" for @keys;
51 close F or die $!;
52 exit
54 read_config;
56 sub substitute {
57 my $line = shift;
58 $line =~ s/\@$_\@/$config{$_}/ for @keys;
59 $line
62 while (<STDIN>) { print STDOUT substitute($_); }