-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-ssl.py
76 lines (59 loc) · 2.33 KB
/
auto-ssl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import platform
import subprocess
def get_linux_distribution():
try:
with open('/etc/os-release', 'r') as f:
for line in f:
if line.startswith('ID='):
return line.split('=')[1].strip().strip('"').lower()
except FileNotFoundError:
pass
return None
def install_package(package_name):
distname = get_linux_distribution()
if distname in ['debian', 'ubuntu']:
cmd = ['sudo', 'apt', 'install']
elif distname in ['fedora', 'centos', 'redhat']:
cmd = ['sudo', 'yum', 'install']
elif distname == 'arch':
cmd = ['sudo', 'pacman', '-S']
else:
print(f"Unsupported distribution: {distname}. Please install {package_name} manually.")
return
subprocess.run(cmd + [package_name, '-y'])
def run_command(command):
result = os.system(command)
if result != 0:
print(f"Error occurred while executing: {command}")
# Check the operating system and install necessary packages
if platform.system() == 'Linux':
install_package('socat')
run_command("curl https://get.acme.sh | sh")
run_command("~/.acme.sh/acme.sh --set-default-ca --server letsencrypt")
run_command("~/.acme.sh/acme.sh --register-account -m [email protected]")
run_command(f"clear")
domain = input("Please enter your domain: ")
run_command(f"~/.acme.sh/acme.sh --issue -d {domain} --standalone --force")
copy_ssl = input("Do you want to copy the SSL files to /root? (y/n): ")
if copy_ssl.lower() == 'y':
run_command(f"~/.acme.sh/acme.sh --installcert -d {domain} --key-file /root/private.key --fullchain-file /root/cert.crt --force")
run_command(f"clear")
print("")
print(20 * "###")
print(f"Full Chain: /root/cert.crt")
print(f"Private Key: /root/private.key")
print("")
print(20 * "###")
print("Process complete.")
else:
run_command(f"clear")
print(20 * "###")
print("")
print(f"Full Chain: /root/.acme.sh/{domain}_ecc/fullchain.cer")
print(f"Private Key: /root/.acme.sh/{domain}_ecc/{domain}.key")
print("")
print(20 * "###")
print("Process complete.")
else:
print(f"Unsupported operating system: {platform.system()}. Please run this script on a Linux system.")