Replace hardcoded values with variables
This commit is contained in:
parent
7c118fd7fc
commit
d4518906b5
68
autouser.sh
68
autouser.sh
|
@ -6,6 +6,22 @@ if [[ ! -f "$FILE" ]]; then
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# User '.csv' columns
|
||||||
|
COL_USERNAME="1"
|
||||||
|
COL_FULLNAME="2"
|
||||||
|
COL_USERUID="3"
|
||||||
|
COL_USERGID="4"
|
||||||
|
COL_USERGROUPS="5"
|
||||||
|
COL_TLFN="6"
|
||||||
|
COL_EXTRAINFO="7"
|
||||||
|
COL_USERSHELL="8"
|
||||||
|
COL_USERLOCKED="9"
|
||||||
|
|
||||||
|
# Group '.csv' columns
|
||||||
|
COL_GROUPNAME="1"
|
||||||
|
COL_GROUPGID="2"
|
||||||
|
|
||||||
|
# Control variables
|
||||||
DRYRUN=false
|
DRYRUN=false
|
||||||
FILE_CONTENTS="$(cat ${@: -1})"
|
FILE_CONTENTS="$(cat ${@: -1})"
|
||||||
CREATE_USERS=false
|
CREATE_USERS=false
|
||||||
|
@ -49,8 +65,8 @@ turnLowercase()
|
||||||
createGroups ()
|
createGroups ()
|
||||||
{
|
{
|
||||||
while read line; do
|
while read line; do
|
||||||
GID=$(cutter "${line}" "2")
|
GID=$(cutter "${line}" "$COL_GROUPGID")
|
||||||
GROUPNAME=$(turnLowercase $(cutter "${line}" "1"))
|
GROUPNAME=$(turnLowercase $(cutter "${line}" "$COL_GROUPNAME"))
|
||||||
if [[ -z "$GID" ]]; then
|
if [[ -z "$GID" ]]; then
|
||||||
echo "[+] Adding group $GROUPNAME..."
|
echo "[+] Adding group $GROUPNAME..."
|
||||||
groupadd $GROUPNAME
|
groupadd $GROUPNAME
|
||||||
|
@ -64,8 +80,8 @@ createGroups ()
|
||||||
createGroupsDry ()
|
createGroupsDry ()
|
||||||
{
|
{
|
||||||
while read line; do
|
while read line; do
|
||||||
GID=$(cutter "${line}" "2")
|
GID=$(cutter "${line}" "$COL_GROUPGID")
|
||||||
GROUPNAME=$(turnLowercase $(cutter "${line}" "1"))
|
GROUPNAME=$(turnLowercase $(cutter "${line}" "$COL_GROUPNAME"))
|
||||||
if [[ -z "$GID" ]]; then
|
if [[ -z "$GID" ]]; then
|
||||||
echo "groupadd $GROUPNAME"
|
echo "groupadd $GROUPNAME"
|
||||||
else
|
else
|
||||||
|
@ -77,7 +93,7 @@ createGroupsDry ()
|
||||||
deleteGroups ()
|
deleteGroups ()
|
||||||
{
|
{
|
||||||
while read line; do
|
while read line; do
|
||||||
GROUPNAME=$(turnLowercase $(cutter "${line}" "1"))
|
GROUPNAME=$(turnLowercase $(cutter "${line}" "$COL_GROUPNAME"))
|
||||||
echo "[+] Deleting group $GROUPNAME..."
|
echo "[+] Deleting group $GROUPNAME..."
|
||||||
groupdel $GROUPNAME
|
groupdel $GROUPNAME
|
||||||
done <<< "$FILE_CONTENTS"
|
done <<< "$FILE_CONTENTS"
|
||||||
|
@ -86,7 +102,7 @@ deleteGroups ()
|
||||||
deleteGroupsDry ()
|
deleteGroupsDry ()
|
||||||
{
|
{
|
||||||
while read line; do
|
while read line; do
|
||||||
GROUPNAME=$(turnLowercase $(cutter "${line}" "1"))
|
GROUPNAME=$(turnLowercase $(cutter "${line}" "$COL_GROUPNAME"))
|
||||||
echo "groupdel $GROUPNAME"
|
echo "groupdel $GROUPNAME"
|
||||||
done <<< "$FILE_CONTENTS"
|
done <<< "$FILE_CONTENTS"
|
||||||
}
|
}
|
||||||
|
@ -94,15 +110,15 @@ deleteGroupsDry ()
|
||||||
createUsers ()
|
createUsers ()
|
||||||
{
|
{
|
||||||
while read line; do
|
while read line; do
|
||||||
USERNAME=$(turnLowercase $(cutter "${line}" "1"))
|
USERNAME=$(turnLowercase $(cutter "${line}" "$COL_USERNAME"))
|
||||||
FULLNAME=$(cutter "${line}" "2")
|
FULLNAME=$(cutter "${line}" "$COL_FULLNAME")
|
||||||
USERUID=$(cutter "${line}" "3")
|
USERUID=$(cutter "${line}" "$COL_USERUID")
|
||||||
USERGID=$(turnLowercase $(cutter "${line}" "4"))
|
USERGID=$(turnLowercase $(cutter "${line}" "$COL_USERGID"))
|
||||||
USERGROUPS=$(turnLowercase $(cutter "${line}" "5"))
|
USERGROUPS=$(turnLowercase $(cutter "${line}" "$COL_USERGROUPS"))
|
||||||
TLFN=$(cutter "${line}" "6")
|
TLFN=$(cutter "${line}" "$COL_TLFN")
|
||||||
EXTRAINFO=$(cutter "${line}" "7")
|
EXTRAINFO=$(cutter "${line}" "$COL_EXTRAINFO")
|
||||||
USERSHELL=$(cutter "${line}" "8")
|
USERSHELL=$(cutter "${line}" "$COL_USERSHELL")
|
||||||
USERLOCKED=$(cutter "${line}" "9")
|
USERLOCKED=$(cutter "${line}" "$COL_USERLOCKED")
|
||||||
|
|
||||||
echo "[+] Adding user $USERNAME..."
|
echo "[+] Adding user $USERNAME..."
|
||||||
useradd -m $USERNAME
|
useradd -m $USERNAME
|
||||||
|
@ -147,15 +163,15 @@ createUsers ()
|
||||||
createUsersDry ()
|
createUsersDry ()
|
||||||
{
|
{
|
||||||
while read line; do
|
while read line; do
|
||||||
USERNAME=$(turnLowercase $(cutter "${line}" "1"))
|
USERNAME=$(turnLowercase $(cutter "${line}" "$COL_USERNAME"))
|
||||||
FULLNAME=$(cutter "${line}" "2")
|
FULLNAME=$(cutter "${line}" "$COL_FULLNAME")
|
||||||
USERUID=$(cutter "${line}" "3")
|
USERUID=$(cutter "${line}" "$COL_USERUID")
|
||||||
USERGID=$(turnLowercase $(cutter "${line}" "4"))
|
USERGID=$(turnLowercase $(cutter "${line}" "$COL_USERGID"))
|
||||||
USERGROUPS=$(turnLowercase $(cutter "${line}" "5"))
|
USERGROUPS=$(turnLowercase $(cutter "${line}" "$COL_USERGROUPS"))
|
||||||
TLFN=$(cutter "${line}" "6")
|
TLFN=$(cutter "${line}" "$COL_TLFN")
|
||||||
EXTRAINFO=$(cutter "${line}" "7")
|
EXTRAINFO=$(cutter "${line}" "$COL_EXTRAINFO")
|
||||||
USERSHELL=$(cutter "${line}" "8")
|
USERSHELL=$(cutter "${line}" "$COL_USERSHELL")
|
||||||
USERLOCKED=$(cutter "${line}" "9")
|
USERLOCKED=$(cutter "${line}" "$COL_USERLOCKED")
|
||||||
|
|
||||||
echo "useradd -m $USERNAME"
|
echo "useradd -m $USERNAME"
|
||||||
echo "echo \"$USERNAME:$USERNAME | chpasswd\""
|
echo "echo \"$USERNAME:$USERNAME | chpasswd\""
|
||||||
|
@ -199,7 +215,7 @@ createUsersDry ()
|
||||||
deleteUsers ()
|
deleteUsers ()
|
||||||
{
|
{
|
||||||
while read line; do
|
while read line; do
|
||||||
USERNAME=$(turnLowercase $(cutter "${line}" "1"))
|
USERNAME=$(turnLowercase $(cutter "${line}" "$COL_USERNAME"))
|
||||||
echo "[+] Deleting user $USERNAME..."
|
echo "[+] Deleting user $USERNAME..."
|
||||||
userdel -r $USERNAME 2>/dev/null
|
userdel -r $USERNAME 2>/dev/null
|
||||||
groupdel $USERNAME 2>/dev/null
|
groupdel $USERNAME 2>/dev/null
|
||||||
|
@ -209,7 +225,7 @@ deleteUsers ()
|
||||||
deleteUsersDry ()
|
deleteUsersDry ()
|
||||||
{
|
{
|
||||||
while read line; do
|
while read line; do
|
||||||
USERNAME=$(turnLowercase $(cutter "${line}" "1"))
|
USERNAME=$(turnLowercase $(cutter "${line}" "$COL_USERNAME"))
|
||||||
echo "userdel -r $USERNAME"
|
echo "userdel -r $USERNAME"
|
||||||
echo "groupdel $USERNAME"
|
echo "groupdel $USERNAME"
|
||||||
done <<< "$FILE_CONTENTS"
|
done <<< "$FILE_CONTENTS"
|
||||||
|
|
Loading…
Reference in New Issue