| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- #!/bin/bash
- set -e
- # run dpkg-reconfigure unattended-upgrades and answer no unattended
- echo "Running dpkg-reconfigure unattended-upgrades..."
- echo "unattended-upgrades unattended-upgrades/enable_auto_updates boolean false" | sudo debconf-set-selections
- sudo dpkg-reconfigure -f noninteractive unattended-upgrades
- # mark linux-image-generic and linux-headers-generic as held back
- echo "Marking linux-image-generic and linux-headers-generic as held back..."
- sudo apt-mark hold linux-image-generic linux-headers-generic
- # upgrade the system
- echo "Upgrading the system..."
- sudo DEBIAN_FRONTEND=noninteractive apt upgrade -y
- # Update and install required packages for Active Directory
- sudo DEBIAN_FRONTEND=noninteractive apt update
- sudo DEBIAN_FRONTEND=noninteractive apt install -y realmd libnss-sss libpam-sss sssd sssd-tools adcli samba-common-bin oddjob oddjob-mkhomedir packagekit
- # Install any additional software
- # Required packages for Ninja
- sudo DEBIAN_FRONTEND=noninteractive apt install -y net-tools network-manager policycoreutils jq libjq1 libonig5
- # Load configuration file
- source config.sh
- # Set the username and password
- ADMINUSER=$ADMIN_USER
- #ADMINPASS=$ADMIN_PASSWORD
- # Set the hostname
- sudo hostnamectl set-hostname "$NEW_HOSTNAME"
- # Set /etc/host
- echo "127.0.0.1 localhost" | sudo tee /etc/hosts
- echo "$(hostname -I | cut -d' ' -f1) $HOST $NEW_HOSTNAME" | sudo tee -a /etc/hosts
- # Update and install required packages
- #sudo apt update
- #sudo apt install -y realmd libnss-sss libpam-sss sssd sssd-tools adcli samba-common-bin oddjob oddjob-mkhomedir packagekit
- # Join the domain
- #echo "$ADMINPASS" | sudo -S realm join --user="$ADMINUSER" --computer-ou="$OU" "$DOMAIN"
- echo "Joining the domain..."
- sudo -S realm join --user="$ADMINUSER" --computer-ou="$OU" "$DOMAIN"
- #work in progress - --computer-desc="$COMPUTER_DESC"
- # Configure PAM to create home directories for domain users on first login
- sudo bash -c "cat >> /usr/share/pam-configs/mkhomedir" << EOL
- Name: Activate mkhomedir
- Default: yes
- Priority: 900
- Session-Type: Additional
- Session:
- required pam_mkhomedir.so umask=0077 skel=/etc/skel
- EOL
- # Enable the mkhomedir PAM module
- sudo pam-auth-update --enable mkhomedir
- # Set permissions for the home directories
- sudo chmod 0700 /home/*
- # Configure SSSD
- sudo sed -i 's/use_fully_qualified_names = True/use_fully_qualified_names = False/g' /etc/sssd/sssd.conf
- # Deny login to all users
- sudo realm deny --all
- # Allow login to domain groups
- sudo realm permit -g "Domain Admins"
- sudo realm permit -g "Access - Admin - All Servers"
- sudo realm permit -g "Access - Admin - $HOST"
- sudo realm permit -g "Access - Admin - All Linux Servers"
- # Set up sudoers file
- echo "%Domain\ Admins ALL=(ALL:ALL) ALL" | sudo tee /etc/sudoers.d/LocalAdmins > /dev/null
- echo "%Access\ -\ Admin\ -\ All\ Servers ALL=(ALL) ALL" | sudo tee -a /etc/sudoers.d/LocalAdmins > /dev/null
- echo "%Access\ -\ Admin\ -\ All\ Linux\ Servers ALL=(ALL) ALL" | sudo tee -a /etc/sudoers.d/LocalAdmins > /dev/null
- echo "%Access\ -\ Admin\ -\ $HOST ALL=(ALL) ALL" | sudo tee -a /etc/sudoers.d/LocalAdmins > /dev/null
- echo "Ansible ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/LocalAdmins > /dev/null
- # Set Timezone to Eastern
- echo "Seting the Timezone..."
- sudo timedatectl set-timezone America/New_York
- # copy file from SCP server to local system
- # sudo scp -r anonymous@ptiwa001:ninja-agent.deb /home/coadmin/
- # curl -o ninja-agent.deb https://app.ninjarmm.com/agent/installer/e99519fc-b76e-4c50-b5ff-ef68db95b032/serverslinuxmainoffice-5.6.7925-installer-x86-64.deb
- echo "Installing Ninja..."
- # Step 1: Get OAuth token
- oauth_response=$(curl --request POST \
- --url https://app.ninjarmm.com/ws/oauth/token \
- --header 'Content-Type: application/x-www-form-urlencoded' \
- --data grant_type=client_credentials \
- --data client_id=Exx51oPGv_hZ8fgQh2IqtpX5VpA \
- --data client_secret=AAv3WeKnUjSOSRuW94plKdrihEw8AEZCJd38VK56aSGjAa4BAtm_zw \
- --data scope=management)
- # Extract access token from response
- access_token=$(echo "$oauth_response" | jq -r '.access_token')
- # Step 2: Generate installer URL
- installer_response=$(curl -X 'GET' \
- 'https://app.ninjarmm.com/v2/organization/26/location/45/installer/LINUX_RPM' \
- -H 'accept: application/json' \
- -H "Authorization: Bearer $access_token")
- # Extract installer URL from response
- installer_url=$(echo "$installer_response" | jq -r '.url')
- # Step 3: Download installer using generated URL
- curl -o ninja-agent.deb "$installer_url"
- # install Ninja
- sudo dpkg -i ninja-agent.deb
- # copy file from SCP server to local system
- #sudo scp -r anonymous@ptiwa001:falcon-sensor_6.46.0-14306.deb /home/coadmin/
- # Install CrowdStrike Falcon
- echo "Installing Falcon Sensor..."
- sudo export FALCON_CLIENT_ID="58f632f6b11c43f48864c9043ec8428d"
- sudo export FALCON_CLIENT_SECRET="8VrQZaLfAHgJNpED0627tyeu9oGbcwWP51mxYk34"
- sudo export FALCON_CID="D0511099B3FF494D8B87F48C4AB90201-56"
- sudo export FALCON_SENSOR_VERSION_DECREMENT="1"
- curl -L https://raw.githubusercontent.com/crowdstrike/falcon-linux-install-bash/main/falcon-linux-deploy.sh | sudo bash
- # install package using dpkg
- # sudo dpkg -i falcon-sensor_6.46.0-14306.deb
-
- # Run the additional command
- # sudo /opt/CrowdStrike/falconctl -s --cid=D0511099B3FF494D8B87F48C4AB90201-56
- # Remove packages that are not required
- echo "Removing old packages..."
- sudo apt autoremove -y
- # Configure syslog server
- echo "Configuring syslog server..."
- echo 'remote host is: dcpi-siem 10.200.24.51:514' | sudo tee -a /etc/rsyslog.conf
- echo '*.* @@10.200.24.51:514' | sudo tee -a /etc/rsyslog.conf
- # Start/Restart Services
- echo "Restarting system services..."
- sudo systemctl restart sssd
- sudo systemctl start ninjarmm-agent.service
- sudo systemctl start falcon-sensor
- sudo systemctl restart rsyslog
- # check the status of the services
- sudo systemctl | grep -E 'falcon-sensor|ninjarmm-agent|sssd.service'
- # Query user and print message
- id chagood && echo "Successfully queried Active Directory for user chagood"
- # Check if reboot is required
- if [ -f /var/run/reboot-required ]; then
- echo -e "\033[31mA reboot is required.\033[0m"
- else
- echo -e "\033[32mReboot not required.\033[0m"
- fi
|