mirror of
https://github.com/kmein/niveum
synced 2026-03-22 04:41:07 +01:00
feat(cloud): add script for browsing mega
This commit is contained in:
50
.bin/toposort.nix
Normal file
50
.bin/toposort.nix
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
let
|
||||||
|
lib = import <nixpkgs/lib>;
|
||||||
|
in rec {
|
||||||
|
inherit lib;
|
||||||
|
|
||||||
|
input = [
|
||||||
|
{
|
||||||
|
x = ["pool" "zfs"];
|
||||||
|
y = ["mdadm" "raid1"];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
x = ["pool" "zfs"];
|
||||||
|
y = ["disk" "sda"];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
x = ["mdadm" "raid1"];
|
||||||
|
y = ["disk" "sdb"];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
x = ["mdadm" "raid1"];
|
||||||
|
y = ["disk" "sdc"];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
outNodes = node: graph:
|
||||||
|
lib.unique
|
||||||
|
(builtins.map (e: e.y)
|
||||||
|
(builtins.filter (v: v.x == node) graph));
|
||||||
|
|
||||||
|
vertices = graph:
|
||||||
|
lib.unique
|
||||||
|
(builtins.map (x: x.y) graph ++ builtins.map (x: x.x) graph);
|
||||||
|
|
||||||
|
deleteVertex = node: graph: (builtins.filter (v: v.x != node && v.y != node) graph);
|
||||||
|
|
||||||
|
findSink = graph:
|
||||||
|
lib.findFirst
|
||||||
|
(v: outNodes v graph == [])
|
||||||
|
(lib.trace graph (builtins.abort "No sink found"))
|
||||||
|
(vertices graph);
|
||||||
|
|
||||||
|
topSort = graph:
|
||||||
|
if graph == []
|
||||||
|
then []
|
||||||
|
else if builtins.length graph == 1
|
||||||
|
then let only = builtins.head graph; in [only.y only.x]
|
||||||
|
else let sink = findSink graph; in [sink] ++ topSort (deleteVertex sink graph);
|
||||||
|
|
||||||
|
output = topSort input;
|
||||||
|
}
|
||||||
@@ -57,11 +57,11 @@ in {
|
|||||||
user = "kieran";
|
user = "kieran";
|
||||||
password = lib.fileContents <secrets/nextcloud/password>;
|
password = lib.fileContents <secrets/nextcloud/password>;
|
||||||
endpoint = "https://cloud.xn--kiern-0qa.de";
|
endpoint = "https://cloud.xn--kiern-0qa.de";
|
||||||
|
target = "${config.users.users.me.home}/notes";
|
||||||
};
|
};
|
||||||
in ''
|
in ''
|
||||||
KIERAN_TARGET=${config.users.users.me.home}/notes
|
mkdir -p ${lib.escapeShellArg kieran.target}
|
||||||
mkdir -p "$KIERAN_TARGET"
|
${pkgs.nextcloud-client}/bin/nextcloudcmd --user ${kieran.user} --password ${lib.escapeShellArg kieran.password} --path /Notes ${lib.escapeShellArg kieran.target} ${kieran.endpoint}
|
||||||
${pkgs.nextcloud-client}/bin/nextcloudcmd --user ${kieran.user} --password ${lib.escapeShellArg kieran.password} --path /Notes "$KIERAN_TARGET" ${kieran.endpoint}
|
|
||||||
'';
|
'';
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
@@ -76,8 +76,32 @@ in {
|
|||||||
${pkgs.findutils}/bin/find ${config.users.users.me.home}/cloud/syncthing/library -type f
|
${pkgs.findutils}/bin/find ${config.users.users.me.home}/cloud/syncthing/library -type f
|
||||||
${pkgs.findutils}/bin/find ${config.users.users.me.home}/cloud/Seafile/Books -type f
|
${pkgs.findutils}/bin/find ${config.users.users.me.home}/cloud/Seafile/Books -type f
|
||||||
} | ${pkgs.fzf}/bin/fzf)"
|
} | ${pkgs.fzf}/bin/fzf)"
|
||||||
${pkgs.zathura}/bin/zathura "$book"
|
exec ${pkgs.zathura}/bin/zathura "$book"
|
||||||
'')
|
'')
|
||||||
|
(let
|
||||||
|
kieran = {
|
||||||
|
user = "kieran.meinhardt@gmail.com";
|
||||||
|
password = lib.fileContents <secrets/mega/password>;
|
||||||
|
};
|
||||||
|
megatools = command: "${pkgs.megatools}/bin/megatools ${command} --username ${lib.escapeShellArg kieran.user} --password ${lib.escapeShellArg kieran.password}";
|
||||||
|
in
|
||||||
|
pkgs.writers.writeDashBin "book-mega" ''
|
||||||
|
set -efu
|
||||||
|
selection="$(${megatools "ls"} | ${pkgs.fzf}/bin/fzf)"
|
||||||
|
test -n "$selection" || exit 1
|
||||||
|
|
||||||
|
tmpdir="$(mktemp -d)"
|
||||||
|
trap clean EXIT
|
||||||
|
clean() {
|
||||||
|
rm -rf "$tmpdir"
|
||||||
|
}
|
||||||
|
|
||||||
|
(
|
||||||
|
cd "$tmpdir"
|
||||||
|
${megatools "get"} "$selection"
|
||||||
|
exec ${pkgs.zathura}/bin/zathura "$(basename "$selection")"
|
||||||
|
)
|
||||||
|
'')
|
||||||
];
|
];
|
||||||
|
|
||||||
fileSystems."/media/moodle" = {
|
fileSystems."/media/moodle" = {
|
||||||
|
|||||||
Reference in New Issue
Block a user