Skip to content
This repository
tag: REL_4_8_5
Fetching contributors…

Cannot retrieve contributors at this time

executable file 141 lines (117 sloc) 3.621 kb
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
#! /usr/bin/perl -w
#
# Copyright 2001 by Stefan Hornburg (Racke) <racke@linuxia.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA.

use strict;

# constants we use
my $lock_ex = 2;
my $lock_un = 8;

# configuration files which we modify
my $featconf = '/etc/interchange/features.cfg';
my $settingsconf = '/etc/interchange/settings.cfg';

# Interchange variables
my %setvars = (DEBUG => 0, UI_LOCALE => 'en_US');
my %featvars = (UI => '', USE_FOUNDATION => '');
my %skipvars;

# other variables
my (@tokens, $varref);

# parse commandline
for (@ARGV) {
unless (/\S+=/) {
die "$0: invalid parameter '$_'\n";
}
@tokens = split(/=/);
if (exists($setvars{$tokens[0]})) {
$varref = \%setvars;
} elsif (exists($featvars{$tokens[0]})) {
$varref = \%featvars;
} else {
die "$0: no such variable $tokens[0]\n";
}
if (defined $tokens[1]) {
$varref->{$tokens[0]} = $tokens[1];
} else {
$varref->{$tokens[0]} = '';
}
# don't override these settings
$skipvars{$tokens[0]} = 1;
}

# modify features configuration
&update_configfile($featconf, 0, \%featvars);

# modify settings configuration
&update_configfile($settingsconf, 1, \%setvars);

sub update_configfile {
my ($configfile, $modsallowed, $varref) = @_;

if (-f $configfile) {
open (SCONF, "+<$configfile")
|| die ("$0: Couldn't open $configfile: $!\n");
flock (SCONF, $lock_ex);
while (<SCONF>) {
# strip leading/trailing whitespace
s/^\s+//; s/^\s+$//;
# skip comment lines/blank lines
next if /^\#/; next unless /\S/;
# check for "Variable"'s
@tokens = split (/\s+/, $_, 3);
next if $tokens[0] ne 'Variable';
next if exists $skipvars{$tokens[1]};
# record values found
if (exists $varref->{$tokens[1]}) {
if (defined $tokens[2]) {
$varref->{$tokens[1]} = $tokens[2];
} else {
$varref->{$tokens[1]} = '';
}
}
}
truncate (SCONF, 0)
|| die ("$0: Couldn't truncate $configfile: $!\n");
seek (SCONF, 0, 0)
|| die ("$0: Seek failed on $configfile: $!\n");
} else {
open (SCONF, ">$configfile")
|| die ("$0: Couldn't open $configfile: $!\n");
}

if ($modsallowed) {
print SCONF <<EOF;
# This file is automatically generated by $0.
# You may modify this file, but this is NOT recommended.

EOF
    } else {
print SCONF <<EOF;
# This file is automatically generated by $0.
# You may NOT modify this file, because it reflects the
# installation state of the Interchange packages.

EOF
}

for (sort (keys %$varref)) {
print SCONF "Variable $_ $varref->{$_}\n";
}
flock (SCONF, $lock_un);
close (SCONF)
|| die ("$0: Couldn't close $configfile: $!\n");
}


=head1 NAME

interchangeconfig - Updates Debian specific Interchange configuration files

=head1 DESCRIPTION

interchangeconfig reads and writes the Interchange configuration files
/etc/interchange/features.cfg and /etc/interchange/settings.cfg.

=head1 AUTHOR

Stefan Hornburg (Racke), racke@linuxia.de

=head1 SEE ALSO

interchange(1p)

=cut
Something went wrong with that request. Please try again.