Ticket #6737: adduser.2.sh

File adduser.2.sh, 780 bytes (added by castet.matthieu@…, 6 years ago)
Line 
1#! /bin/sh
2
3set -e
4#set -x
5
6[ $# -ne 2 ] && { echo "$0 user group"; exit 1; }
7USER="$1"
8GROUP="$2"
9
10grep -q -e "^$GROUP:" /etc/group && exit 1
11grep -q -e "^$USER:" /etc/passwd && exit 1
12
13for UID in $(seq 500 1000)
14do
15        grep -q -e "^[^:]*:[^:]:$UID:" /etc/passwd || break
16done
17[ $UID -eq 1000 ] && exit 1
18
19for GID in $(seq 500 1000)
20do
21        grep -q -e "^[^:]*:[^:]:$GID:" /etc/group || break
22done
23[ $GID -eq 1000 ] && exit 1
24
25echo "using uid : $UID, gid : $GID"
26
27cp /etc/group /etc/group.new
28echo $GROUP:x:$GID: >> /etc/group.new
29mv /etc/group.new /etc/group
30
31cp /etc/passwd /etc/passwd.new
32echo "$USER:!:$UID:$GID:$USER:/home/$USER:/bin/ash" >> /etc/passwd.new
33mv /etc/passwd.new /etc/passwd
34mkdir -p "/home/$USER"
35chown $USER:$GROUP "/home/$USER"
36chmod 755 "/home/$USER"
37passwd $USER