Index: main/trunk/package-kits/linux/perllib/Greenstone/Package/_apt.pm
===================================================================
--- main/trunk/package-kits/linux/perllib/Greenstone/Package/_apt.pm	(revision 29539)
+++ main/trunk/package-kits/linux/perllib/Greenstone/Package/_apt.pm	(revision 29546)
@@ -12,3 +12,25 @@
 }
 
+sub write_function {
+    my ($self, $name, @lines) = @_;
+    open OUT, '>', "/tmp/$name";
+    for my $line (@lines) {
+        print OUT $line, "\n";
+    }
+    close OUT;
+    $self->add ("/tmp/$name", "$self->{output}/$name");
+}
+
+sub add_install {
+    my $self = shift;
+    exists $self->{config}->{PRE_INSTALL} and
+        $self->write_function ("preinst", @{$self->{config}->{PRE_INSTALL}});
+    exists $self->{config}->{POST_INSTALL} and
+        $self->write_function ("postinst", @{$self->{config}->{POST_INSTALL}});
+    exists $self->{config}->{PRE_REMOVE} and
+        $self->write_function ("prerm", @{$self->{config}->{PRE_REMOVE}});
+    exists $self->{config}->{POST_REMOVE} and
+        $self->write_function ("postrm", @{$self->{config}->{POST_REMOVE}});
+}
+
 1;
Index: main/trunk/package-kits/linux/perllib/Greenstone/Package/_pacman.pm
===================================================================
--- main/trunk/package-kits/linux/perllib/Greenstone/Package/_pacman.pm	(revision 29539)
+++ main/trunk/package-kits/linux/perllib/Greenstone/Package/_pacman.pm	(revision 29546)
@@ -38,3 +38,40 @@
 }
 
+sub write_function {
+    my ($name, $out, @lines) = @_;
+    print $out $name, "() {\n";
+    for my $line (@lines) {
+        print $out "\t", $line, "\n";
+    }
+    print $out "}\n\n";
+}
+
+sub add_install {
+    my $self = shift;
+    if (exists $self->{config}->{PRE_INSTALL} or
+        exists $self->{config}->{POST_INSTALL} or
+        exists $self->{config}->{PRE_REMOVE} or
+        exists $self->{config}->{POST_REMOVE}) {
+        my $name = "$self->{config}->{NAME}.install";
+        open my $INSTALL, '>', "/tmp/$name";
+        exists $self->{config}->{PRE_INSTALL} and do {
+            write_function "pre_install", $INSTALL, @{$self->{config}->{PRE_INSTALL}};
+            write_function "pre_upgrade", $INSTALL, @{$self->{config}->{PRE_INSTALL}};
+        };
+        exists $self->{config}->{POST_INSTALL} and do {
+            write_function "post_install", $INSTALL, @{$self->{config}->{POST_INSTALL}};
+            write_function "post_upgrade", $INSTALL, @{$self->{config}->{POST_INSTALL}};
+        };
+        exists $self->{config}->{PRE_REMOVE} and
+            write_function "pre_remove", $INSTALL, @{$self->{config}->{PRE_REMOVE}};
+        exists $self->{config}->{POST_REMOVE} and
+            write_function "post_remove", $INSTALL, @{$self->{config}->{POST_REMOVE}};
+        close $INSTALL;
+        $self->add ("/tmp/$name", "$self->{output}/$name");
+        $self->{config}->{INSTALL} = "install=$name";
+    } else {
+        $self->{config}->{INSTALL} = "";
+    }
+}
+
 1;
Index: main/trunk/package-kits/linux/perllib/Greenstone/Package/_rpm.pm
===================================================================
--- main/trunk/package-kits/linux/perllib/Greenstone/Package/_rpm.pm	(revision 29539)
+++ main/trunk/package-kits/linux/perllib/Greenstone/Package/_rpm.pm	(revision 29546)
@@ -12,3 +12,27 @@
 }
 
+sub write_function {
+    my ($name, @lines) = @_;
+    my $ret = "";
+    $ret .= "%" . $name . "\n";
+    for my $line (@lines) {
+        $ret .= $line . "\n";
+    }
+    $ret .= "\n";
+    return $ret;
+}
+
+sub add_install {
+    my $self = shift;
+    $self->{config}->{INSTALL} = "";
+    exists $self->{config}->{PRE_INSTALL} and
+        $self->{config}->{INSTALL} .= write_function "pre", @{$self->{config}->{PRE_INSTALL}};
+    exists $self->{config}->{POST_INSTALL} and
+        $self->{config}->{INSTALL} .= write_function "post", @{$self->{config}->{POST_INSTALL}};
+    exists $self->{config}->{PRE_REMOVE} and
+        $self->{config}->{INSTALL} .= write_function "preun", @{$self->{config}->{PRE_INSTALL}};
+    exists $self->{config}->{POST_REMOVE} and
+        $self->{config}->{INSTALL} .= write_function "postun", @{$self->{config}->{POST_INSTALL}};
+}
+
 1;
