43 lines
882 B
Plaintext
43 lines
882 B
Plaintext
|
#!/bin/bash
|
||
|
|
||
|
for arg in User_Id User_Name Home_Dir Group_Id Group_Name
|
||
|
do
|
||
|
declare "$arg"=$1
|
||
|
shift
|
||
|
done
|
||
|
|
||
|
|
||
|
|
||
|
echo "User Add & Exec: User_Id: (${User_Id}) User_Name: [${User_Name}] Home_Dir: [${Home_Dir}] Group_Id: (${Group_Id}) Group_Name: [${Group_Name}]"
|
||
|
echo " Display: [${DISPLAY}] Cmd: [${*}]"
|
||
|
echo ""
|
||
|
|
||
|
|
||
|
echo "Creating group..."
|
||
|
|
||
|
groupadd --gid ${Group_Id} ${Group_Name}
|
||
|
|
||
|
|
||
|
echo "Creating user..."
|
||
|
|
||
|
if [[ ! -d ${Home_Dir} ]]
|
||
|
then
|
||
|
home_opts="--create-home"
|
||
|
fi
|
||
|
|
||
|
useradd 2>/dev/null --uid ${User_Id} --gid ${Group_Id} -m --home-dir ${Home_Dir} ${home_opts} --password "" ${User_Name}
|
||
|
|
||
|
|
||
|
echo "Update global profile..."
|
||
|
|
||
|
echo -e "export DISPLAY=${DISPLAY}\nexport XDG_RUNTIME_DIR=/run/user/${User_Id}" >/etc/profile.d/x11.sh
|
||
|
|
||
|
chown ${User_Name}:${Group_Name} /run/user/${User_Id}
|
||
|
|
||
|
|
||
|
echo "Exec Cmd..."
|
||
|
|
||
|
su - -P ${User_Name} -c $*
|
||
|
|
||
|
echo "Completed!"
|