build: add mise root tasks
e25f9ad95a1f7336145cac07d0305365815945f6
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: 72a1d7c20d06
bugabingas dorkfiles
e25f9ad95a1f7336145cac07d0305365815945f6
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+255 / −9 text lines
+8 / −9 text lines
new file mode 100644+70 / −0 text lines
[settings]unix_default_inline_shell_args = "nu -c"windows_default_inline_shell_args = "nu -c"[tasks.default]description = "List tasks"run = "mise tasks ls"[tasks.link]description = "Initialize crypto, install hooks, verify, and link dorkfiles into HOME"run = "java bootstripper.java bootstrap"[tasks.nugu-shaders]description = "Compile checked-in Quickshell shaders from source"run = [ "mkdir quickshell/nuguland/shaders", "/usr/lib/qt6/bin/qsb --glsl 330 --hlsl 50 --msl 12 -o quickshell/nuguland/shaders/aurora.frag.qsb quickshell/nuguland/shaders/aurora.frag",][tasks.check]description = "Verify crypto filters, hooks, staged secrets, and symlink manifests"run = "java bootstripper.java check"[tasks.clean]description = "Remove managed dorkfiles links from HOME"run = "java bootstripper.java clean"[tasks.pre-commit]description = "Run the same checks as the Git pre-commit hook"run = "java bootstripper.java pre-commit"[tasks.test]description = "Run Podman integration test for all symlink manifests"usage = '''arg "[hostname]" default="desktop"'''run = 'java ./scripts/dotfiles_integration_test.java "{{usage.hostname}}"'[tasks.init-crypto]description = "Create initial crypto salt"run = "java bootstripper.java init-crypto"[tasks.hooks]description = "Install Git hooks"run = "java bootstripper.java install-hooks"[tasks.unlink]description = "Remove managed dorkfiles links from HOME"run = "java bootstripper.java clean"[tasks.setup]description = "Initial setup: link dorkfiles and fix permissions"depends = ["link", "fix-permissions"][tasks.import-winget]description = "Install previously exported winget apps"run = "winget import C:/Users/okr/Tools/winget_installed_apps.json"[tasks.fix-permissions]description = "Fix local file permissions"run = "java scripts/fix_permissions.java"[tasks.vcs-remote]description = "Set dorkfiles origin to vcs.bugabinga.net"run = [ "git remote remove origin", "git remote add origin git@vcs.bugabinga.net:dotfiles.git", "git fetch", "git branch --set-upstream-to=origin/trunk trunk",]new file mode 100644+167 / −0 text lines
import java.io.*;import java.nio.file.*;import java.time.*;import java.util.*;import java.util.stream.*;public class dotfiles_integration_test { static Path root; public static void main(String[] args) throws Exception { if (args.length > 0 && args[0].equals("--inside")) inside(args.length > 1 ? args[1] : "desktop"); else host(args.length > 0 ? args[0] : "desktop"); } static void host(String hostname) throws Exception { root = Path.of(run(null, "git", "rev-parse", "--show-toplevel").trim()); var key = root.resolve(".git/dotfiles-aes.key"); if (!Files.isReadable(key)) fail("missing " + key); var container = "dotfiles-integration-" + LocalDateTime.now() + "-" + ProcessHandle.current().pid(); container = container.replaceAll("[^A-Za-z0-9_.-]", "-"); try { run(null, "podman", "run", "--name", container, "--rm", "-d", "--hostname", hostname, "-e", "PRIMARY_HOSTNAME=" + hostname, "-v", root + ":/src:ro", "-v", key + ":/dotfiles-aes.key:ro", "registry.fedoraproject.org/fedora:latest", "sleep", "infinity"); run(null, "podman", "exec", container, "dnf", "-qy", "--setopt=install_weak_deps=False", "install", "git-core", "java-latest-openjdk-devel"); run(null, "podman", "exec", container, "git", "config", "--global", "--add", "safe.directory", "/src"); run(null, "podman", "exec", container, "mkdir", "-p", "/root/work"); run(null, "podman", "exec", container, "git", "clone", "--quiet", "--no-local", "/src", "/root/work/dotfiles"); run(null, "podman", "exec", container, "install", "-m", "600", "/dotfiles-aes.key", "/root/work/dotfiles/.git/dotfiles-aes.key"); run(null, "podman", "exec", "-w", "/root/work/dotfiles", container, "javac", "-d", "/tmp/dotfiles-test-classes", "/src/scripts/dotfiles_integration_test.java"); run(null, "podman", "exec", "-w", "/root/work/dotfiles", container, "java", "-cp", "/tmp/dotfiles-test-classes", "dotfiles_integration_test", "--inside", hostname); } finally { runAllowFail(null, "podman", "rm", "-f", container); } } static void inside(String primaryHostname) throws Exception { root = Path.of(".").toAbsolutePath().normalize(); System.out.println("rootless=" + rootless()); ok("deps"); System.out.println(run(root, "git", "--version").trim()); System.out.println(run(root, "java", "-version").lines().findFirst().orElse("java")); run(root, "java", "bootstripper.java", "install-hooks"); if (!Files.isExecutable(root.resolve(".git/hooks/pre-commit"))) fail("hook-executable"); if (!Files.readString(root.resolve(".git/hooks/pre-commit")).contains("exec java bootstripper.java pre-commit")) fail("hook-content"); ok("install-hooks"); if (!run(root, "git", "show", "HEAD:nushell/secrets.nu").startsWith("DFAES1")) fail("committed-encrypted"); ok("committed-encrypted"); var hosts = new ArrayList<String>(); try (var s = Files.list(root)) { s.filter(p -> p.getFileName().toString().endsWith(".symlinks")) .map(p -> p.getFileName().toString().replaceFirst("\\.symlinks$", "")) .sorted().forEach(hosts::add); } System.out.println("primary-manifest=" + primaryHostname + ".symlinks"); System.out.println("manifests=" + String.join(" ", hosts)); for (var host : hosts) runManifest(host); ok("symlink-manifests:" + hosts.size()); if (Files.readString(root.resolve("nushell/secrets.nu")).startsWith("DFAES1")) fail("worktree-still-encrypted"); ok("worktree-decrypted"); run(root, "java", "bootstripper.java", "pre-commit"); ok("pre-commit"); freshCryptoSmoke(); System.out.println("RESULT:ok"); } static void runManifest(String host) throws Exception { var manifest = root.resolve(host + ".symlinks"); var home = Path.of("/tmp/home-" + host); System.out.println("manifest=" + manifest.getFileName()); deleteTree(home); Files.createDirectories(home); var env = Map.of("HOSTNAME", host); run(root, env, "java", "-Duser.home=" + home, "bootstripper.java", "bootstrap"); ok("bootstrap:" + host); run(root, env, "java", "-Duser.home=" + home, "bootstripper.java", "check"); ok("check:" + host); forEachMapping(manifest, (source, target) -> { var path = targetPath(home, target); if (!Files.isSymbolicLink(path)) throw new RuntimeException("FAIL:link:" + host + ":" + target); }); ok("links:" + host); run(root, env, "java", "-Duser.home=" + home, "bootstripper.java", "clean"); ok("clean:" + host); } static void freshCryptoSmoke() throws Exception { var repo = Path.of("/tmp/fresh-crypto"); var home = Path.of("/tmp/fresh-crypto-home"); deleteTree(repo); deleteTree(home); Files.createDirectories(repo.resolve("tools")); Files.createDirectories(home); Files.copy(root.resolve("bootstripper.java"), repo.resolve("bootstripper.java")); Files.copy(root.resolve("tools/aes.java"), repo.resolve("tools/aes.java")); Files.writeString(repo.resolve(".secrets"), "secret.txt\n"); Files.writeString(repo.resolve("mini.symlinks"), "dummy.txt\n~/dummy.txt\n"); Files.writeString(repo.resolve("secret.txt"), "not a real secret\n"); Files.writeString(repo.resolve("dummy.txt"), "dummy\n"); run(repo, "git", "init", "--quiet"); var env = Map.of("DOTFILES_AES_PASSPHRASE", "test"); run(repo, env, "java", "bootstripper.java", "init-crypto"); run(repo, env, "java", "bootstripper.java", "check"); run(repo, env, "git", "add", ".dotfiles-aes-salt", ".secrets", "bootstripper.java", "tools/aes.java", "mini.symlinks", "dummy.txt", "secret.txt"); run(repo, env, "java", "bootstripper.java", "check"); if (!run(repo, "git", "show", ":secret.txt").startsWith("DFAES1")) fail("fresh-staged-encrypted"); var env2 = new HashMap<>(env); env2.put("HOSTNAME", "mini"); run(repo, env2, "java", "-Duser.home=" + home, "bootstripper.java", "bootstrap"); if (!Files.isSymbolicLink(home.resolve("dummy.txt"))) fail("fresh-link"); run(repo, env2, "java", "-Duser.home=" + home, "bootstripper.java", "clean"); ok("fresh-crypto"); } interface Mapping { void accept(String source, String target) throws Exception; } static void forEachMapping(Path manifest, Mapping mapping) throws Exception { String source = null; for (var raw : Files.readAllLines(manifest)) { var line = raw.strip(); if (line.isEmpty()) continue; if (source == null) source = line; else { mapping.accept(source, line); source = null; } } if (source != null) fail("missing target after " + source); } static Path targetPath(Path home, String target) { return target.startsWith("~/") ? home.resolve(target.substring(2)) : Path.of(target); } static String rootless() throws IOException { var p = Path.of("/proc/self/uid_map"); if (!Files.exists(p)) return "unknown"; var parts = Files.readString(p).trim().split("\\s+"); return parts.length >= 2 && parts[0].equals("0") && !parts[1].equals("0") ? "yes" : "unknown"; } static void deleteTree(Path p) throws IOException { if (!Files.exists(p)) return; try (var s = Files.walk(p)) { for (var x : s.sorted(Comparator.reverseOrder()).toList()) Files.deleteIfExists(x); } } static void ok(String what) { System.out.println("ok:" + what); } static void fail(String what) { throw new RuntimeException("FAIL:" + what); } static String run(Path dir, String... cmd) throws Exception { return run(dir, Map.of(), cmd); } static String run(Path dir, Map<String, String> env, String... cmd) throws Exception { var pb = new ProcessBuilder(cmd); if (dir != null) pb.directory(dir.toFile()); pb.environment().putAll(env); var p = pb.redirectErrorStream(true).start(); var out = new String(p.getInputStream().readAllBytes()); var code = p.waitFor(); if (code != 0) throw new RuntimeException(String.join(" ", cmd) + "\n" + out); return out; } static void runAllowFail(Path dir, String... cmd) { try { run(dir, cmd); } catch (Exception ignored) {} }}new file mode 100644+10 / −0 text lines
import java.nio.file.*;import java.util.*;public class fix_permissions { public static void main(String[] args) throws Exception { if (!System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("linux")) return; var profile = Path.of(System.getProperty("user.home"), ".mozilla/firefox/qrza8u52.default-release"); if (Files.exists(profile)) new ProcessBuilder("chmod", "700", profile.toString()).inheritIO().start().waitFor(); }}