diff --git a/autouser.sh b/autouser.sh index ab00fc9..82efca6 100755 --- a/autouser.sh +++ b/autouser.sh @@ -6,6 +6,22 @@ if [[ ! -f "$FILE" ]]; then exit 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 FILE_CONTENTS="$(cat ${@: -1})" CREATE_USERS=false @@ -49,8 +65,8 @@ turnLowercase() createGroups () { while read line; do - GID=$(cutter "${line}" "2") - GROUPNAME=$(turnLowercase $(cutter "${line}" "1")) + GID=$(cutter "${line}" "$COL_GROUPGID") + GROUPNAME=$(turnLowercase $(cutter "${line}" "$COL_GROUPNAME")) if [[ -z "$GID" ]]; then echo "[+] Adding group $GROUPNAME..." groupadd $GROUPNAME @@ -64,8 +80,8 @@ createGroups () createGroupsDry () { while read line; do - GID=$(cutter "${line}" "2") - GROUPNAME=$(turnLowercase $(cutter "${line}" "1")) + GID=$(cutter "${line}" "$COL_GROUPGID") + GROUPNAME=$(turnLowercase $(cutter "${line}" "$COL_GROUPNAME")) if [[ -z "$GID" ]]; then echo "groupadd $GROUPNAME" else @@ -77,7 +93,7 @@ createGroupsDry () deleteGroups () { while read line; do - GROUPNAME=$(turnLowercase $(cutter "${line}" "1")) + GROUPNAME=$(turnLowercase $(cutter "${line}" "$COL_GROUPNAME")) echo "[+] Deleting group $GROUPNAME..." groupdel $GROUPNAME done <<< "$FILE_CONTENTS" @@ -86,7 +102,7 @@ deleteGroups () deleteGroupsDry () { while read line; do - GROUPNAME=$(turnLowercase $(cutter "${line}" "1")) + GROUPNAME=$(turnLowercase $(cutter "${line}" "$COL_GROUPNAME")) echo "groupdel $GROUPNAME" done <<< "$FILE_CONTENTS" } @@ -94,15 +110,15 @@ deleteGroupsDry () createUsers () { while read line; do - USERNAME=$(turnLowercase $(cutter "${line}" "1")) - FULLNAME=$(cutter "${line}" "2") - USERUID=$(cutter "${line}" "3") - USERGID=$(turnLowercase $(cutter "${line}" "4")) - USERGROUPS=$(turnLowercase $(cutter "${line}" "5")) - TLFN=$(cutter "${line}" "6") - EXTRAINFO=$(cutter "${line}" "7") - USERSHELL=$(cutter "${line}" "8") - USERLOCKED=$(cutter "${line}" "9") + USERNAME=$(turnLowercase $(cutter "${line}" "$COL_USERNAME")) + FULLNAME=$(cutter "${line}" "$COL_FULLNAME") + USERUID=$(cutter "${line}" "$COL_USERUID") + USERGID=$(turnLowercase $(cutter "${line}" "$COL_USERGID")) + USERGROUPS=$(turnLowercase $(cutter "${line}" "$COL_USERGROUPS")) + TLFN=$(cutter "${line}" "$COL_TLFN") + EXTRAINFO=$(cutter "${line}" "$COL_EXTRAINFO") + USERSHELL=$(cutter "${line}" "$COL_USERSHELL") + USERLOCKED=$(cutter "${line}" "$COL_USERLOCKED") echo "[+] Adding user $USERNAME..." useradd -m $USERNAME @@ -147,15 +163,15 @@ createUsers () createUsersDry () { while read line; do - USERNAME=$(turnLowercase $(cutter "${line}" "1")) - FULLNAME=$(cutter "${line}" "2") - USERUID=$(cutter "${line}" "3") - USERGID=$(turnLowercase $(cutter "${line}" "4")) - USERGROUPS=$(turnLowercase $(cutter "${line}" "5")) - TLFN=$(cutter "${line}" "6") - EXTRAINFO=$(cutter "${line}" "7") - USERSHELL=$(cutter "${line}" "8") - USERLOCKED=$(cutter "${line}" "9") + USERNAME=$(turnLowercase $(cutter "${line}" "$COL_USERNAME")) + FULLNAME=$(cutter "${line}" "$COL_FULLNAME") + USERUID=$(cutter "${line}" "$COL_USERUID") + USERGID=$(turnLowercase $(cutter "${line}" "$COL_USERGID")) + USERGROUPS=$(turnLowercase $(cutter "${line}" "$COL_USERGROUPS")) + TLFN=$(cutter "${line}" "$COL_TLFN") + EXTRAINFO=$(cutter "${line}" "$COL_EXTRAINFO") + USERSHELL=$(cutter "${line}" "$COL_USERSHELL") + USERLOCKED=$(cutter "${line}" "$COL_USERLOCKED") echo "useradd -m $USERNAME" echo "echo \"$USERNAME:$USERNAME | chpasswd\"" @@ -199,7 +215,7 @@ createUsersDry () deleteUsers () { while read line; do - USERNAME=$(turnLowercase $(cutter "${line}" "1")) + USERNAME=$(turnLowercase $(cutter "${line}" "$COL_USERNAME")) echo "[+] Deleting user $USERNAME..." userdel -r $USERNAME 2>/dev/null groupdel $USERNAME 2>/dev/null @@ -209,7 +225,7 @@ deleteUsers () deleteUsersDry () { while read line; do - USERNAME=$(turnLowercase $(cutter "${line}" "1")) + USERNAME=$(turnLowercase $(cutter "${line}" "$COL_USERNAME")) echo "userdel -r $USERNAME" echo "groupdel $USERNAME" done <<< "$FILE_CONTENTS"