Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Post Code

Name: Anonymous 2011-03-04 21:33

One recurring complaint is that nobody talks about code on /prog/. So everyone write go and write some code, any code, that does something, anything, and post it. A small explanation wouldn't go amiss either.

Name: Anonymous 2011-03-05 17:12

How an expert newfag adds users;

#!/bin/bash
#
# lrn2bash
# ########
# prototype useradd using only primitive
# utilities and bash builtins
#
# add a new user account where uid is
# incremented and gid defaults to users
# group.
#
# overview
# ########
# this script takes 1 argument; user name
# this script takes 3 options; help, verbose, test
#
# the user id and group id is read from passwd
#
# each test will loop and read new input if fail
#
# the script will not write or execute any commands
# until all tests have passed
#
# rules/tests
# ###########
#
# the user name must be at least 3 characters in
# length and only alaphanumeric characters
# the user name must not be in use
#
# password must be at least 6 characters in length
# password must be verified
#
USERS=`ls /home`
#USERNAME=`for USER in $USERS; do echo $USER; done;`
username=$1
USERNAME_VALID=''
while [[ -z "$USERNAME_VALID" ]]; do
    if [ `echo "$username" | grep "$USERS"` ]; then
        echo -en "User exits.\nEnter new username: "
        read username
    elif [ `echo ${#username}` -le 1 ]; then
        echo -en "Need at least 2 characters.\nEnter new username: "
        read username
    elif [[ $username != [[:alpha:]][[:alnum:]]* ]]; then
        echo -en "Alpha numeric characters only. \nEnter new username: "
        read username
    else
        USERNAME_VALID=1
        echo "Your new user name: $username"
    fi;
done;

PASSWORD_VALID=''
echo -en "\nCreate new password: "
read -es password
while [[ -z "$PASSWORD_VALID" ]]; do
    if [[ ${#password} -lt 7 ]]; then
        echo -en "Password must be at least 6 characters.\nEnter new password: "
        read -es password
    else
        echo -en "Verify new password: "
        read -es verify_password
        if [[ "$password" = "$verify_password" ]]; then
            PASSWORD_VALID=1
        fi;
    fi;
done;

GROUP_USERS_STRING=`cat /etc/group | grep "^users*"`
while IFS=: read USR PASSWD GID; do
    gid=$GID
done <<< $GROUP_USERS_STRING

PASSWD_PREVIOUS_UID=tail etc/passwd -n10 | grep "\:10[0-9]\{2\}\:10[0-9]\{2\}\:" | tail -n1
while IFS=: read USR PASSWD UID; do
    uid=$(($UID+1))
done <<< $PASSWD_PREVIOUS_UID


# still need to read comment, set homepath, and define shell
# define passwd string
# encrypt password with crypt
# define shadow string
# chmod shadow (and passwd if necessary)
# append each string appropriately
# i.e. /etc/passwd
#    /etc/shadow
#   /etc/group
# chmod files with original permissions
# cp /etc/skel to /home/{$username}
#      


# echo "{$username}:x:{$uid}:{$gid}:"

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List