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
|
import argparse
import pathlib
import subprocess
import textwrap
def setup_nextcloud():
parser = argparse.ArgumentParser()
parser.add_argument("style", choices=["noinstall", "flatpak", "rclone"])
args = parser.parse_args()
home = pathlib.Path.home().absolute()
assert args.style != "flatpak", "flatpak not implemented yet"
if args.style == "rclone":
if not (home / ".config" / "rclone" / "rclone.conf").exists():
print("Visit https://nextcloud.pdp7.net/nextcloud/index.php/settings/user/security , create an app password")
subprocess.run(["rclone", "config", "create", "nextcloud", "webdav", "url=https://nextcloud.pdp7.net/nextcloud/remote.php/dav/files/alex/", "vendor=nextcloud", "user=alex", "--all"], check=True)
(home / "Nextcloud").mkdir(exist_ok=True)
nextcloud_service_path = home / ".config" / "systemd" / "user" / "nextcloud.service"
nextcloud_service_path.parent.mkdir(parents=True, exist_ok=True)
nextcloud_service_path.write_text(textwrap.dedent("""
[Unit]
[Service]
ExecStart=/usr/bin/rclone mount --vfs-cache-mode=full --dir-perms 700 --file-perms 600 nextcloud: /home/alex/Nextcloud/
[Install]
WantedBy=default.target
""").lstrip())
subprocess.run(["systemctl", "--user", "enable", "--now", "nextcloud"], check=True)
if not (home / ".ssh").exists():
subprocess.run(["ln", "-s", home / "Nextcloud" / "_ssh", home / ".ssh"], check=True)
dotfiles_dir = home / "Nextcloud" / "dotfiles"
for dotfile in dotfiles_dir.glob("*"):
relative_dotfile = dotfile.relative_to(dotfiles_dir)
replaced_dotfile = pathlib.Path.home() / ("." + relative_dotfile.parts[0][1:])
if not replaced_dotfile.exists():
subprocess.run(["ln", "-s", dotfile, replaced_dotfile], check=True)
subprocess.run(["ln", "-s", "~/.weechat", "~/.config/weechat"], check=True)
|