This commit is contained in:
Constantin
2025-09-12 23:04:52 +03:00
commit 2277b11563
127 changed files with 23640 additions and 0 deletions
+99
View File
@@ -0,0 +1,99 @@
#!/usr/bin/env python3
import os
import sys
import subprocess
# List of required directories (relative to project root)
REQUIRED_DIRS = [
'config/caddy/certs',
'config/dns',
'config/dhcp',
'config/ntp',
'config/mail/config',
'config/mail/ssl',
'config/radicale',
'config/webdav',
'config/wireguard',
'config/api',
'data/caddy',
'data/dns',
'data/dhcp',
'data/maildata',
'data/mailstate',
'data/maillogs',
'data/radicale',
'data/files',
'data/api',
'data/vault/certs',
'data/vault/keys',
'data/vault/trust',
'data/vault/ca',
]
# List of required files (relative to project root)
REQUIRED_FILES = [
'config/caddy/Caddyfile',
'config/dns/Corefile',
'config/dhcp/dnsmasq.conf',
'config/ntp/chrony.conf',
'config/mail/mailserver.env',
'config/webdav/users.passwd',
]
# Helper to create directories
def ensure_dir(path):
if not os.path.exists(path):
os.makedirs(path, exist_ok=True)
print(f"[CREATED] Directory: {path}")
# Add .gitkeep to empty dirs
gitkeep = os.path.join(path, '.gitkeep')
with open(gitkeep, 'w') as f:
f.write('')
else:
print(f"[EXISTS] Directory: {path}")
# Helper to create empty files if missing
def ensure_file(path):
if not os.path.exists(path):
parent = os.path.dirname(path)
if parent and not os.path.exists(parent):
os.makedirs(parent, exist_ok=True)
print(f"[CREATED] Directory: {parent}")
with open(path, 'w') as f:
f.write('')
print(f"[CREATED] File: {path}")
else:
print(f"[EXISTS] File: {path}")
# Optionally generate a self-signed CA cert for Caddy
def ensure_caddy_ca_cert():
cert_dir = os.path.join('config', 'caddy', 'certs')
ca_key = os.path.join(cert_dir, 'ca.key')
ca_crt = os.path.join(cert_dir, 'ca.crt')
if os.path.exists(ca_key) and os.path.exists(ca_crt):
print(f"[EXISTS] Caddy CA cert and key: {ca_crt}, {ca_key}")
return
print("[INFO] Generating self-signed CA certificate for Caddy...")
try:
subprocess.run([
'openssl', 'req', '-x509', '-newkey', 'rsa:4096',
'-keyout', ca_key, '-out', ca_crt, '-days', '365', '-nodes',
'-subj', '/C=US/ST=State/L=City/O=PersonalInternetCell/CN=CellCA'
], check=True)
print(f"[CREATED] Caddy CA cert and key: {ca_crt}, {ca_key}")
except FileNotFoundError:
print("[WARN] openssl not found, skipping CA cert generation.")
except subprocess.CalledProcessError:
print("[ERROR] openssl failed to generate CA cert.")
def main():
print("--- Personal Internet Cell: Setup Script ---")
for d in REQUIRED_DIRS:
ensure_dir(d)
for f in REQUIRED_FILES:
ensure_file(f)
ensure_caddy_ca_cert()
print("--- Setup complete! ---")
if __name__ == '__main__':
main()