summarylogtreecommitdiffstats
path: root/libnss-unknown.install
diff options
context:
space:
mode:
authorArnaud Rebillout2019-08-08 11:16:02 +0700
committerArnaud Rebillout2019-08-08 11:17:10 +0700
commitf16a0d7dc71a5b8621fab06f82d3c3799fdf19b2 (patch)
tree430560a93c0536c6bd49c24a10e6c9a79e377608 /libnss-unknown.install
downloadaur-libnss-unknown.tar.gz
Initial arch packaging
Signed-off-by: Arnaud Rebillout <arnaud.rebillout@collabora.com>
Diffstat (limited to 'libnss-unknown.install')
-rw-r--r--libnss-unknown.install45
1 files changed, 45 insertions, 0 deletions
diff --git a/libnss-unknown.install b/libnss-unknown.install
new file mode 100644
index 000000000000..62304fece576
--- /dev/null
+++ b/libnss-unknown.install
@@ -0,0 +1,45 @@
+post_install() {
+ # try to insert the unknown entry to the "passwd" and "group" lines in
+ # /etc/nsswitch.conf to automatically enable libnss-unknown support; do not
+ # change the configuration if the lines already contain "unknown"
+
+ echo "Checking NSS setup..."
+ # abort if /etc/nsswitch.conf does not exist
+ if ! [ -e /etc/nsswitch.conf ]; then
+ echo "Could not find /etc/nsswitch.conf."
+ return
+ fi
+ perl -i -pe '
+ sub insert {
+ my $line = shift;
+ # this also splits on tab
+ my @bits=split(" ", $line);
+ # do not break configuration if the line already references
+ # unknown
+ if (grep { $_ eq "unknown"} @bits) {
+ return $line;
+ }
+ # add unknown at the end
+ return $line . " unknown";
+ }
+ s/^(passwd:\s+)(.*)/$1.insert($2)/e;
+ s/^(group:\s+)(.*)/$1.insert($2)/e;
+ ' /etc/nsswitch.conf
+}
+
+post_remove() {
+ # try to remove the unknown entry from the "passwd" and "group" lines in
+ # /etc/nsswitch.conf to disable libnss-unknown support
+
+ echo "Checking NSS setup..."
+ # abort if /etc/nsswitch.conf does not exist
+ if ! [ -e /etc/nsswitch.conf ]; then
+ echo "Could not find /etc/nsswitch.conf."
+ return
+ fi
+ # we must remove possible [foo=bar] options as well
+ sed -i -r "/(passwd|group):/ s/[[:space:]]+unknown\b([[:space:]]*\[[^]]*\])*//" \
+ /etc/nsswitch.conf
+}
+
+# vim:set sw=2 et: