1 Star 0 Fork 0

不歪/树莓派初始化脚本

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
add_group_user.sh 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
不歪 提交于 2018-06-08 13:36 . docker安装脚本完善
#!/bin/bash
help() {
echo "usage: add_group.sh <user> [group]"
echo " if group is empty, group equals user"
exit 1
}
if [[ "-h" == "$1" ]] || [[ "--help" == "$1" ]]; then
help
fi
USER=$1
GROUP=$2
if [[ "" == "${USER}" ]]; then
help
fi
if [[ "" == "${GROUP}" ]]; then
GROUP=$USER
fi
echo "USER=${USER}"
echo "GROUP=${GROUP}"
# 添加新用户组
group_info=`grep -E "^${GROUP}:" /etc/group`
echo group_info=$group_info
if [[ "" == "$group_info" ]]; then
# 用户组不存在,则添加用户组
echo "add group ..."
groupadd $GROUP
ret=$?
if [[ 0 -ne $ret ]]; then
echo "$LINENO: add new group is failed. group=${GROUP}"
exit $ret
fi
echo "group add success"
else
echo "group \"${GROUP}\" exists"
fi
# 向组中添加新用户
id $USER
ret=$?
if [[ 0 -ne $ret ]]; then
# 用户不存在,则添加用户
echo "add user ..."
useradd $USER -m -s /bin/bash -g $GROUP
ret=$?
if [[ 0 -ne $ret ]]; then
echo "$LINENO: useradd is failed. user=${USER}"
exit $ret
fi
echo "user add success"
else
echo "user \"${USER}\" exists"
fi
echo "new user password:"
passwd $USER
ret=$?
if [[ 0 -ne $ret ]]; then
echo "$LINENO: passwd ${USER} is failed. user=${USER}"
echo $ret
fi
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Shell
1
https://gitee.com/bw/RespberryInitShells.git
git@gitee.com:bw/RespberryInitShells.git
bw
RespberryInitShells
树莓派初始化脚本
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385