import subprocess # Set the domain name and administrator credentials domain_name = "example.com" admin_username = "administrator" admin_password = "password" # Set Hostname def set_hostname(): hostname = subprocess.run(["hostname"], stdout=subprocess.PIPE, check=True).stdout.decode().strip() hostname = hostname.split(".")[0] subprocess.run(["sudo", "hostnamectl", "set-hostname", hostname], check=True) # Install the necessary packages def install_packages(): packages = ["realmd", "libnss-sss", "libpam-sss", "sssd", "sssd-tools", "adcli", "samba-common-bin", "oddjob", "oddjob-mkhomedir", "packagekit", "python-ldap", "net-tools", "network-manager", "policycoreutils"] subprocess.run(["sudo", "apt-get", "install", "-y", *packages], check=True) # Copy the files from the remote server def copy_files(file_name): subprocess.run(["scp", "anonymous@ptiwa001:"+file_name, "~/"], check=True) # Join the domain using realm def join_domain(): subprocess.run(["sudo", "realm", "join", "--user", f"{admin_username}%'{admin_password}'", domain_name], 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. Error: ",result.stderr.decode()) # Activate creation of homedir def activate_mkhomedir(): subprocess.run(["sudo", "bash", "-c", "cat > /usr/share/pam-configs/mkhomedir <> /etc/sudoers.d/LocalAdmins"], check=True) subprocess.run(["sudo", "bash", "-c", f"echo '%Access\ -\ Admin\ -\ All\ Servers ALL=(ALL) ALL' >> /etc/sudoers.d/LocalAdmins"], check=True) subprocess.run(["sudo", "bash", "-c", f"echo '%{group_name} ALL=(ALL) ALL' >> /etc/sudoers.d/LocalAdmins"], check=True)