summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralex <alex@pdp7.net>2023-10-21 18:54:50 +0200
committeralex <alex@pdp7.net>2023-10-21 18:55:08 +0200
commite7ddf0cfc6f0b928a34ff03f6483f40a3ab2f3a9 (patch)
tree4029c0db128aae5f4e4bc45a4e0d0e03d79089da
parentf7e1221718dbc729d2daf6d41402dca432b7b8d5 (diff)
Add Nextcloud setup
-rwxr-xr-xscripts/p7s/nextcloud.py40
-rw-r--r--scripts/pyproject.toml1
2 files changed, 41 insertions, 0 deletions
diff --git a/scripts/p7s/nextcloud.py b/scripts/p7s/nextcloud.py
new file mode 100755
index 00000000..0077c3a4
--- /dev/null
+++ b/scripts/p7s/nextcloud.py
@@ -0,0 +1,40 @@
+import pathlib
+import subprocess
+import textwrap
+
+
+def setup_nextcloud():
+ home = pathlib.Path.home()
+
+ 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", "Nextcloud/_ssh", ".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)
diff --git a/scripts/pyproject.toml b/scripts/pyproject.toml
index b797e68b..2adaf4e8 100644
--- a/scripts/pyproject.toml
+++ b/scripts/pyproject.toml
@@ -20,3 +20,4 @@ ruscreen = 'p7s.ruscreen:main'
mbsync_config = 'p7s.mail:generate_config'
db-create = 'p7s.distrobox:create'
db-enter = 'p7s.distrobox:enter'
+nextcloud_setup = 'p7s.nextcloud:setup_nextcloud'