-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.py
More file actions
executable file
·58 lines (46 loc) · 1.95 KB
/
install.py
File metadata and controls
executable file
·58 lines (46 loc) · 1.95 KB
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
#!/usr/bin/env python3
"""Install script for cflan - NetworkManager dispatcher setup."""
import os
import shutil
import sys
def install() -> None:
"""Deploy NetworkManager dispatcher script and configuration files."""
if os.getuid() != 0:
sys.exit("Error: Must run as root")
script_dir = os.path.dirname(os.path.abspath(__file__))
print("Deploying NetworkManager dispatcher script...")
dispatcher_path = "/etc/NetworkManager/dispatcher.d/set_dns"
shutil.copyfile(os.path.join(script_dir, "set_dns.py"), dispatcher_path)
os.chown(dispatcher_path, 0, 0)
os.chmod(dispatcher_path, 0o700)
print(f" Installed: {dispatcher_path}")
print("\nDeploying configuration...")
config_deployed = False
# Try unencrypted config first
vars_path = os.path.join(script_dir, "vars.yaml")
if os.path.exists(vars_path):
target_path = "/vars.yaml"
shutil.copyfile(vars_path, target_path)
os.chown(target_path, 0, 0)
os.chmod(target_path, 0o600)
print(f" Installed: {target_path}")
config_deployed = True
# Fall back to sops encrypted config
sops_path = os.path.join(script_dir, "sops_vars.yaml")
if not config_deployed and os.path.exists(sops_path):
target_path = "/sops_vars.yaml"
shutil.copyfile(sops_path, target_path)
os.chown(target_path, 0, 0)
os.chmod(target_path, 0o600)
print(f" Installed: {target_path}")
print(" Note: Ensure SOPS is configured for root user")
config_deployed = True
if not config_deployed:
print(" Warning: No configuration file found (vars.yaml or sops_vars.yaml)")
print(" Create one before running the script!")
print("\nInstallation complete!")
print("\nNext steps:")
print("1. Verify your configuration in /vars.yaml or /sops_vars.yaml")
print("2. Test with: sudo /etc/NetworkManager/dispatcher.d/set_dns eth0 up")
if __name__ == "__main__":
install()