-
Notifications
You must be signed in to change notification settings - Fork 0
/
lockusr
66 lines (56 loc) · 1.35 KB
/
lockusr
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
#!/usr/bin/env bash
#
###############################################################################
# Environment
###############################################################################
# $_ME
#
# This program's basename.
_ME="$(basename "${0}")"
###############################################################################
# Help
###############################################################################
# _print_help()
#
# Usage:
# _print_help
#
# Print the program help information.
_print_help() {
cat <<HEREDOC
Program to lock a user and remove them from all but their primary group. Also,
their home directory and its contents will be moved to "/locked_users"
Usage:
${_ME} USERNAME
Options:
-h --help Show this screen.
HEREDOC
}
_usage() {
echo "Usage: ${_ME} USERNAME"
}
###############################################################################
# Main
###############################################################################
_main() {
if [[ -z "${1:-}" ]]
then
usage
exit 1
else
if [[ "${1}" =~ ^-h|--help$ ]]
then
_print_help
else
usermod -L "${1}"
usermod -G "${1}" "${1}"
if [[ ! -d /locked_users ]]
then
mkdir /locked_users
fi
mv /home/"${1}" /locked_users/"${1}"
fi
fi
}
# Call `_main` after everything has been defined.
_main "$@"