forked from BerndStorck/parsePasswd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parpass
executable file
·122 lines (101 loc) · 3.07 KB
/
parpass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#! /bin/bash
#
# parpass 1.1.1 - 2020-06-16
#
# Reads the password file /etc/passwd and search for user names which
# begin with $1, and parses the record for printing it in human
# readable form to the screen.
#
# Bernd Storck
#
# Contact: https://www.facebook.com/BStLinux/
#
SCRIPT="parpass"
TITLE="$SCRIPT (parsePasswd)"
VERSION="1.1.1"
OLDIFS="$IFS"
IFS=":"
if [ "$(echo "$LANG" | cut -c 1-2)" == "de" ]; then
UILANG="Deutsch"
label_ID="IDs (uid/gid)"
label_homeDir="Verzeichnis"
label_loginShell="Login-Shell"
label_realName="Realname"
label_room="Zimmer"
label_workPhone="Telefon"
label_phone="Privat"
label_comment="Kommentar";
else
UILANG="English"
label_ID="IDs (uid/gid)"
label_homeDir="Directory"
label_loginShell="Login Shell"
label_realName="Real Name"
label_room="Room"
label_workPhone="Work Fon"
label_phone="Home Phone"
label_comment="Comment";
fi
function hilfe () {
# Displays program purpose and usage help.
echo -e "\e[1;33m$TITLE $VERSION \e[0m\n"
if [ "$UILANG" == "Deutsch" ]; then
echo -e "Das Programm liest die Passwortdatei \"/etc/passwd\" und zeigt ihren Inhalt gut lesbar an.
AUFRUFPARAMETER DER FUNKTION \"$SCRIPT\":
--help|-h|--hilf Diese Hilfe anzeigen
BEISPIELAUFRUFE:
\033[1;32mAufruf Beschreibung\033[0m
$SCRIPT root # Zeigt die Daten aus der passwd zum Account root an.
$SCRIPT bs # Zeigt die Daten zu allen Accounts an, die mit \"bs\" beginnen.
$SCRIPT # Zeigt die Daten aus der Datei passwd zu allen Accounts an.
"
else # English help:
echo -e "Reads the password file \"/etc/passwd\" and displays it's content human readable at the screen.
PARAMETERS:
--help|-h|--hilf Show this help
EXAMPLES:
\033[1;32mCall Description\033[0m
$SCRIPT root # Shows information from passwd according to the account \"root\".
$SCRIPT bs # Shows information about all accounts, which do begin with \"bs\".
$SCRIPT # Shows information from file \"passwd\" for all accounts.\n"
fi
}
function printField() {
# Writes pairs of field name and filed content to a temporary file, so
# that the result can be reformatted at the end, when complete.
echo -e "\t\e[1;37m${2}:\e[0m# ${1}" >> /tmp/parpass.tmp
}
function printNotEmpty() {
if [ "$1" != "" ]; then
printField "$1" "$2"
fi
}
### main ###################
case "$1" in
--help|-h|--hilf|-help)
hilfe
exit 0
;;
esac
rm -f /tmp/parpass.tmp
while read -r user trash uid gid data homeDir loginShell
do
if grep -i -q "^$1" <<< "$user" > /dev/null 2>&1; then
echo -e "\n\e[1;93m${user} \e[0;33m------------------------------------------------\e[0m";
printField "$uid / $gid" "$label_ID"
printField "$homeDir" "$label_homeDir"
printField "$loginShell" "$label_loginShell"
IFS=','
read -r realName room workPhone phone comment <<< "$data"
printNotEmpty "$realName" "$label_realName"
printNotEmpty "$room" "$label_room"
printNotEmpty "$workPhone" "$label_workPhone"
printNotEmpty "$phone" "$label_phone"
printNotEmpty "$comment" "$label_comment"
IFS=':'
column -s# -t /tmp/parpass.tmp
rm /tmp/parpass.tmp
fi
done < "/etc/passwd"
IFS="$OLDIFS"
exit 0