dotfiles
bugabingas dorkfiles
owned by bugabinga
chore: use java shell for mise tasks
362ced6058a0c461ecf13fd3469dff80635a39db
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (5)
7 7 Preserve unrelated dirty work.
8 8 Check `git status --short` before edits.
9 9 Prefer repo paths (`pi/agent/...`) over `$HOME` paths.
10 -Use `mise` tasks; host bootstrap assumes Git + mise, then mise supplies Java/Nushell.
10 +Use `mise` tasks; host bootstrap assumes Git + mise, then mise supplies Java.
11 +Root `mise.toml` tools are dorkfiles bootstrap deps only; other apps come from system/package manager.
12 +Root mise task shell is `scripts/mise_shell.java`, not Nushell/Bash.
11 13 `mise run test` also needs host Podman; its Fedora container installs Git/mise, then mise supplies Java.
12 14 Never print decrypted secrets.
13 15 Do not delete noisy research/cache/untracked files unless explicitly asked.
bootstripper.java
Modified449 449 var target_path
= expand_target(target);
450 450 if (
Files.exists(target_path,
LinkOption.
NOFOLLOW_LINKS)) {
451 451 if (
Files.isSymbolicLink(target_path)) {
452 + var raw_actual
= symlink_target_path(target_path);
453 + if (
!inside_home(raw_actual))
454 + throw fail(
"Target symlink points outside HOME: {0} -> {1}. Move it manually.", target_path, raw_actual);
452 455 if (
!Files.exists(target_path)) {
453 456 log(
"\nRELINK {0}: broken symlink.", emphasize_global(target_path.toString()));
454 457 remove_owned_symlink(target_path);
510 + static Path symlink_target_path(
Path target_path) throws
IOException {
511 + var link
= Files.readSymbolicLink(target_path);
512 + var resolved
= link.isAbsolute()
? link
: target_path.getParent().resolve(link);
513 + return resolved.toAbsolutePath().normalize();
507 516 static Path sibling_backup_path(
Path target_path) throws
Throwable {
508 517 return sibling_path(target_path,
"backup");
2 -"aqua:nushell/nushell" =
"latest" 6 -unix_default_inline_shell_args =
"nu -c" 7 -windows_default_inline_shell_args =
"nu -c" 5 +unix_default_inline_shell_args =
"java scripts/mise_shell.java" 6 +windows_default_inline_shell_args =
"java scripts/mise_shell.java" 10 9 description =
"List tasks" 12 -run =
"mise tasks ls" 11 +run =
'run("mise", "tasks", "ls");' 15 14 description =
"Verify crypto, hooks, secrets, and symlink manifests" 16 -run =
"java bootstripper.java check" 15 +run =
'run("java", "bootstripper.java", "check");' 19 18 description =
"Run Podman integration test" 20 -run =
"java ./scripts/dotfiles_integration_test.java" 19 +run =
'run("java", "./scripts/dotfiles_integration_test.java");' 22 21 [
tasks.
test-inside]
23 22 description =
"Run Podman container checks" 25 -run =
"java ./scripts/dotfiles_integration_test.java --inside" 24 +run =
'run("java", "./scripts/dotfiles_integration_test.java", "--inside");' 28 27 description =
"Link dorkfiles into HOME" 30 - "java bootstripper.java bootstrap",
31 - "java scripts/fix_permissions.java",
29 +run("java", "bootstripper.java", "bootstrap"); 30 +run("java", "scripts/fix_permissions.java"); 35 34 description =
"Remove managed dorkfiles links from HOME" 36 -run =
"java bootstripper.java clean" 35 +run =
'run("java", "bootstripper.java", "clean");' 39 38 description =
"Create initial crypto salt" 41 -run =
"java bootstripper.java init-crypto" 40 +run =
'run("java", "bootstripper.java", "init-crypto");' 44 43 description =
"Install Git hooks" 46 -run =
"java bootstripper.java install-hooks" 45 +run =
'run("java", "bootstripper.java", "install-hooks");' 49 48 description =
"Fix local file permissions" 51 -run =
"java scripts/fix_permissions.java" 50 +run =
'run("java", "scripts/fix_permissions.java");' scripts/dotfiles_integration_test.java
Modified 67 67 System.out.println(run(root,
"git",
"--version").trim());
68 68 System.out.println(run(root,
"mise",
"--version").trim());
69 + var miseTools
= run(root,
"mise",
"ls",
"--current").toLowerCase(
Locale.
ROOT);
70 + if (miseTools.contains(
"nushell")) fail(
"root-mise-nushell-tool");
69 71 System.out.println(run(root,
"java",
"-version").lines().findFirst().orElse(
"java"));
71 73 run(root,
"mise",
"run",
"hook");
scripts/mise_shell.java
Addednew file mode 100644 8 +void main(
String[] args) throws
Exception 10 + if (args.length
!= 1)
12 + System.err.println(
"expected one mise task snippet arg, got " + args.length);
17 + try (
var jshell
= JShell.builder().executionEngine(
"local").out(
System.out).err(
System.err).build())
19 + failed
|= !evalAll(jshell, startup(),
true);
21 + failed
|= !evalAll(jshell, args[
0],
false);
39 +boolean evalAll(
JShell jshell,
String input,
boolean startup)
43 + while (
!rest.isBlank())
45 + var info
= jshell.sourceCodeAnalysis().analyzeCompletion(rest);
46 + if (
!info.completeness().isComplete())
48 + System.err.println((startup
? "startup: " : "")
+ "incomplete snippet: " + info.completeness());
51 + if (
!evalOne(jshell, info.source(), startup))
56 + rest
= info.remaining();
70 +boolean evalOne(
JShell jshell,
String code,
boolean startup)
73 + for (
var event
: jshell.eval(code))
75 + if (event.exception()
!= null)
77 + var message
= event.exception().getMessage();
78 + System.err.println(message
== null ? event.exception().toString()
: message);
81 + var status
= event.status();
82 + if (status
== Snippet.
Status.
REJECTED || status
== Snippet.
Status.
RECOVERABLE_NOT_DEFINED)
84 + jshell.diagnostics(event.snippet()).forEach(d
-> System.err.println((startup
? "startup: " : "")
+ d.getMessage(
Locale.
ROOT)));
105 +import java.nio.charset.
*;
106 +import java.nio.file.
*;
108 +import java.util.regex.
*;
109 +import java.util.stream.
*;
111 +Path CWD = Path.of(
"").toAbsolutePath().normalize();
112 +Map<
String,
String>
ENV = new HashMap<>(
System.getenv());
125 +record Result(
int code,
String out)
134 + String text() {
return out; }
143 + String trimmed() {
return out.strip(); }
152 + List<
String> lines() {
return out.lines().toList(); }
178 +Path path(
String first,
String... more)
180 + return CWD.resolve(
Path.of(first, more)).toAbsolutePath().normalize();
194 + var next
= path(dir);
195 + if (
!Files.isDirectory(next))
196 + throw new IllegalArgumentException(
"not a directory: " + next);
207 +String env(
String name)
209 + return ENV.get(name);
221 +void export(
String name,
String value)
223 + ENV.put(name, value);
234 +ProcessBuilder process(
String... cmd)
236 + var pb
= new ProcessBuilder(cmd).directory(
CWD.toFile());
237 + pb.environment().clear();
238 + pb.environment().putAll(
ENV);
252 +void run(
String... cmd) throws
Exception 254 + var code
= process(cmd).inheritIO().start().waitFor();
256 + throw new RuntimeException(
"command failed (" + code
+ "): " + String.join(
" ", cmd));
266 +Result result(
String... cmd) throws
Exception 268 + var p
= process(cmd).redirectErrorStream(
true).start();
269 + var out
= new String(p.getInputStream().readAllBytes(),
StandardCharsets.
UTF_8);
270 + return new Result(p.waitFor(), out);
281 +String out(
String... cmd) throws
Exception 283 + var r
= result(cmd);
285 + throw new RuntimeException(r.out());
296 +int code(
String... cmd) throws
Exception 298 + return result(cmd).code();
308 +String read(
String file) throws
Exception 310 + return Files.readString(path(file));
321 +void write(
String file,
String text) throws
Exception 323 + var p
= path(file);
324 + var parent
= p.getParent();
325 + if (parent
!= null)
326 + Files.createDirectories(parent);
327 + Files.writeString(p, text);
338 +void mkdir(
String dir) throws
Exception 340 + Files.createDirectories(path(dir));
352 +Path protectDelete(
Path p)
354 + p
= p.toAbsolutePath().normalize();
355 + var home
= Path.of(
System.getProperty(
"user.home")).toAbsolutePath().normalize();
356 + if (p.getParent()
== null || p.equals(home)
|| p.equals(
CWD))
357 + throw new IllegalArgumentException(
"refuse to delete: " + p);
369 +void rm(
String first,
String... more) throws
Exception 371 + var p
= protectDelete(path(first, more));
372 + if (
Files.isDirectory(p,
LinkOption.
NOFOLLOW_LINKS)
&& !Files.isSymbolicLink(p))
373 + throw new IllegalArgumentException(
"is a directory; use rmdir or rmTree: " + p);
374 + Files.deleteIfExists(p);
385 +void rmdir(
String first,
String... more) throws
Exception 387 + Files.deleteIfExists(protectDelete(path(first, more)));
399 +void rmTree(
String first,
String... more) throws
Exception 401 + var p
= protectDelete(path(first, more));
402 + if (
!Files.exists(p,
LinkOption.
NOFOLLOW_LINKS))
404 + if (
Files.isSymbolicLink(p)
|| !Files.isDirectory(p,
LinkOption.
NOFOLLOW_LINKS))
409 + try (
var stream
= Files.walk(p))
411 + for (
var x
: stream.sorted(
Comparator.reverseOrder()).toList())
412 + Files.deleteIfExists(x);
424 +List<
Path> glob(
String pattern) throws
Exception 426 + try (
var stream
= Files.newDirectoryStream(
CWD, pattern))
428 + var paths
= new ArrayList<
Path>();
429 + stream.forEach(paths::add);
430 + paths.sort(
Comparator.naturalOrder());
444 +String which(
String name)
446 + var path
= ENV.getOrDefault(
"PATH",
"");
447 + var extensions
= System.getProperty(
"os.name").toLowerCase(
Locale.
ROOT).contains(
"win")
448 + ? ENV.getOrDefault(
"PATHEXT",
".EXE;.CMD;.BAT").split(
Pattern.quote(
File.pathSeparator))
449 + : new String[] {
"" };
450 + for (
var dir
: path.split(
Pattern.quote(
File.pathSeparator)))
452 + for (
var extension
: extensions)
454 + var candidate
= Path.of(dir, name
+ extension);
455 + if (
Files.isExecutable(candidate))
456 + return candidate.toString();