mirror of
https://github.com/dragonlock2/matthewtran.com.git
synced 2025-10-11 20:17:54 +00:00
auto advertisement of time machine shares
This commit is contained in:
parent
ba62e62a59
commit
3fc2698db9
@ -44,7 +44,11 @@ Services deployed on [matthewtran.com](https://matthewtran.com).
|
|||||||
|
|
||||||
## backup
|
## backup
|
||||||
|
|
||||||
Run `scripts/backup.py` and save the resultant `data.zip` somewhere. I should probably automate this.
|
Run `scripts/backup.py` and save the resultant `data.zip` somewhere. Also run the following commands for BTRFS maintenance. I should probably automate this.
|
||||||
|
```
|
||||||
|
btrfs device stats <mount>
|
||||||
|
btrfs scrub start -B <mount>
|
||||||
|
```
|
||||||
|
|
||||||
## security
|
## security
|
||||||
|
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/sudo /usr/bin/python3
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import yaml
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
override = {}
|
||||||
|
|
||||||
# create folders so containers have access
|
# create folders so containers have access
|
||||||
PATHS = {
|
PATHS = {
|
||||||
"web": [
|
"web": [
|
||||||
@ -25,34 +30,64 @@ if __name__ == "__main__":
|
|||||||
for group in PATHS:
|
for group in PATHS:
|
||||||
for p in PATHS[group]:
|
for p in PATHS[group]:
|
||||||
Path(p).mkdir(parents=True, exist_ok=True)
|
Path(p).mkdir(parents=True, exist_ok=True)
|
||||||
shutil.chown(p, group=group)
|
shutil.chown(p, user=os.getlogin(), group=group)
|
||||||
|
|
||||||
# add users to nas
|
# add users to nas
|
||||||
users = json.load(open("nas/users.json", "r"))
|
file = Path("nas/users.json")
|
||||||
with open("nas/users.sh", "w") as f:
|
script = Path("nas/users.sh")
|
||||||
for id, user in enumerate(users):
|
with script.open("w") as f:
|
||||||
id = 3000 + id
|
if file.exists():
|
||||||
f.write(f"groupadd -g {id} {user}\n")
|
users = json.load(file.open())
|
||||||
f.write(f"useradd -M -s /bin/false -u {id} -g {id} {user}\n")
|
for id, user in enumerate(users):
|
||||||
f.write(f"su - me -c 'echo \"{users[user]}\\n{users[user]}\\n\" | pdbedit -s smb.conf -a {user}'\n")
|
id = 3000 + id
|
||||||
|
f.writelines(s + "\n" for s in [
|
||||||
|
f"groupadd -g {id} {user}",
|
||||||
|
f"useradd -M -s /bin/false -u {id} -g {id} {user}",
|
||||||
|
f"su - me -c 'echo \"{users[user]}\\n{users[user]}\\n\" | pdbedit -s smb.conf -a {user}'",
|
||||||
|
])
|
||||||
|
shutil.chown(script, user=os.getlogin(), group=os.getlogin())
|
||||||
|
|
||||||
# add volumes to nas
|
# add volumes to nas
|
||||||
mounts = json.load(open("nas/mounts.json", "r"))
|
file = Path("nas/mounts.json")
|
||||||
with open("compose.override.yml", "w") as f:
|
serv = Path("/etc/avahi/services")
|
||||||
if mounts:
|
conf = Path("nas/smb.conf")
|
||||||
f.writelines(s + "\n" for s in [
|
shutil.copyfile("nas/base.conf", conf)
|
||||||
"services:",
|
shutil.chown(conf, user=os.getlogin(), group=os.getlogin())
|
||||||
" nas:",
|
for f in serv.glob("nas-*.service"):
|
||||||
" volumes:",
|
f.unlink()
|
||||||
] + [
|
if file.exists():
|
||||||
f" - {mounts[m]}:/home/me/share/{m}" for m in mounts
|
mounts = json.load(file.open())
|
||||||
])
|
with open("nas/smb.conf", "a") as f:
|
||||||
|
for m in mounts:
|
||||||
# generate nas config
|
f.write(f"[{m}]\n")
|
||||||
shutil.copyfile("nas/base.conf", "nas/smb.conf")
|
f.write(f"path = /home/me/share/{m}\n")
|
||||||
with open("nas/smb.conf", "a") as f:
|
|
||||||
if mounts:
|
|
||||||
for dest in mounts:
|
|
||||||
f.write(f"[{dest}]\n")
|
|
||||||
f.write(f"path = /home/me/share/{dest}\n")
|
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
|
override.setdefault("services", {})["nas"] = {"volumes": [f"{mounts[m]}:/home/me/share/{m}" for m in mounts]}
|
||||||
|
for m in mounts:
|
||||||
|
with (serv / f"nas-{m}.service").open("w") as f:
|
||||||
|
f.writelines(s + "\n" for s in [
|
||||||
|
"<?xml version=\"1.0\" standalone='no'?>",
|
||||||
|
"<!DOCTYPE service-group SYSTEM \"avahi-service.dtd\">",
|
||||||
|
"<service-group>",
|
||||||
|
f" <name replace-wildcards=\"yes\">%h - {m}</name>",
|
||||||
|
" <service>",
|
||||||
|
" <type>_smb._tcp</type>",
|
||||||
|
" <port>445</port>",
|
||||||
|
" </service>",
|
||||||
|
" <service>",
|
||||||
|
" <type>_adisk._tcp</type>",
|
||||||
|
f" <txt-record>dk0=adVN={m},adVF=0x82</txt-record>",
|
||||||
|
" <txt-record>sys=waMa=0,adVF=0x100</txt-record>",
|
||||||
|
" </service>",
|
||||||
|
"</service-group>",
|
||||||
|
])
|
||||||
|
subprocess.run(["systemctl", "restart", "avahi-daemon"], check=True)
|
||||||
|
|
||||||
|
# generate compose override
|
||||||
|
file = Path("compose.override.yml")
|
||||||
|
if override:
|
||||||
|
with file.open("w") as f:
|
||||||
|
yaml.dump(override, f)
|
||||||
|
shutil.chown(file, user=os.getlogin(), group=os.getlogin())
|
||||||
|
else:
|
||||||
|
file.unlink(True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user