#!/bin/sh # config helper MUID=130 MGID=130 USERNAME=prosody GROUPNAME=prosody COMMENT=XMPP-server LOGINSHELL=/usr/bin/false echo "" echo "This script tries to create:" echo "user $USERNAME with user id $MUID" echo "group $GROUPNAME with group id $MGID" echo "If the user or group id already exists, it automatically tries higher ids." echo "" echo "After that it creates the needed directories with proper permissions, too." echo "" echo "Hit ENTER to continue (CTRL+C to cancel)" read JUNK echo "" if grep -qe "^$GROUPNAME:" /etc/group; then echo "group $GROUPNAME already exists. Exiting..." exit 1 fi if grep -qe "^$USERNAME:" /etc/passwd; then echo "user $USERNAME already exists. Exiting..." exit 1 fi NEXTGID="$(MGID=$MGID awk -F: '{uid[$3]=1} END { for (i=ENVIRON["MGID"];i in uid;i++);print i}' /etc/group)" echo creating group $GROUPNAME with GID $NEXTGID... /usr/sbin/groupadd -g $NEXTGID $GROUPNAME # if nscd is running update group cache [ $(pidof nscd) ] && { nscd --invalidate group; } NEXTUID="$(MUID=$MUID awk -F: '{uid[$3]=1} END { for (i=ENVIRON["MUID"];i in uid;i++);print i}' /etc/passwd)" echo creating user $USERNAME with UID $NEXTUID... /usr/sbin/useradd -g $GROUPNAME -u $NEXTUID -s $LOGINSHELL -c $COMMENT $USERNAME # if nscd is running update user cache [ $(pidof nscd) ] && { nscd --invalidate passwd; } echo "creating needed dirs..." mkdir -p /var/run/prosody/ mkdir -p -m750 /var/lib/prosody/ chown prosody:prosody /var/lib/prosody chown prosody:prosody /var/run/prosody