Mistři v programování na #hovnokod

Bash #54

#!/bin/bash
function get_group()
{
rm ./group
gnc=`cat /etc/group | wc -l`
cn=1
while let "cn<=gnc"
do
gn=`cat /etc/group | head -n $cn | tail -n 1 | tr ':' '\n' | head -n 1 | grep [A-Za-z0-9].*`
gnl=`cat /etc/group | head -n $cn | tail -n 1`
echo $gnl
echo "Do you want add your to group "$gn
read as
if [ "$as" == "yes" ]; then
echo "yes"
c=`echo $gnl | wc -c`
let c--
ct=":"
echo $c
cn2=`echo $gnl | cut -c$c`
echo "cn2 "$cn2
if [ "$cn2" != ":" ]
then
echo no
gnl=$gnl","
gnl=$gnl"$1"
echo $gnl >> ./group
else
gnl=$gnl""$1
echo $gnl >> ./group
fi
echo $gnl
else
echo $gnl >> ./group
fi

let cn++
done
cp ./group /etc/group
}

if [ $# -lt 1 ]; then
echo -n "Enter username:"
read username
uid=1
puid=0
while :
do
uid=`echo ${RANDOM:0:3}`
puid=`cat /etc/passwd | tr ':' '\n' | grep ^[0-9].*$ | grep $uid`
if [ "$puid" == "" ];then
echo "uid = $uid"
echo "puid = $puid"
echo $username
groupadd $username
gid=`cat /etc/group | grep $username | tr ':' '\n' | grep ^[0-9].*$ | head -n 1 | tail -n 1`
echo "gid "$gid
echo -n "Enter shell:"
read ushell
echo -n "Enter your name:"
read rname
echo $username:x:$uid:$gid:$rname:/home/$username:$ushell >> /etc/passwd
echo $username:Jkirh5i3e/GqU:14318:0:99999:7:7:: >> /etc/shadow
echo "Your password www.***.**"
mkdir /home/$username
chmod u+r+w+x /home/$username
chmod g+r+w+x /home/$username
chmod o+r+w+x /home/$username
get_group $username
exit 0
else
uid=`echo ${RANDOM:0:3}`
echo $uid
echo "puid "$puid
fi
done
fi
echo -n "script havnt command line arguments"
exit 0

Anonymous,