import subprocess # Set the domain name and administrator credentials domain_name = "example.com" admin_username = "administrator" admin_password = "password" # Set Hostname subprocess.run(["sudo", "hostnamectl", "set-hostname", "newhostname.peo.local"], check=True) # Install the necessary packages subprocess.run(["sudo", "apt-get", "install", "-y", "realmd", "libnss-sss", "libpam-sss", "sssd", "sssd-tools", "adcli", "samba-common-bin", "oddjob", "oddjob-mkhomedir", "packagekit", "python-ldap", "net-tools", "network-manager", "policycoreutils"], check=True) # Join the domain using realm subprocess.run(["sudo", "realm", "join", "--user", f"{admin_username}%'{admin_password}'", domain_name], check=True) # Copy the Falcon_senson.deb file from the remote server to the home directory subprocess.run(["scp", "anonymous@ptiwa001:falcon-sensor_6.46.0-14306.deb", "~/"], check=True) # Copy the ninja.deb file from the remote server to the home directory subprocess.run(["scp", "anonymous@ptiwa001:ninja-agent.deb", "~/"], check=True) # Verify that the join was successful result = subprocess.run(["sudo", "net", "ads", "testjoin"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) if result.returncode == 0: print("Successfully joined the domain") else: print("Failed to join the domain.") # Activate creation of homedir subprocess.run(["sudo", "bash", "-c", "cat > /usr/share/pam-configs/mkhomedir <> /etc/sudoers.d/LocalAdmins"], check=True) subprocess.run(["sudo", "sh", "-c", "echo '%Access\\ -\\ Admin\\ -\\ All\\ Servers ALL=(ALL) ALL' >> /etc/sudoers.d/LocalAdmins"], check=True) subprocess.run(["sudo", "sh", "-c", f"echo '%Access\\ -\\ Admin\\ -\\ {hostname} ALL=(ALL) ALL' >> /etc/sudoers.d/LocalAdmins"], check=True) print("Join to Domain, installation of Falson Sensor and Ninja Agent are complete") print(result.stderr.decode())