| @@ -9,6 +9,45 @@ 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 | |||
| 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 | |||
| if [ "$current_user" == "$username" ]; then | |||
| echo "Script launched from same user!" | |||
| @@ -275,7 +314,6 @@ echo "module.exports = { instanceName : '$INSTANCENAME', reposerver: '$REPOSERVE | |||
| echo "Setup completed successfully!" | |||
| if [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "CentOS" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then | |||
| sudo dnf install redis -y | |||
| else | |||