x11-pulse/sbin/user_add_exec
2024-08-23 17:42:22 +02:00

54 lines
1013 B
Bash
Executable File

#!/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 -n " Display: [${DISPLAY}] Cmd: [$1]"
i=2
while [[ $i -le $# ]]
do
echo -n " [${!i}]"
i=$(($i + 1))
done
echo ""
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..."
#echo "su - -P ${User_Name} -c \"$*\""
su - -P ${User_Name} -c "$*"
echo "Completed!"