From 09b99511f272f8ef9662bb36e013887082e2f3ae Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Sat, 18 Sep 2004 09:27:06 +0000 Subject: full support for @shell: insert shells into /etc/shells if they're not already there, and remove them on deinstall. --- usr.sbin/pkg_add/pkg_add | 23 ++++++++++++++++++++++- usr.sbin/pkg_add/pkg_delete | 29 ++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index 918aec4c2ab..a4fd519094d 100644 --- a/usr.sbin/pkg_add/pkg_add +++ b/usr.sbin/pkg_add/pkg_add @@ -1,7 +1,7 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_add,v 1.54 2004/09/14 22:53:17 espie Exp $ +# $OpenBSD: pkg_add,v 1.55 2004/09/18 09:27:05 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie # @@ -173,6 +173,27 @@ sub install "install-info", "--info-dir=".dirname($fullname), $fullname); } +package OpenBSD::PackingElement::Shell; +sub install +{ + my ($self, $archive, $destdir, $verbose, $not) = @_; + $self->SUPER::install($archive, $destdir, $verbose, $not); + return if $not; + my $fullname = $self->fullname(); + # go append to /etc/shells if needed + open(my $shells, '<', $destdir.'/etc/shells') or return; + local $_; + while(<$shells>) { + s/^\#.*//; + return if $_ =~ m/^\Q$fullname\E\s*$/; + } + close($shells); + open(my $shells2, '>>', $destdir.'/etc/shells') or return; + print $shells2 $fullname, "\n"; + close $shells2; + print "Shell $fullname appended to $destdir/etc/shells\n"; +} + package OpenBSD::PackingElement::Dir; sub install { diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete index ac4dda9694d..9338f85ffcf 100644 --- a/usr.sbin/pkg_add/pkg_delete +++ b/usr.sbin/pkg_add/pkg_delete @@ -1,6 +1,6 @@ #!/usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_delete,v 1.42 2004/09/14 22:58:30 espie Exp $ +# $OpenBSD: pkg_delete,v 1.43 2004/09/18 09:27:05 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie # @@ -274,6 +274,33 @@ sub delete $self->SUPER::delete($state); } +package OpenBSD::PackingElement::Shell; +sub delete +{ + my ($self, $state) = @_; + unless ($state->{not}) { + my $destdir = $state->{destdir}; + my $fullname = $self->fullname(); + my @l=(); + if (open(my $shells, '<', $destdir.'/etc/shells')) { + local $_; + while(<$shells>) { + push(@l, $_); + s/^\#.*//; + if ($_ =~ m/^\Q$fullname\E\s*$/) { + pop(@l); + } + } + close($shells); + open(my $shells2, '>', $destdir.'/etc/shells'); + print $shells2 @l; + close $shells2; + print "Shell $fullname removed from $destdir/etc/shells\n"; + } + } + $self->SUPER::delete($state); +} + package OpenBSD::PackingElement::Extra; sub delete { -- cgit v1.2.3