2024-08-23 11:44:27 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
for arg in User_Id User_Name Home_Dir Group_Id Group_Name
|
|
|
|
do
|
|
|
|
declare "$arg"=$1
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-23 17:42:22 +02:00
|
|
|
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 ""
|
2024-08-23 11:44:27 +02:00
|
|
|
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..."
|
2024-08-23 17:42:22 +02:00
|
|
|
#echo "su - -P ${User_Name} -c \"$*\""
|
2024-08-23 11:44:27 +02:00
|
|
|
|
2024-08-23 17:42:22 +02:00
|
|
|
su - -P ${User_Name} -c "$*"
|
2024-08-23 11:44:27 +02:00
|
|
|
|
|
|
|
echo "Completed!"
|