#! /usr/bin/perl
# Copyright (C) 2010-2016 by Dirk Krause. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
#
# Hash table containing dirname=1 for directory
# names to ignore (to avoid conflicts).
#
my %dirs_to_ignore;
$dirs_to_ignore{"/usr"} = 1;
$dirs_to_ignore{"/usr/share"} = 1;
$dirs_to_ignore{"/usr/share/man"} = 1;
$dirs_to_ignore{"/usr/share/man/man1"} = 1;
$dirs_to_ignore{"/usr/share/man/man2"} = 1;
$dirs_to_ignore{"/usr/share/man/man3"} = 1;
$dirs_to_ignore{"/usr/share/man/man4"} = 1;
$dirs_to_ignore{"/usr/share/man/man5"} = 1;
$dirs_to_ignore{"/usr/share/man/man6"} = 1;
$dirs_to_ignore{"/usr/share/man/man7"} = 1;
$dirs_to_ignore{"/usr/share/applications"} = 1;
$dirs_to_ignore{"/usr/include"} = 1;
$dirs_to_ignore{"/usr/bin"} = 1;
$dirs_to_ignore{"/usr/sbin"} = 1;
$dirs_to_ignore{"/usr/lib"} = 1;
$dirs_to_ignore{"/usr/lib/pkgconfig"} = 1;
$dirs_to_ignore{"/usr/libexec"} = 1;
$dirs_to_ignore{"/usr/libexec/filters"} = 1;
$dirs_to_ignore{"/etc"} = 1;
$dirs_to_ignore{"/var"} = 1;
$dirs_to_ignore{"/var/run"} = 1;
$dirs_to_ignore{"/var/spool"} = 1;
$dirs_to_ignore{"/var/log"} = 1;
$dirs_to_ignore{"/var/tmp"} = 1;
$dirs_to_ignore{"/usr/local"} = 1;
$dirs_to_ignore{"/usr/local/share"} = 1;
$dirs_to_ignore{"/usr/local/share/man"} = 1;
$dirs_to_ignore{"/usr/local/share/man/man1"} = 1;
$dirs_to_ignore{"/usr/local/share/man/man2"} = 1;
$dirs_to_ignore{"/usr/local/share/man/man3"} = 1;
$dirs_to_ignore{"/usr/local/share/man/man4"} = 1;
$dirs_to_ignore{"/usr/local/share/man/man5"} = 1;
$dirs_to_ignore{"/usr/local/share/man/man6"} = 1;
$dirs_to_ignore{"/usr/local/share/man/man7"} = 1;
$dirs_to_ignore{"/usr/local/share/applications"} = 1;
$dirs_to_ignore{"/usr/local/include"} = 1;
$dirs_to_ignore{"/usr/local/bin"} = 1;
$dirs_to_ignore{"/usr/local/sbin"} = 1;
$dirs_to_ignore{"/usr/local/lib"} = 1;
$dirs_to_ignore{"/usr/local/lib/pkgconfig"} = 1;
$dirs_to_ignore{"/usr/local/libexec"} = 1;
$dirs_to_ignore{"/usr/local/libexec/filters"} = 1;
$dirs_to_ignore{"/usr/local/etc"} = 1;
$dirs_to_ignore{"/usr/local/var"} = 1;
$dirs_to_ignore{"/usr/local/var/run"} = 1;
$dirs_to_ignore{"/usr/local/var/spool"} = 1;
$dirs_to_ignore{"/usr/local/var/log"} = 1;
$dirs_to_ignore{"/usr/local/var/tmp"} = 1;
sub getpwd() {
my $back = undef;
my $line;
if(open(INPUT, "pwd |")) {
while() {
$line = $_; chomp $line;
if($line =~ /\S+/o) {
$back = $line;
}
}
close(INPUT);
}
return $back;
}
my $cwd = getpwd();
my @files = (
"compver", "depend", "space", "copyright", "request",
"checkinstall", "preinstall", "postinstall",
"preremove", "postremove", "pkginfo"
);
if(open(OUTPUT, ">prototype")) {
if( -f "pkginfo") {
system("chmod 644 pkginfo");
print OUTPUT "i pkginfo=$cwd/pkginfo\n";
foreach my $i (@files) {
if( -f "$i" ) {
if ( "$i" ne "pkginfo" ) {
system("chmod 644 $i");
print OUTPUT "i $i=$cwd/$i\n";
}
}
}
if(open(INPUT, "find . -type d -print |")) {
my $line;
while() {
$line = $_; chomp $line;
if("$line" ne ".") {
if($line =~ /^\.(.*)$/o) {
$line = $1;
}
if ( ! ( exists( $dirs_to_ignore{"$line"} ) ) ) {
print OUTPUT "d none $line 0755 bin bin\n";
}
}
}
close(INPUT);
}
if(open(INPUT, "find . -type f |")) {
my $mode = "0644";
my $line;
my $must_use_this;
while() {
$line = $_; chomp $line;
$must_use_this = 1;
$mode = "0644";
foreach my $i (@files) {
if ("$i" eq "$line") {
$must_use_this = 0;
}
if ("/$i" eq "$line") {
$must_use_this = 0;
}
if ("./$i" eq "$line") {
$must_use_this = 0;
}
}
if($line =~ /^\.(.*)$/o) {
$line = $1;
}
if("$line" ne "prototype") {
if("$line" ne "/prototype") {
if($line =~ /\/bin\//o) {
$mode = "0755";
}
if($line =~ /\/sbin\//o) {
$mode = "0755";
}
if($line =~ /\/libexec\//o) {
$mode = "0755";
}
if($must_use_this) {
print OUTPUT "f none $line=$cwd$line";
print OUTPUT " $mode bin bin\n";
}
}
}
}
close(INPUT);
}
if(open(INPUT, "find . -type l |")) {
my $mode = "0644";
my $line;
my $must_use_this;
my $target;
my $l2;
my $origline;
while() {
$line = $_; chomp $line;
$origline = $line;
$must_use_this = 1;
$mode = "0644";
$target = undef;
foreach my $i (@files) {
if ("$i" eq "$line") {
$must_use_this = 0;
}
if ("/$i" eq "$line") {
$must_use_this = 0;
}
if ("./$i" eq "$line") {
$must_use_this = 0;
}
}
if($line =~ /^\.(.*)$/o) {
$line = $1;
}
if("$line" ne "prototype") {
if("$line" ne "/prototype") {
if($line =~ /\/bin\//o) {
$mode = "0755";
}
if($line =~ /\/sbin\//o) {
$mode = "0755";
}
if($line =~ /\/libexec\//o) {
$mode = "0755";
}
if (open(IN2, "ls -l \"$origline\" |")) {
while() {
$l2 = $_; chomp $l2;
if ("$l2" =~ /.*\->\s+(\S.*)/o) {
$target = $1;
}
}
close(IN2);
if(($must_use_this) && (defined($target))) {
print OUTPUT "s none $line=$target";
print OUTPUT " $mode bin bin\n";
}
}
}
}
}
close(INPUT);
}
} else {
print "dkmkproto: ERROR: Missing pkginfo file!\n";
}
close(OUTPUT);
}