1 #!/usr/bin/perl
3 $pkgdevice = $ARGV[0] || die "Unable to determine device ($!)\n";
5 $find = "/usr/bin/find";
6 $pkgproto = "/usr/bin/pkgproto";
7 $pkgmk = "/usr/bin/pkgmk";
8 $pkgtrans = "/usr/bin/pkgtrans";
9 $prototype = "prototype";
10 $pkginfo = "pkginfo";
12 # Sanity check
14 $pwd = `pwd`;
15 if ($pwd =~ '\/usr\/local') {
16 $pwd = $`;
17 }
18 die "Wrong location, please cd to <PKGBASE>/usr/local/ and run again.\n"
19 if ($pwd eq "");
21 open (PREPROTO,"$find . -print |$egrep -v \"^.(/usr(/local)|/opt)?\$\" | $pkgproto |") ||
22 die "Unable to read prototype information ($!)\n";
23 open (PROTO,">$prototype") ||
24 die "Unable to write file prototype ($!)\n";
25 print PROTO "i pkginfo=./$pkginfo\n";
26 while (<PREPROTO>) {
27 # Read in the prototype information
28 chomp;
29 $thisline = $_;
30 if ($thisline =~ " prototype "
31 or $thisline =~ " pkginfo ") {
32 # Don't do anything as they aren't important
33 } elsif ($thisline =~ "^[fd] ") {
34 # Change the ownership of files and directories
35 ($dir, $none, $file, $mode, $user, $group) = split / /,$thisline;
36 print PROTO "$dir $none $file $mode bin bin\n";
37 } else {
38 # Symlinks and other stuff should be printed also
39 print PROTO "$thisline\n";
40 }
41 }
42 close PROTO;
43 close PREPROTO;
45 # Now we can start building the package
47 $os = `uname -r`;
48 $os =~ '\.';
49 $os = "sol$'";
50 chomp $os;
52 open (PKGINFO,"<$pkginfo") ||
53 die "Unable to read package information ($!)\n";
54 while (<PKGINFO>) {
55 # Read in the package information
56 chomp;
57 $thisline = $_;
58 ($var,$value) = split /=/,$thisline;
59 if ("$var" eq "NAME"
60 or "$var" eq "VERSION"
61 or "$var" eq "ARCH") {
62 $tmp = lc($var);
63 $value =~ s/\"//g;
64 if ("$tmp" eq "version"
65 and $value =~ ",REV") {
66 ($value,$var) = split /\,/,$value;
67 $$tmp = $value;
68 } else {
69 $$tmp = $value;
70 }
71 }
72 }
73 close PKGINFO;
75 $packagename = "$name-$version-$os-$arch-local";
77 print "Building package\n";
78 system ("$pkgmk -o -r `pwd` -d $pkgdevice");
79 system ("(cd $pkgdevice && $pkgtrans -s `pwd` ../$packagename)");
80 print "Done. ($packagename)\n";