Skip to content
This repository was archived by the owner on Nov 8, 2021. It is now read-only.

Commit 1196ff4

Browse files
authored
Add ability to config user deletion program & args (#156)
This adds two new configuration options. USERDEL_PROGRAM and USERDEL_ARGS. They allow users to configure how users are deleted via the configuration file.
1 parent 2995794 commit 1196ff4

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ LOCAL_MARKER_GROUP="iam-synced-users" # Dedicated UNIX group to mark im
114114
LOCAL_GROUPS="GROUPNAMES" # Comma seperated list of UNIX groups to add the users in
115115
USERADD_PROGRAM="/usr/sbin/useradd" # The useradd program to use. defaults to `/usr/sbin/useradd`
116116
USERADD_ARGS="--create-home --shell /bin/bash" # Arguments for the useradd program. defaults to `--create-home --shell /bin/bash`
117+
USERDEL_PROGRAM="/usr/sbin/userdel" # The userdel program to use. defaults to `/usr/sbin/userdel`
118+
USERDEL_ARGS="--force --remove" # Arguments for the userdel program. defaults to `--force --remove`
117119
```
118120

119121
The LOCAL_MARKER_GROUP will be created if it does not exist. BEWARE: DO NOT add any manually created users

import_users.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ fi
5454
# Possibility to provide custom useradd arguments
5555
: ${USERADD_ARGS:="--user-group --create-home --shell /bin/bash"}
5656

57+
# Possibility to provide a custom userdel program
58+
: ${USERDEL_PROGRAM:="/usr/sbin/userdel"}
59+
60+
# Possibility to provide custom userdel arguments
61+
: ${USERDEL_ARGS:="--force --remove"}
62+
5763
# Initizalize INSTANCE variable
5864
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
5965
REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}')
@@ -211,7 +217,8 @@ function delete_local_user() {
211217
/usr/bin/pkill -9 -u "${1}" || true
212218
sleep 1
213219
# Remove account now that all processes for the user are gone
214-
/usr/sbin/userdel -f -r "${1}"
220+
${USERDEL_PROGRAM} ${USERDEL_ARGS} "${1}"
221+
215222
log "Deleted user ${1}"
216223
}
217224

install.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ LOCAL_GROUPS=""
4242
ASSUME_ROLE=""
4343
USERADD_PROGRAM=""
4444
USERADD_ARGS=""
45+
USERDEL_PROGRAM=""
46+
USERDEL_ARGS=""
4547
RELEASE="master"
4648

47-
while getopts :hva:i:l:s:p:u:r: opt
49+
while getopts :hva:i:l:s:p:u:d:f:r: opt
4850
do
4951
case $opt in
5052
h)
@@ -72,6 +74,12 @@ do
7274
u)
7375
USERADD_ARGS="$OPTARG"
7476
;;
77+
d)
78+
USERDEL_PROGRAM="$OPTARG"
79+
;;
80+
f)
81+
USERDEL_ARGS="$OPTARG"
82+
;;
7583
r)
7684
RELEASE="$OPTARG"
7785
;;
@@ -93,6 +101,8 @@ export LOCAL_GROUPS
93101
export ASSUME_ROLE
94102
export USERADD_PROGRAM
95103
export USERADD_ARGS
104+
export USERDEL_PROGRAM
105+
export USERDEL_ARGS
96106

97107
# check if AWS CLI exists
98108
if ! [ -x "$(which aws)" ]; then
@@ -147,6 +157,16 @@ then
147157
echo "USERADD_ARGS=\"${USERADD_ARGS}\"" >> $MAIN_CONFIG_FILE
148158
fi
149159

160+
if [ "${USERDEL_PROGRAM}" != "" ]
161+
then
162+
echo "USERDEL_PROGRAM=\"${USERDEL_PROGRAM}\"" >> $MAIN_CONFIG_FILE
163+
fi
164+
165+
if [ "${USERDEL_ARGS}" != "" ]
166+
then
167+
echo "USERDEL_ARGS=\"${USERDEL_ARGS}\"" >> $MAIN_CONFIG_FILE
168+
fi
169+
150170
./install_configure_selinux.sh
151171

152172
./install_configure_sshd.sh

0 commit comments

Comments
 (0)