Add config generator scripts

This commit is contained in:
Matthias Schiffer 2013-09-28 18:39:32 +02:00
parent fc6ad3d6f4
commit 35a20e256c
3 changed files with 72 additions and 0 deletions

View File

@ -115,6 +115,10 @@ src-link luci ../../packages_luci
endef
export FEEDS
export GLUON_GENERATE := $(GLUONDIR)/scripts/generate.sh
feeds: FORCE
rm -f feeds.conf
echo "$$FEEDS" > feeds.conf

40
scripts/configure.pl Executable file
View File

@ -0,0 +1,40 @@
#!/usr/bin/perl
use warnings;
use strict;
my %config;
sub add_config {
my ($prefix, $c) = @_;
foreach my $key (keys $c) {
my $val = $c->{$key};
if (ref($val)) {
add_config($key . '.', $val);
}
else {
$config{'@' . $prefix . $key . '@'} = $val;
}
}
}
sub read_config {
my $input = shift;
my $CONFIG = do $input;
add_config('', $CONFIG);
}
read_config 'site/site.pl';
my $regex = join '|', map {quotemeta} keys %config;
for (<>) {
s/($regex)/${config{$1}}/g;
print;
}

28
scripts/generate.sh Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
declare -a IN
GLUONDIR="$(dirname "$0")/.."
for ((i = 1; i < $#; i++)); do
IN[$i]="${!i}"
done
OUT="$(readlink -f "${!#}")"
for S in "${IN[@]}"; do (
cd "$(dirname "$S")"
NAME="$(basename "$S")"
IFS='
'
for FILE in $(find "$NAME" -type f); do
D="$(dirname "$FILE")"
mkdir -p "$OUT/$D"
(cd "$GLUONDIR"; scripts/configure.pl) < "$FILE" > "$OUT/$FILE"
chmod --reference="$FILE" "$OUT/$FILE"
done
); done