revision... i'll better use while, cases and getopts :)
This commit is contained in:
parent
3ab1ba0d21
commit
546a0c479e
99
ffuseradd.sh
99
ffuseradd.sh
|
@ -1,23 +1,88 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
NMEUSR=$1
|
#NMEUSR=$1
|
||||||
EMLUSR=$2
|
#EMLUSR=$2
|
||||||
GRPUSR=$3
|
#GRPUSR=$3
|
||||||
ADDUSR="$(which useradd) -m -G"
|
#ADDUSR="$(which useradd) -m"
|
||||||
|
|
||||||
|
|
||||||
if [ "$NMEUSR" = "" ]; then
|
# Usage info
|
||||||
echo -e "\nUSAGE: ffuseradd <USERNAME>... [EMAIL ADDRESS]... [GROUP]... \nUsername is\
|
|
||||||
necessary!\nEmail address and group are optional.\nGroups for example: sudo,www-user. Ever add multible groups \",\" separated! Leave it blank for standard user."
|
#if [ "$NMEUSR" = "" ]; then
|
||||||
exit
|
# echo -e "\nUSAGE: ffuseradd <USERNAME>... [EMAIL ADDRESS]... [GROUP]... \nUsername is\
|
||||||
else
|
# necessary!\nEmail address and group are optional.\nGroups for example: sudo,www-user. Ever add multible groups \",\" separated! Leave it blank for standard user."
|
||||||
if [ "$EMLUSR" = "" ]; then
|
# exit
|
||||||
echo -e "You entered username:\n Username: "$NMEUSR"\n Email address: none"
|
#else
|
||||||
else
|
# if [ "$EMLUSR" = "" ]; then
|
||||||
echo -e "You entered username:\n Username: "$NMEUSR"\n Email address: "$EMLUSR""
|
# echo -e "You entered:\n Username: "$NMEUSR"\n Email address: none"
|
||||||
fi
|
# else
|
||||||
fi
|
# echo -e "You entered:\n Username: "$NMEUSR"\n Email address: "$EMLUSR""
|
||||||
|
# fi
|
||||||
|
#fi
|
||||||
|
|
||||||
# Adding user
|
# Adding user
|
||||||
echo -e "\nadding user "$NMEUSR" with "$ADDUSR""
|
|
||||||
echo $GRPUSR
|
#echo -e "\nadding user "$NMEUSR" with "$ADDUSR" "$GRPUSR" "$NMEUSR""
|
||||||
|
|
||||||
|
###################
|
||||||
|
### UND NOCHMAL ###
|
||||||
|
###################
|
||||||
|
|
||||||
|
usage()
|
||||||
|
{
|
||||||
|
cat<<EOF
|
||||||
|
usage: $0 -u <USERNAME> -[e|g]options
|
||||||
|
|
||||||
|
This script adds a new user and includes his public key into the users home
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
-h show this message
|
||||||
|
-u set username
|
||||||
|
-e set new users email address
|
||||||
|
-g set additional group(s) for the new user
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
NMEUSR=
|
||||||
|
EMLUSR=
|
||||||
|
GROUSR=
|
||||||
|
VERBOSE=
|
||||||
|
|
||||||
|
while getopts "h:u:e:g:" OPTION
|
||||||
|
do
|
||||||
|
case $OPTION in
|
||||||
|
h)
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
u)
|
||||||
|
NMEUSR=$OPTARG
|
||||||
|
;;
|
||||||
|
e)
|
||||||
|
EMLUSR=$OPTARG
|
||||||
|
;;
|
||||||
|
g)
|
||||||
|
GRPUSR=$OPTARG
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -z $NMEUSR ]] || [[ -z $EMLUSR ]] || [[ -z $GRPUSR ]]
|
||||||
|
then
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#while getopts u:e:g: option
|
||||||
|
#do
|
||||||
|
# case "${option}"
|
||||||
|
# in
|
||||||
|
# u) NMEUSR=${OPTARG};;
|
||||||
|
# e) EMLUSR=${OPTARG};;
|
||||||
|
# g) GRPUSR=${OPTARG};;
|
||||||
|
# esac
|
||||||
|
#done
|
||||||
|
|
||||||
|
#echo $NMEUSR
|
||||||
|
#echo $EMLUSR
|
||||||
|
#echo $GRPUSR
|
||||||
|
|
Loading…
Reference in a new issue