From cdf013cec47f70a0c1f1ae38289385e5434a7992 Mon Sep 17 00:00:00 2001 From: vijayclouddevops <151009420+vijayclouddevops@users.noreply.github.com> Date: Sat, 7 Dec 2024 14:09:38 +0530 Subject: [PATCH] Update setupUser.sh update --- scripts/setupUser.sh | 111 +------------------------------------------ 1 file changed, 1 insertion(+), 110 deletions(-) diff --git a/scripts/setupUser.sh b/scripts/setupUser.sh index 2b340037..9ec5ea5b 100755 --- a/scripts/setupUser.sh +++ b/scripts/setupUser.sh @@ -1,71 +1,3 @@ -#!/bin/bash - -now=`date +%d%b%Y-%H%M` - -exp() -{ - "$1" <(cat <<-EOF - spawn passwd $USER - expect "Enter new UNIX password:" - send -- "$passw\r" - expect "Retype new UNIX password:" - send -- "$passw\r" - expect eof - EOF - ) - echo "password for USER $USER updated successfully - adding to sudoers file now" -} - -setup_pass() -{ - -if [ $1 == "sles" ];then - - if [ ! -f /usr/bin/expect ] && [ ! -f /bin/expect ];then -# zypper -y update - zypper install -y expect - exp "/usr/bin/expect" - else - exp "/usr/bin/expect" - fi - -elif [ $1 == "ubuntu" ];then - - if [ ! -f /usr/bin/expect ] && [ ! -f /bin/expect ];then - apt-get update - apt install -y expect - exp "/usr/bin/expect" - else - exp "/usr/bin/expect" - fi - -elif [ $1 == "amzn" ];then - - echo $1 - if [ ! -f /usr/bin/expect ] && [ ! -f /bin/expect ];then - rpm -Uvh http://epel.mirror.net.in/epel/6/x86_64/epel-release-6-8.noarch.rpm - yum install -y expect - exp "/usr/bin/expect" - else - exp "/usr/bin/expect" - fi - -elif [ $1 == "centos" ];then - - echo $1 - if [ ! -f /usr/bin/expect ] && [ ! -f /bin/expect ];then - rpm -Uvh http://epel.mirror.net.in/epel/6/x86_64/epel-release-6-8.noarch.rpm - yum install -y expect - exp "/bin/expect" - else - exp "/bin/expect" - fi -else - echo "could not find case $1" -fi - -} - update_conf() { sudofile="/etc/sudoers" @@ -79,7 +11,6 @@ update_conf() echo "$USER user already present in $sudofile - no changes required" grep $USER $sudofile else -# echo "$USER ALL=(ALL) ALL" >> $sudofile echo "$USER ALL=(ALL) NOPASSWD: ALL" >> $sudofile echo "updated the sudoers file successfully" fi @@ -104,49 +35,9 @@ update_conf() sed -i '/PasswordAuthentication.*no/d' $sshdfile sed -i '/PasswordAuthentication.*yes/d' $sshdfile echo "PasswordAuthentication yes" >> $sshdfile - #sed -i '/PermitRootLogin.*yes/d' $sshdfile - #sed -i '/PermitRootLogin.*prohibit-password/d' $sshdfile - #echo "PermitRootLogin yes" >> $sshdfile echo "updated $sshdfile Successfully -- restarting sshd service" - service sshd restart + service sshd restart || sudo /usr/sbin/sshd else echo "could not find $sshdfile" fi } - -############### MAIN ################### - -USER="devops" -GROUP="devops" -passw="today@1234" - -if id -u "$USER" &>/dev/null; then - echo "devops user exists no action required.." - exit 0 -else - echo "devops user missing, continue to create it.." -fi - -if [ -f /etc/os-release ];then - osname=`grep ID /etc/os-release | egrep -v 'VERSION|LIKE|VARIANT|PLATFORM' | cut -d'=' -f2 | sed -e 's/"//' -e 's/"//'` - echo $osname -else - echo "can not locate /etc/os-release - unable find the osname" - exit 8 -fi - -case "$osname" in - sles|amzn|ubuntu|centos) - userdel -r $USER - groupdel $GROUP - sleep 3 - groupadd $GROUP - useradd $USER -m -d /home/$USER -s /bin/bash -g $GROUP - setup_pass $osname - update_conf - ;; - *) - echo "could not determine the correct osname -- found $osname" - ;; -esac -exit 0