1 1 import static java.
text.
MessageFormat.
format;
3 +import java.
io.
ByteArrayOutputStream;
3 4 import java.
io.
IOException;
4 -import java.
io.
InputStreamReader;
5 +import java.
net.
InetAddress;
6 +import java.
nio.
charset.
StandardCharsets;
5 7 import java.
nio.
file.
Files;
6 8 import java.
nio.
file.
LinkOption;
7 9 import java.
nio.
file.
Path;
10 +import java.
nio.
file.
attribute.
PosixFilePermission;
8 11 import java.
nio.
file.
attribute.
PosixFilePermissions;
12 +import java.
security.
SecureRandom;
13 +import java.
util.
ArrayList;
14 +import java.
util.
Arrays;
15 +import java.
util.
Base64;
16 +import java.
util.
HashSet;
9 17 import java.
util.
List;
18 +import java.
util.
Set;
19 +import java.
util.
regex.
Pattern;
20 +import java.
util.
stream.
Collectors;
21 +import javax.
crypto.
SecretKeyFactory;
22 +import javax.
crypto.
spec.
PBEKeySpec;
11 24 class bootstripper {
13 25 private final static String operating_system
= System.getProperty(
"os.name");
14 26 private final static boolean win32
= operating_system.toLowerCase().contains(
"win");
27 + private final static String filter_name
= "dotfiles-aes";
28 + private final static String key_file
= ".git/dotfiles-aes.key";
29 + private final static String salt_file
= ".dotfiles-aes-salt";
30 + private final static String secrets_file
= ".secrets";
31 + private final static String attributes_begin
= "# BEGIN bootstripper secrets";
32 + private final static String attributes_end
= "# END bootstripper secrets";
33 + private final static byte[] aes_magic
= new byte[] {
'D',
'F',
'A',
'E',
'S',
'1' };
34 + private final static int salt_bytes
= 32;
35 + private final static int derived_key_bits
= 512;
36 + private final static int pbkdf2_iterations
= 310_000;
16 38 public static void main(
String[] arguments)
throws Throwable {
39 + var command
= "bootstrap";
17 40 var dorkfile_path_input
= ".";
18 - var do_clean
= false;
20 42 if (arguments.length
== 1) {
21 - if (
"clean".equals(arguments[
0])) {
43 + if (is_command(arguments[
0]))
44 + command
= arguments[
0];
24 46 dorkfile_path_input
= arguments[
0];
26 47 }
else if (arguments.length
== 2) {
27 - if (
"clean".equals(arguments[
0])) {
29 - dorkfile_path_input
= arguments[
1];
48 + if (
!is_command(arguments[
0])) {
52 + command
= arguments[
0];
53 + dorkfile_path_input
= arguments[
1];
34 54 }
else if (arguments.length
> 2) {
38 - var dorkfiles_root
= Path.of(dorkfile_path_input).toRealPath();
39 - log(
"Assuming dorkfiles root repo in {0}.",
40 - emphasize_local(dorkfiles_root.toString()));
41 - var hostname
= hostname();
42 - log(
"Hostname: {0}", emphasize_global(hostname));
43 - var symlinks_file
= dorkfiles_root.resolve(hostname
+ ".symlinks");
44 - if (
Files.exists(symlinks_file)) {
46 - delete_symlinks(dorkfiles_root, symlinks_file);
48 - create_symlinks(dorkfiles_root, symlinks_file);
50 - throw fail(
"Expected a file containing symlinks at: {0}. Found nothing!",
59 + var root
= Path.of(dorkfile_path_input).toRealPath();
60 + if (
"init-crypto".equals(command)) {
64 + if (
"check".equals(command)) {
65 + setup_crypto(root,
false);
70 + log(
"Assuming dorkfiles root repo in {0}.", emphasize_local(root.toString()));
71 + if (
"clean".equals(command)) {
72 + var symlinks_file
= symlinks_file(root);
73 + delete_symlinks(root, symlinks_file);
77 + setup_crypto(root,
true);
79 + var symlinks_file
= symlinks_file(root);
80 + create_symlinks(root, symlinks_file);
83 + static boolean is_command(
String argument) {
84 + return "bootstrap".equals(argument)
|| "clean".equals(argument)
|| "check".equals(argument)
|| "init-crypto".equals(argument);
87 + static void init_crypto(
Path root)
throws Throwable {
88 + require_git_repo(root);
89 + var salt
= root.resolve(salt_file);
90 + if (
Files.exists(salt)) {
91 + log(
"Crypto salt already exists: {0}", emphasize_local(salt_file));
94 + var bytes
= new byte[salt_bytes];
95 + new SecureRandom().nextBytes(bytes);
96 + Files.writeString(salt,
Base64.getEncoder().encodeToString(bytes)
+ "\n",
StandardCharsets.
UTF_8);
97 + log(
"Created crypto salt: {0}", emphasize_local(salt_file));
100 + static void setup_crypto(
Path root,
boolean restore)
throws Throwable {
101 + require_git_repo(root);
102 + var secrets
= read_secrets(root);
103 + if (secrets.isEmpty())
105 + require_normal_gitdir(root);
106 + install_filter(root);
107 + write_attributes(root, secrets);
109 + self_test_aes(root);
111 + restore_tracked_secrets(root, secrets);
112 + apply_secret_permissions(root, secrets);
113 + install_pre_commit_hook(root);
116 + static void require_git_repo(
Path root)
throws Throwable {
117 + run(root,
List.of(
"git",
"rev-parse",
"--is-inside-work-tree"),
null,
false);
120 + static void require_normal_gitdir(
Path root)
throws Throwable {
121 + if (
!Files.isDirectory(root.resolve(
".git")))
122 + throw fail(
"Expected normal .git directory. Linked worktrees are not supported yet.");
125 + static List<
String>
read_secrets(
Path root)
throws IOException {
126 + var path
= root.resolve(secrets_file);
127 + if (
!Files.exists(path))
129 + var secrets
= new ArrayList<
String>();
130 + for (
var raw
: Files.readAllLines(path)) {
131 + var line
= raw.strip();
132 + if (line.isEmpty()
|| line.startsWith(
"#"))
134 + if (line.contains(
" ")
|| line.contains(
"\t")
|| line.startsWith(
"/")
|| line.contains(
"\\"))
135 + throw new IllegalArgumentException(
"invalid secret path: " + line);
141 + static void install_filter(
Path root)
throws Throwable {
142 + run(root,
List.of(
"git",
"config",
"--local",
"filter." + filter_name
+ ".clean",
143 + "java tools/aes.java encrypt --key-file " + key_file),
null,
false);
144 + run(root,
List.of(
"git",
"config",
"--local",
"filter." + filter_name
+ ".smudge",
145 + "java tools/aes.java decrypt --key-file " + key_file),
null,
false);
146 + run(root,
List.of(
"git",
"config",
"--local",
"filter." + filter_name
+ ".required",
"true"),
null,
false);
149 + static void write_attributes(
Path root,
List<
String> secrets)
throws IOException {
150 + var attributes
= root.resolve(
".git/info/attributes");
151 + Files.createDirectories(attributes.getParent());
152 + var previous
= Files.exists(attributes)
? Files.readString(attributes)
: "";
153 + var lines
= new ArrayList<
String>();
154 + var in_block
= false;
155 + for (
var line
: previous.split(
"\n",
-1)) {
156 + if (attributes_begin.equals(line)) {
160 + if (attributes_end.equals(line)) {
164 + if (
!in_block
&& !line.isEmpty())
167 + lines.add(attributes_begin);
168 + for (
var secret
: secrets)
169 + lines.add(secret
+ " -text filter=" + filter_name
+ " -diff");
170 + lines.add(attributes_end);
171 + Files.writeString(attributes,
String.join(
"\n", lines)
+ "\n",
StandardCharsets.
UTF_8);
174 + static void ensure_key(
Path root)
throws Throwable {
175 + var key
= root.resolve(key_file);
176 + if (
Files.exists(key))
178 + var salt
= read_salt(root);
179 + var passphrase
= passphrase();
181 + var factory
= SecretKeyFactory.getInstance(
"PBKDF2WithHmacSHA256");
182 + var spec
= new PBEKeySpec(passphrase, salt, pbkdf2_iterations, derived_key_bits);
183 + var encoded
= factory.generateSecret(spec).getEncoded();
184 + Files.writeString(key,
Base64.getEncoder().encodeToString(encoded)
+ "\n",
StandardCharsets.
UTF_8);
185 + chmod(key,
"rw-------");
186 + log(
"Cached dotfiles AES key in {0}", emphasize_local(key_file));
188 + Arrays.fill(passphrase,
'\0');
192 + static byte[] read_salt(
Path root)
throws IOException {
193 + var path
= root.resolve(salt_file);
194 + if (
!Files.exists(path))
195 + throw new IllegalStateException(
"Missing " + salt_file
+ ". Run `java bootstripper.java init-crypto` once for this repo.");
196 + return Base64.getDecoder().decode(
Files.readString(path).trim());
199 + static char[] passphrase() {
200 + var from_env
= System.getenv(
"DOTFILES_AES_PASSPHRASE");
201 + if (from_env
!= null && !from_env.isEmpty())
202 + return from_env.toCharArray();
203 + var console
= System.console();
204 + if (console
== null)
205 + throw new IllegalStateException(
"No console available. Set DOTFILES_AES_PASSPHRASE for non-interactive bootstrap.");
206 + var first
= console.readPassword(
"[%s]:", emphasize_global(
"Dotfiles AES passphrase"));
207 + var second
= console.readPassword(
"[%s]:", emphasize_global(
"Repeat passphrase"));
208 + if (
!Arrays.equals(first, second))
209 + throw new IllegalStateException(
"Passphrases do not match.");
210 + Arrays.fill(second,
'\0');
214 + static void self_test_aes(
Path root)
throws Throwable {
215 + var plain
= "bootstripper self-test".getBytes(
StandardCharsets.
UTF_8);
216 + var encrypted
= run(root,
List.of(
"java",
"tools/aes.java",
"encrypt",
"--key-file", key_file), plain,
false).stdout;
217 + if (
!starts_with(encrypted, aes_magic))
218 + throw fail(
"AES self-test did not produce expected magic header.");
219 + var decrypted
= run(root,
List.of(
"java",
"tools/aes.java",
"decrypt",
"--key-file", key_file), encrypted,
false).stdout;
220 + if (
!Arrays.equals(plain, decrypted))
221 + throw fail(
"AES self-test failed to round-trip.");
224 + static void restore_tracked_secrets(
Path root,
List<
String> secrets)
throws Throwable {
225 + var tracked
= new ArrayList<
String>();
226 + for (
var secret
: secrets) {
227 + var result
= run(root,
List.of(
"git",
"ls-files",
"--error-unmatch",
"--", secret),
null,
false,
false);
228 + if (result.exit
== 0) {
229 + tracked.add(secret);
230 + var path
= root.resolve(secret);
231 + if (
Files.exists(path)
&& starts_with(
Files.readAllBytes(path), aes_magic))
232 + Files.delete(path);
235 + if (tracked.isEmpty())
237 + var command
= new ArrayList<
String>();
238 + command.addAll(
List.of(
"git",
"restore",
"--source=HEAD",
"--worktree",
"--"));
239 + command.addAll(tracked);
240 + run(root, command,
null,
false);
243 + static void apply_secret_permissions(
Path root,
List<
String> secrets)
throws IOException {
244 + for (
var secret
: secrets) {
245 + var path
= root.resolve(secret);
246 + if (
Files.exists(path)
&& secret.startsWith(
"ssh/")
&& secret.endsWith(
".key"))
247 + chmod(path,
"rw-------");
251 + static void install_pre_commit_hook(
Path root)
throws IOException {
252 + var hooks
= root.resolve(
".git/hooks");
253 + Files.createDirectories(hooks);
254 + var hook
= hooks.resolve(
"pre-commit");
255 + Files.writeString(hook,
"#!/bin/sh\ncd \"$(git rev-parse --show-toplevel)\" || exit 1\nexec java bootstripper.java check\n",
StandardCharsets.
UTF_8);
256 + chmod(hook,
"rwxr-xr-x");
259 + static void check(
Path root)
throws Throwable {
260 + var secrets
= read_secrets(root);
261 + if (secrets.isEmpty())
263 + check_filter(root);
264 + check_attributes(root, secrets);
265 + check_key_not_tracked(root);
266 + check_staged_secrets(root, secrets);
267 + check_no_tresor_refs(root);
268 + check_staged_plaintext_patterns(root);
269 + log(
"OK bootstripper check passed.");
272 + static void check_filter(
Path root)
throws Throwable {
273 + var clean
= run(root,
List.of(
"git",
"config",
"--local",
"--get",
"filter." + filter_name
+ ".clean"),
null,
false).text().strip();
274 + var smudge
= run(root,
List.of(
"git",
"config",
"--local",
"--get",
"filter." + filter_name
+ ".smudge"),
null,
false).text().strip();
275 + var required
= run(root,
List.of(
"git",
"config",
"--local",
"--get",
"filter." + filter_name
+ ".required"),
null,
false).text().strip();
276 + if (
!clean.equals(
"java tools/aes.java encrypt --key-file " + key_file))
277 + throw fail(
"Unexpected clean filter: {0}", clean);
278 + if (
!smudge.equals(
"java tools/aes.java decrypt --key-file " + key_file))
279 + throw fail(
"Unexpected smudge filter: {0}", smudge);
280 + if (
!required.equals(
"true"))
281 + throw fail(
"Filter is not required.");
284 + static void check_attributes(
Path root,
List<
String> secrets)
throws Throwable {
285 + for (
var secret
: secrets) {
286 + var output
= run(root,
List.of(
"git",
"check-attr",
"text",
"filter",
"diff",
"--", secret),
null,
false).text();
287 + if (
!output.contains(secret
+ ": text: unset"))
288 + throw fail(
"Missing -text attribute for {0}: {1}", secret, output.strip());
289 + if (
!output.contains(secret
+ ": filter: " + filter_name))
290 + throw fail(
"Missing filter attribute for {0}: {1}", secret, output.strip());
291 + if (
!output.contains(secret
+ ": diff: unset"))
292 + throw fail(
"Missing -diff attribute for {0}: {1}", secret, output.strip());
296 + static void check_key_not_tracked(
Path root)
throws Throwable {
297 + var bad
= run(root,
List.of(
"git",
"ls-files",
"--", key_file),
null,
false).text().strip();
298 + if (
!bad.isEmpty())
299 + throw fail(
"Key file is tracked: {0}", key_file);
300 + var staged
= run(root,
List.of(
"git",
"diff",
"--cached",
"--name-only",
"--", key_file),
null,
false).text().strip();
301 + if (
!staged.isEmpty())
302 + throw fail(
"Key file is staged: {0}", key_file);
305 + static void check_staged_secrets(
Path root,
List<
String> secrets)
throws Throwable {
306 + for (
var secret
: secrets) {
307 + var status
= run(root,
List.of(
"git",
"diff",
"--cached",
"--name-status",
"--", secret),
null,
false).text().strip();
308 + if (status.isEmpty()
|| status.startsWith(
"D"))
310 + var blob
= run(root,
List.of(
"git",
"show",
":" + secret),
null,
false).stdout;
311 + if (
!starts_with(blob, aes_magic))
312 + throw fail(
"Staged secret is not encrypted: {0}", secret);
313 + run(root,
List.of(
"java",
"tools/aes.java",
"decrypt",
"--key-file", key_file), blob,
false);
317 + static void check_no_tresor_refs(
Path root)
throws IOException {
318 + try (
var stream
= Files.list(root)) {
319 + var files
= stream.filter(path
-> path.getFileName().toString().endsWith(
".symlinks")).collect(
Collectors.toList());
320 + for (
var file
: files) {
321 + var line_number
= 0;
322 + for (
var line
: Files.readAllLines(file)) {
324 + if (line.strip().startsWith(
"tresor/"))
325 + throw new IllegalStateException(
"tresor reference remains: " + file.getFileName()
+ ":" + line_number);
331 + static void check_staged_plaintext_patterns(
Path root)
throws Throwable {
332 + var diff
= run(root,
List.of(
"git",
"diff",
"--cached",
"-U0"),
null,
false).text();
333 + var patterns
= List.of(
334 + Pattern.compile(
"gh[pousr]_[A-Za-z0-9_]{20,}"),
335 + Pattern.compile(
"github_personal_access_token\\s*\\\":\\s*\\\"[^<G][^\\\"]+\\\""),
336 + Pattern.compile(
"oauth_(access|refresh)_token\\s*=\\s*\\S+"),
337 + Pattern.compile(
"Authorization\\s*[:=]\\s*Bearer\\s+[A-Za-z0-9._-]{20,}",
Pattern.
CASE_INSENSITIVE));
338 + for (
var pattern
: patterns) {
339 + var matcher
= pattern.matcher(diff);
340 + if (matcher.find())
341 + throw fail(
"Potential plaintext secret in staged diff: {0}", matcher.group());
345 + static Path symlinks_file(
Path root)
throws Throwable {
346 + var hostname
= hostname();
347 + log(
"Hostname: {0}", emphasize_global(hostname));
348 + var symlinks_file
= root.resolve(hostname
+ ".symlinks");
349 + if (
!Files.exists(symlinks_file))
350 + throw fail(
"Expected a file containing symlinks at: {0}. Found nothing!", symlinks_file);
351 + return symlinks_file;
55 354 static void create_symlinks(
Path root,
Path symlinks_file)
throws Throwable {
56 - log(
"Creating symlinks as defined in {0} file.",
57 - emphasize_local(symlinks_file.getFileName().toString()));
355 + log(
"Creating symlinks as defined in {0} file.", emphasize_local(symlinks_file.getFileName().toString()));
58 356 var lines
= Files.readAllLines(symlinks_file);
59 357 for_each_mapping(lines, (source, target)
-> link(root, source, target));
62 360 static void delete_symlinks(
Path root,
Path symlinks_file)
throws Throwable {
63 - log(
"Deleting symlinks as defined in {0} file.",
64 - emphasize_local(symlinks_file.getFileName().toString()));
361 + log(
"Deleting symlinks as defined in {0} file.", emphasize_local(symlinks_file.getFileName().toString()));
65 362 var lines
= Files.readAllLines(symlinks_file);
66 363 for_each_mapping(lines, (source, target)
-> delete(root, source, target));
74 371 if (
Files.exists(target_path,
LinkOption.
NOFOLLOW_LINKS)) {
75 372 if (
Files.isSymbolicLink(target_path)) {
76 - log(
"\nOK {0} exists and points to {1}, a symlink indeed!\nDeleting {0}.",
77 - emphasize_global(target_path.toString()),
78 - emphasize_local(source_path.toString()));
373 + log(
"\nOK {0} exists and points to {1}, a symlink indeed!\nDeleting {0}.", emphasize_global(target_path.toString()), emphasize_local(source_path.toString()));
80 374 Files.delete(target_path);
82 - log(
"\nNOPE {0} exists, but it is not a symlink! Clean manually.",
83 - target_path.toString());
376 + log(
"\nNOPE {0} exists, but it is not a symlink! Clean manually.", target_path.toString());
89 382 var home
= System.getProperty(
"user.home");
90 383 var source_path
= root.resolve(source).toAbsolutePath();
91 384 if (
!Files.exists(source_path)) {
92 - log(
"\n{0} does not exist anymore in my dorkfiles. Have I yeeted it?",
93 - emphasize_global(source_path.toString()));
385 + log(
"\n{0} does not exist anymore in my dorkfiles. Have I yeeted it?", emphasize_global(source_path.toString()));
96 388 var target_path
= Path.of(target.replace(
"~", home)).toAbsolutePath();
97 - var is_directory
= Files.isDirectory(source_path);
98 389 if (
Files.exists(target_path,
LinkOption.
NOFOLLOW_LINKS)) {
99 390 if (
Files.exists(target_path)) {
100 - log(
"\nOK {0} already exists!\nNot linking {1}.",
101 - emphasize_global(target_path.toString()),
102 - emphasize_local(source_path.toString()));
391 + log(
"\nOK {0} already exists!\nNot linking {1}.", emphasize_global(target_path.toString()), emphasize_local(source_path.toString()));
105 - log(
"\nNOPE {0} exists, but it points into nirvana. Removing broken link!",
106 - target_path.toString());
394 + log(
"\nNOPE {0} exists, but it points into nirvana. Removing broken link!", target_path.toString());
107 395 Files.delete(target_path);
110 - if (source_path.getParent().endsWith(
"tresor")) {
111 - log(
"\nDetected encrypted file in tresor! {0}", source_path.getFileName());
112 - final var success
= decrypt(source_path, target_path);
114 - log(
"\nDECRYPT {0} to {1}!", source_path, target_path);
116 - log(
"\nFAIL DECRYPT {0} to {1}!", source_path, target_path);
119 - log(
"\nLINK {0} TO {1}.", emphasize_local(source_path.toString()),
120 - emphasize_local(target_path.toString()));
398 + log(
"\nLINK {0} TO {1}.", emphasize_local(source_path.toString()), emphasize_local(target_path.toString()));
121 399 Files.createDirectories(target_path.getParent());
123 - Files.createSymbolicLink(target_path, source_path);
124 - }
catch (
Exception __) {
133 - var process
= new ProcessBuilder();
134 - var command
= process.command();
135 - command.add(
"cmd.exe");
137 - command.add(
"mklink");
138 - if (is_directory) {
141 - command.add(target_path.toString());
142 - command.add(source_path.toString());
143 - log(command.toString());
144 - process.inheritIO().start().onExit().join();
146 - __.printStackTrace();
147 - throw fail(
"Could not create symbolic link!");
400 + if (target_path.getParent().endsWith(
".ssh"))
401 + chmod(target_path.getParent(),
"rwx------");
402 + Files.createSymbolicLink(target_path, source_path);
152 405 static String hostname() throws
Exception {
153 - var process_builder
= new ProcessBuilder().command(
"hostname");
406 + var computername
= System.getenv(
"COMPUTERNAME");
407 + if (computername
!= null && !computername.isBlank())
408 + return computername;
409 + var hostname
= System.getenv(
"HOSTNAME");
410 + if (hostname
!= null && !hostname.isBlank()
&& !"localhost".equals(hostname))
412 + var detected
= InetAddress.getLocalHost().getHostName();
413 + if (
"localhost".equals(detected)
&& System.getenv(
"PREFIX")
!= null)
418 + static void chmod(
Path path,
String permissions) throws
IOException {
156 - process
= process_builder.start().onExit().join();
157 - }
catch (
IOException __) {
158 - process
= new ProcessBuilder()
159 - .command(
"hostnamectl",
"hostname")
164 - try (
var reader
= new InputStreamReader(process.getInputStream())) {
165 - int character
= -1;
166 - var output
= new StringBuilder();
167 - while ((character
= reader.read())
!= -1) {
168 - if (character
== '\n' || character
== '\r')
170 - output.append((
char) character);
172 - var name
= output.toString();
173 - if (
"localhost".equals(name)) {
175 - assert System.getenv(
"PREFIX")
!= null;
422 + Files.setPosixFilePermissions(path,
PosixFilePermissions.fromString(permissions));
423 + }
catch (
UnsupportedOperationException ignored) {
182 - static boolean decrypt(
Path source_path,
Path target_path) throws
IOException {
183 - final var command
= new String[] {
185 - "./tools/aes.java",
187 - source_path.toString(),
188 - target_path.toString(),
190 - final var success
= new ProcessBuilder(command)
194 - .thenApply(p
-> p.exitValue()
== 0)
196 - if (success
&& !win32) {
197 - final var user_read_only
= PosixFilePermissions.fromString(
"r--------");
198 - Files.setPosixFilePermissions(target_path, user_read_only);
427 + static boolean starts_with(
byte[] bytes,
byte[] prefix) {
428 + if (bytes.length
< prefix.length)
430 + for (
var index
= 0; index
< prefix.length; index
++)
431 + if (bytes[index]
!= prefix[index])
436 + static Result run(
Path directory,
List<
String> command,
byte[] input,
boolean inherit_io) throws
Throwable {
437 + return run(directory, command, input, inherit_io,
true);
440 + static Result run(
Path directory,
List<
String> command,
byte[] input,
boolean inherit_io,
boolean fail) throws
Throwable {
441 + var process_builder
= new ProcessBuilder(command).directory(directory.toFile());
443 + process_builder.inheritIO();
444 + var process
= process_builder.start();
445 + if (input
!= null) {
446 + try (
var stdin
= process.getOutputStream()) {
447 + stdin.write(input);
450 + process.getOutputStream().close();
452 + var stdout
= inherit_io
? new byte[
0]
: process.getInputStream().readAllBytes();
453 + var stderr
= inherit_io
? new byte[
0]
: process.getErrorStream().readAllBytes();
454 + var exit
= process.waitFor();
455 + var result
= new Result(exit, stdout, stderr);
456 + if (fail
&& exit
!= 0)
457 + throw fail(
"Command failed ({0}): {1}\n{2}", exit,
String.join(
" ", command), result.error().strip());
203 461 static void usage() {
204 462 log(
"Bootstraps bugabingas {0}.", emphasize_local(
"dorkfiles"));
205 - log(
"{0}: java bootstripper.java [clean] [dotfiles root path]",
206 - emphasize_global(
"Usage"));
463 + log(
"{0}: java bootstripper.java [init-crypto|check|clean] [dotfiles root path]", emphasize_global(
"Usage"));
209 466 static String emphasize_global(
String message) {
241 498 void apply(
A a,
B b) throws
Throwable;
244 - static void for_each_mapping(
List<
String> lines,
ThrowUp<
String,
String> block)
501 + static void for_each_mapping(
List<
String> lines,
ThrowUp<
String,
String> block) throws
Throwable {
246 502 String source
= null;
247 503 String target
= null;
248 504 for (
String line
: lines) {
521 + static class Result {
523 + final byte[] stdout;
524 + final byte[] stderr;
526 + Result(
int exit,
byte[] stdout,
byte[] stderr) {
528 + this.stdout
= stdout;
529 + this.stderr
= stderr;
533 + return new String(stdout,
StandardCharsets.
UTF_8);
537 + return new String(stderr,
StandardCharsets.
UTF_8);