|
|
|
|
|
|
|
|
# Get the current user (who is running this script) |
|
|
# Get the current user (who is running this script) |
|
|
current_user=$(whoami) |
|
|
current_user=$(whoami) |
|
|
|
|
|
|
|
|
# 1. Check if the current user is the same as the username to create |
|
|
|
|
|
if [ "$current_user" == "$username" ]; then |
|
|
|
|
|
echo "Same user!" |
|
|
|
|
|
else |
|
|
|
|
|
|
|
|
|
|
|
# 1. Add user |
|
|
|
|
|
echo "Adding user $username..." |
|
|
|
|
|
useradd -m -s /bin/bash "$username" |
|
|
|
|
|
|
|
|
|
|
|
read -sp "Enter password for the new user: " user_password |
|
|
|
|
|
echo |
|
|
|
|
|
echo "Setting password for user $username..." |
|
|
|
|
|
echo "$username:$user_password" | chpasswd |
|
|
|
|
|
|
|
|
|
|
|
# 2. Add user to the sudoers group (usually 'wheel' on CentOS) |
|
|
|
|
|
echo "Adding $username to the 'wheel' group for sudo access..." |
|
|
|
|
|
usermod -aG wheel "$username" |
|
|
|
|
|
|
|
|
|
|
|
cd /home/$username |
|
|
|
|
|
wget -q -O - http://git.bbh.org.in/chess/elxr/raw/branch/master/$script_to_run > $script_to_run |
|
|
|
|
|
|
|
|
|
|
|
# 3. Switch to the user and run the script |
|
|
|
|
|
echo "Switching to user $username and executing the script..." |
|
|
|
|
|
sudo -u "$username" bash -c "sh ./$script_to_run" |
|
|
|
|
|
|
|
|
|
|
|
exit 0 |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
|
|
# Get user input for username and script to run |
|
|
|
|
|
# read -p "Enter the username to create: " username |
|
|
|
|
|
# read -p "Enter the full path to the shell script to run: " script_to_run |
|
|
|
|
|
username=elxrprod |
|
|
|
|
|
script_to_run=i.lin.sh |
|
|
|
|
|
|
|
|
|
|
|
# Get the current user (who is running this script) |
|
|
|
|
|
current_user=$(whoami) |
|
|
|
|
|
|
|
|
|
|
|
# 1. Check if the current user is the same as the username to create |
|
|
# 1. Check if the current user is the same as the username to create |
|
|
if [ "$current_user" == "$username" ]; then |
|
|
if [ "$current_user" == "$username" ]; then |
|
|
echo "Script launched from same user!" |
|
|
echo "Script launched from same user!" |
|
|
|
|
|
|
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
# cd /home/$username |
|
|
# cd /home/$username |
|
|
#wget -q -O - http://git.bbh.org.in/chess/elxr/raw/branch/master/$script_to_run > $script_to_run |
|
|
|
|
|
|
|
|
wget -q -O - http://git.bbh.org.in/chess/elxr/raw/branch/master/$script_to_run > $script_to_run |
|
|
sudo cp ./$script_to_run /home/$username |
|
|
sudo cp ./$script_to_run /home/$username |
|
|
sudo chmod u+x /home/$username/i.lin.sh |
|
|
sudo chmod u+x /home/$username/i.lin.sh |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "Setup completed successfully!" |
|
|
echo "Setup completed successfully!" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "CentOS" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then |
|
|
if [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "CentOS" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then |
|
|
sudo dnf install redis -y |
|
|
sudo dnf install redis -y |
|
|
else |
|
|
else |