⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adduser.sh

📁 minix软件源代码
💻 SH
字号:
#!/bin/sh##	adduser 1.0 - add a new user to the system	Author: Kees J. Bot#								16 Jan 1996# Check arguments.case "$#" in3)	user="$1"; group="$2"; home="$3"	;;*)	echo "Usage: adduser user group home-dir" >&2; exit 1esac# We need to be root.case "`id`" in'uid=0('*)	;;*)	echo "adduser: you must be root to add users" >&2; exit 1esac# User and group names must be alphanumeric and no longer than 8 characters.len=`expr "$user" : '[a-z][a-z0-9]*$'`if [ "$len" -eq 0 -o "$len" -gt 8 ]then	echo >&2 \"adduser: the user name must be alphanumeric and no longer than 8 characters"	exit 1filen=`expr "$group" : '[a-z][a-z0-9]*$'`if [ "$len" -eq 0 -o "$len" -gt 8 ]then	echo >&2 \"adduser: the group name must be alphanumeric and no longer than 8 characters"	exit 1fi# The new user name must not exist, but the group must exist.if grep "^$user:" /etc/passwd >/dev/nullthen	echo "adduser: user $user already exists" >&2	exit 1figid=`sed -e "/^$group:/!d" -e 's/^[^:]*:[^:]*:\\([^:]*\\):.*/\\1/' /etc/group`if [ `expr "$gid" : '[0-9]*$'` -eq 0 ]then	echo "adduser: group $group does not exist" >&2	exit 1fi# Find the first free user-id of 10 or higher.uid=10while grep "^[^:]*:[^:]*:$uid:.*" /etc/passwd >/dev/nulldo	uid=`expr $uid + 1`done# No interruptions.trap '' 1 2 3 15# Lock the password file.ln /etc/passwd /etc/ptmp || {	echo "adduser: password file busy, try again later"	exit 1}# Make the new home directory, it should not exist already.mkdir "$home" || {	rm -rf /etc/ptmp	exit 1}# Make the new home directory by copying the honorary home directory of our# fearless leader.echo cpdir /usr/ast "$home"cpdir /usr/ast "$home" || {	rm -rf /etc/ptmp "$home"	exit 1}# Change the ownership to the new user.echo chown -R $uid:$gid "$home"chown -R $uid:$group "$home" || {	rm -rf /etc/ptmp "$home"	exit 1}# Is there a shadow password file?  If so add an entry.if [ -f /etc/shadow ]then	echo "echo $user::0:0::: >>/etc/shadow"	echo "$user::0:0:::" >>/etc/shadow || {		rm -rf /etc/ptmp "$home"		exit 1	}	pwd="##$user"else	pwd=fi# Finish up by adding a password file entry.echo "echo $user:$pwd:$uid:$gid:$user:$home: >>/etc/passwd"echo "$user:$pwd:$uid:$gid:$user:$home:" >>/etc/passwd || {	rm -rf /etc/ptmp "$home"	exit 1}# Remove the lock.rm /etc/ptmp || exitecho "The new user $user has been added to the system.  Note that the password,full name, and shell may be changed with the commands passwd(1), chfn(1),and chsh(1).  The password is now empty, so only console logins are possible."if [ $gid = 0 ]then	echo "\Also note that a new operator needs an executable search path (\$PATH) thatdoes not contain the current directory (an empty field or "." in \$PATH)."fiexit 0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -