first commit

This commit is contained in:
iProbe 2022-10-18 16:59:37 +08:00
commit ba848e218d
1001 changed files with 152333 additions and 0 deletions

90
shell/tools/user-add.sh Normal file
View file

@ -0,0 +1,90 @@
#!/bin/bash
# 检查用户名是否已存在
check_user()
{
user=$1
u=`cat /etc/passwd | awk -F ':' '{print $1}'| grep $user`
if [ -n "$u" ];then
return 1
else
return 0
fi
}
# UID
get_uid()
{
g=`cat /etc/group |grep $1| awk -F ':' '{print $3}'`
if [ -z $g ];then
echo -e "\033[31;1m$1 not exists\033[0m"
exit 1
fi
max=$[g+500]
uids=`cat /etc/passwd | awk -F ':' '{print $3}'`
for uid in $uids;do
if [ $uid -gt $g -a $uid -lt $max ];then
g=$uid
fi
done
echo $[g+1]
}
## 添加用户
if [ $# -eq 0 ];then
echo -e "\033[31;1mUSGE:$0 [username]\033[0m"
else
# chattr -i
chattr -i /etc/passwd
chattr -i /etc/group
while [ $# -gt 0 ];do
echo -e "\033[32;1m++++++Group Lists++++++\033[0m"
echo -e "\033[32;1m\ta: devgroup\n\tb: ops\n\tc: appgroup\n\td: dbgroup\033[0m"
read -p "Choose Group for $1[default devgroup]:" group
: ${group:=devgroup}
case $group in
a|A|devgroup)
echo -e "\033[31;1mAdd user for check logs! \033[0m"
Gid=1000
;;
b|B|ops)
echo -e "\033[31;1mAdd user for system manager! \033[0m"
Gid=10
;;
c|C|appgroup)
echo -e "\033[31;1mAdd user for app! \033[0m"
Gid=0
;;
d|D|dbgroup)
echo -e "\033[31;1mAdd user for database! \033[0m"
Gid=0
;;
*)
echo -e "\033[31;1mNo Support! \033[0m"
Gid=0
;;
esac
gid=`cat /etc/group |grep $group| awk -F ':' '{print $3}'`
if [[ `check_user $1` -eq 1 ]];then
echo -e "\033[31;1m$1 exists already! \033[0m"
else
u=`get_uid $group`
if [ $Gid -gt 0 ];then
/usr/sbin/useradd -u $u -g $gid -G $Gid $1
else
/usr/sbin/useradd -u $u -g $gid $1
fi
password=`/usr/bin/openssl rand -base64 8`
echo -e "$1 password: \033[033;1m$password\033[0m"
echo $password | passwd --stdin $1
fi
shift
done
# chattr +i
chattr +i /etc/passwd
chattr +i /etc/group
fi