Page MenuHomeDevCentral

D137.id330.diff
No OneTemporary

D137.id330.diff

diff --git a/roles/shellserver/user-session/Makefile b/roles/shellserver/user-session/Makefile
new file mode 100644
--- /dev/null
+++ b/roles/shellserver/user-session/Makefile
@@ -0,0 +1,7 @@
+PREFIX=/usr/local
+INSTALL=install
+INSTALL_DATA=${INSTALL} -m 0644
+
+install:
+ ${INSTALL_DATA} files/csh.logout /etc/
+ ${INSTALL} files/whom files/whom-diff ${PREFIX}/bin/
diff --git a/roles/shellserver/user-session/README.md b/roles/shellserver/user-session/README.md
new file mode 100644
--- /dev/null
+++ b/roles/shellserver/user-session/README.md
@@ -0,0 +1,17 @@
+This component provides commands and configuration files
+used by the users' shells.
+
+[ whom-diff ]
+
+We provide the following files:
+
+* `whom` prints by alphabetical order the list of connected users
+* `whom-diff` looks for difference with previous call and prints it
+* /etc/csh.logout takes care of cleanup
+
+To enable it, add to ~/.cshrc:
+
+```lang=sh,name=.cshrc
+setenv SESSION_ID `whom-diff -s`
+alias precmd whom-diff
+```
diff --git a/roles/shellserver/user-session/files/csh.logout b/roles/shellserver/user-session/files/csh.logout
new file mode 100644
--- /dev/null
+++ b/roles/shellserver/user-session/files/csh.logout
@@ -0,0 +1,13 @@
+# -------------------------------------------------------------
+# System-wide .logout file for csh(1)
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Author: Sébastien Santoro aka Dereckson
+# Created: 2015-12-30
+# Licence: Trivial work, not eligible to copyright
+# -------------------------------------------------------------
+
+# -------------------------------------------------------------
+# Cleans up whom-diff files
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+whom-diff --clean
diff --git a/roles/shellserver/user-session/files/whom b/roles/shellserver/user-session/files/whom
new file mode 100755
--- /dev/null
+++ b/roles/shellserver/user-session/files/whom
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+# -------------------------------------------------------------
+# Clean alternative to who
+# Prints the usernames of connected users by alphabetical order
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Author: Sébastien Santoro aka Dereckson
+# Created: 2015-12-30
+# Licence: Trivial work, not eligible to copyright
+# -------------------------------------------------------------
+
+who | awk '{print $1}' | sort | uniq
diff --git a/roles/shellserver/user-session/files/whom-diff b/roles/shellserver/user-session/files/whom-diff
new file mode 100755
--- /dev/null
+++ b/roles/shellserver/user-session/files/whom-diff
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+# -------------------------------------------------------------
+# whom-diff
+#
+# Computes the diff between two `whom` invoke.
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Author: Sébastien Santoro aka Dereckson
+# Created: 2015-12-30
+# Licence: BSD-2-Clause
+# -------------------------------------------------------------
+
+# -------------------------------------------------------------
+# Determines session identifier and directory
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+if [ "$SESSION_ID" = "" ]; then
+ SESSION_ID=`who am I | md5 | cut -c1-8`
+fi
+
+DIR=/var/tmp/whom/$USER/$SESSION_ID
+
+# -------------------------------------------------------------
+# -s / --session
+# Prints the session identifier
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+if [ "$1" = "--session" ] || [ "$1" = "-s" ]; then
+ echo $SESSION_ID
+ exit 0
+fi
+
+# -------------------------------------------------------------
+# Default mode
+#  Prints the diff between current `whom` and previous output
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+if [ $# -eq 0 ]; then
+ # Creates working directory if needed
+ if [ ! -d $DIR ]; then
+ mkdir -p $DIR
+ touch $DIR/old
+ fi
+
+ # Let's diff
+ cd $DIR
+ whom > current
+ diff old current | tail -n +2
+ mv current old
+
+ exit 0
+fi
+
+# -------------------------------------------------------------
+# -c / --clean
+# Cleans directory
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+if [ "$1" = "--clean" ] || [ "$1" = "-c" ]; then
+ rm -rf $DIR
+ exit $?
+fi
+
+# -------------------------------------------------------------
+# Usage
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+>&2 echo "Usage: $0 [--setup|--clean|-s|-c]"
+exit 1

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 18, 01:56 (21 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2249912
Default Alt Text
D137.id330.diff (4 KB)

Event Timeline