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