Skip to content

Commit

Permalink
Added standard scripts to Makefile
Browse files Browse the repository at this point in the history
Also cleaned up the following:
  microseconds
  milliseconds
  nanoseconds
  pgp_verify
  pvim
  seconds

userlist: Added licence info

Added doc/userlist.md (from Google+ post)
  • Loading branch information
unixnut committed Nov 18, 2014
1 parent b0d1176 commit 8219e3c
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 15 deletions.
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
PREFIX=/usr/local
USER_SCRIPTS=aws-host-fingerprints find_swapfiles seconds milliseconds \
microseconds nanoseconds pem-foreach pgp_verify showcn \
smooth _s.sh
# ... TO-DO: mkhtml or makehtml
ADMIN_SCRIPTS=clowncar zonedate

.PHONY: install install_user install_admin install_doc
install: install_user install_admin install_doc

install_user: $(PREFIX)/bin $(USER_SCRIPTS:%=$(PREFIX)/bin/%)

install_admin: $(PREFIX)/sbin $(ADMIN_SCRIPTS:%=$(PREFIX)/sbin/%)

install_doc: $(PREFIX)/share/doc/smooth $(PREFIX)/share/doc/smooth/smooth.md \
$(PREFIX)/share/doc/userlist $(PREFIX)/share/doc/userlist/userlist.md

$(PREFIX)/bin/_s.sh: _s.sh
install -p -m 644 '$^' '$@'

$(PREFIX)/bin $(PREFIX)/sbin:
install -d $@

$(PREFIX)/share/doc/smooth/smooth.md: doc/s\ for\ smooth\ source\ control.md
install -p -m 644 '$^' '$@'

$(PREFIX)/share/doc/smooth:
install -d -p $@

$(PREFIX)/share/doc/userlist/userlist.md: doc/userlist.md
install -p -m 644 '$^' '$@'

$(PREFIX)/share/doc/userlist:
install -d -p $@

$(PREFIX)/bin/%: %
install -p '$<' '$@'

$(PREFIX)/sbin/%: %
install -p '$<' '$@'

_s.sh: doc/s\ for\ smooth\ source\ control.md
(sed -n -e 's/^| `s \*\*\([^*]*\)\*\*\([^` (]*\)` *| *`\(svn[^`]*\).*/r_svn[\1\2]="\3"\nr_svn[\1]="\3"/p' \
-e 's/^| `s \*\*\([^*]*\)\*\*` (\([^)]*\)) *| *`\(svn[^`]*\).*/r_svn[\1]="\3"\nr_svn[\2]="\3"/p' \
Expand Down
15 changes: 15 additions & 0 deletions doc/userlist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Ever wanted the ability to list Unix/Linux users from the command line, leaving
out system users by default?  [userlist]() does this. (See the help() function
for usage information.)

By default, **userlist** runs in privileged mode, showing password and account
expiry information (including user status: active/disabled/expired).  This mode
requires it to be run as the root user.  It can optionally show information
from the passwd file like full name, and/or group information, for each user.  

When run in unprivileged mode, **userlist** just shows passwd file information
and optional group information.

**userlist** is also designed to have its output redirected to a file or piped
to **less**, in which case it can be told to output all information for each
user on a single line.
4 changes: 3 additions & 1 deletion microseconds
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
date +%s%6N
#! /bin/sh

date "$@" +%s%6N
4 changes: 3 additions & 1 deletion milliseconds
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
date +%s%3N
#! /bin/sh

date "$@" +%s%3N
4 changes: 3 additions & 1 deletion nanoseconds
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
date +%s%N
#! /bin/sh

date "$@" +%s%N
6 changes: 5 additions & 1 deletion pgp_verify
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#! /bin/bash
#
#
# Shows concise output as to whether or not someone in our keyring
# (we don't care who) has verified the signature on the given file.
#
# Usage: pgp_verify <file> <sigfile>
gpg --quiet --no-verbose --batch --output - --verify "$1" "$2" 2> >(egrep -v "^gpg: (Signature made | aka )")

2 changes: 2 additions & 0 deletions pvim
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh
# pvim (Bourne shell script) -- captures standard input & edits it with vim
#
# Usage: pvim [ -t ] [ -d ] [ -r | -g ] [ <file_name> ]
#
# pvim prompts for a file name (if <file_name> was not specified) then copies
# standard input into it and edits it with vim. If <file_name> was prompted
# for, or if the -t option was specified, then the file will be created in
Expand Down
4 changes: 3 additions & 1 deletion seconds
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
date +%s
#! /bin/sh

date "$@" +%s
40 changes: 30 additions & 10 deletions userlist
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
#! /bin/sh
# userlist (Bourne shell script) -- list one or all users, with password and expiry info
#
# Version: 1.1
# Copyright: (c) 2014 Alastair Irvine <[email protected]>
# Licence: This project is released under the GNU General Public License
#
# See help() for usage.
#
# Note: Because it accesses the shadow database, userlist should be run as root.
# Otherwise it shows a warning and a minimal listing equivalent to -u.
#
# Licence:
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# See http://www.gnu.org/licenses/gpl-2.0.html for more information.
#
# You can find the complete text of the GPLv2 in the file
# /usr/share/common-licenses/GPL-2 on Debian systems.
# Or see the file COPYING in the same directory as this program.
#
#
# TO-DO:
# rainbow mode, which outputs all 14 pieces of information printed
# for each user in a different colour.
# + Rainbow mode, which outputs all 14 pieces of information printed
# for each user in a different colour.
# + Output phone numbers, etc.
# + check if today has to be past the expiry date to count as expired


self=`basename $0`
allowed_options=s:xXdqvhcCwogu
Expand Down Expand Up @@ -46,7 +66,8 @@ Options:
-h, --help Show this help
Output:
The Status column is one of: active, disabled, expired.
The Status column is one of: active, disabled, expired. (Note: This is
limited in unprivileged mode, and is left out unless verbose mode is active.)
The Password column is one of: set, locked, LOCKED, BLANK, none.
Expand All @@ -55,11 +76,11 @@ Output:
Remaining and Age are calculated by userlist, relative to today.
Important info:
"none" means a specific invalid crypt, used to create the account disabled.
"LOCKED" is a blank password that is locked, which isn't dangerous because
passwd refuses to unlock an account if doing so would make it passwordless.
"none" means a specific invalid crypt, used to create the account disabled.
SSH keys (or other methods), if configured, can be used to log into *any*
account with *any* Status (except "expired") or Password state.
EOT_HELP
Expand All @@ -80,7 +101,7 @@ process_users_full()
if [ $verbose -ge 1 ] ; then
printf "$eol$bold $passwd_header_format$normal" \
"Full name" UID GID "Login shell" "Home directory"
## # TO-DO: output phone numbers, etc.
## # output phone numbers, etc.
## if [ $verbose -ge 2 ] ; then
## printf " \n" ...
## fi
Expand All @@ -101,7 +122,6 @@ process_users_full()
if [ -z "$expire_date" ] ; then
remaining_days=-
else
# TO-DO: check if it has to be past the date to count as expired
if [ $expire_date -lt $today ] ; then
status=expired
fi
Expand Down Expand Up @@ -151,7 +171,7 @@ process_users_full()
if [ $verbose -ge 1 ] ; then
printf "$eol $passwd_field_format" \
"${gecos%%,*}" $uid $gid $loginshell $homedir
## # TO-DO: output phone numbers, etc.
## # output phone numbers, etc.
## if [ $verbose -ge 2 ] ; then
## printf "$eol " ...
## fi
Expand All @@ -175,7 +195,7 @@ $([ $verbose -ge 1 ] && echo "$status_field_format ")\
$passwd_header_format$normal" \
Username $([ $verbose -ge 1 ] && echo Status) \
"Full name" UID GID "Login shell" "Home directory"
## # TO-DO: output phone numbers, etc.
## # output phone numbers, etc.
## if [ $verbose -ge 2 ] ; then
## printf "$eol " ...
## fi
Expand All @@ -199,7 +219,7 @@ $passwd_header_format$normal" \
$([ $verbose -ge 1 ] && echo "$status_field_format ")$passwd_field_format" \
$username $([ $verbose -ge 1 ] && echo $status) \
"${gecos%%,*}" $uid $gid $loginshell $homedir
## # TO-DO: output phone numbers, etc.
## # output phone numbers, etc.
## if [ $verbose -ge 2 ] ; then
## printf "$eol " ...
## fi
Expand Down

0 comments on commit 8219e3c

Please sign in to comment.