dotfiles
bugabingas dorkfiles
owned by bugabinga
bye bye cosmopolitan, hello java
52636d45e086a7f26643b3ab99203401164bb4a7
Oliver Krylow <o.krylow@isp-insoft.de> ·
unsigned
Browse filesCompare with HEAD
Changed files (2)
3 -- [x] remove cosmopolitan from git
4 -- [ ] add download script for cross9 and cosmopolitan
7 3 - [ ] what do we do about ssh and gpg keys? or secrets in general?
8 4 - [x] say goodbye to gpg, too hard for me...
9 -- [ ] how to handle finding the symlink file in bootstripper? turns out, getting path of executable is not trivial.
10 -- [ ] cosmopolitan exe rewrites itself on first use. how do we handle this so a pristine copy is in git...?
new file mode 100644 1 +import java.
nio.
file.
*;
6 + public static void main(
String[] arguments)
throws Exception {
7 + if(arguments.length
== 0){
11 + var dorkfiles_root
= Path.of(arguments[
0]).toRealPath();
12 + System.out.printf(
"Assuming dorkfiles root repo in %s.%n", emphasize_local(dorkfiles_root.toString()));
13 + decrypt_secrets(dorkfiles_root.resolve(
"secrets"));
14 + var hostname
= hostname();
15 + System.out.printf(
"Hostname: %s%n", emphasize_global(hostname));
16 + var symlinks_file
= hostname
+ ".symlinks";
17 + create_symlinks(dorkfiles_root.resolve(symlinks_file));
19 + static void decrypt_secrets(
Path secrets_root)
throws Exception {
20 + System.out.printf(
"Decrypting files in %s folder.%n", emphasize_local(secrets_root.getFileName().toString()));
22 + static void create_symlinks(
Path symlinks_file)
throws Exception {
23 + System.out.printf(
"Creating symlinks as defined in %s file.%n", emphasize_local(symlinks_file.getFileName().toString()));
24 + var lines
= Files.readAllLines(symlinks_file);
25 + String source
= null;
26 + String target
= null;
27 + for(
String line
: lines){
28 + if(line.isBlank())
continue;
29 + if (source
== null) source
= line;
30 + else if (target
== null) target
= line;
31 + if(source
!= null && target
!= null){
32 + link(source, target);
38 + static void link(
String source,
String target)
throws Exception {
39 + var home
= System.getProperty(
"user.home");
40 + var source_path
= Path.of(source.replace(
"~", home)).toAbsolutePath();
41 + var target_path
= Path.of(target.replace(
"~", home)).toAbsolutePath();
42 + var is_directory
= Files.isDirectory(source_path);
43 + if(
Files.exists(target_path)){
44 + System.out.printf(
"%s already exists! Not linking %s.%n", emphasize_global(target_path.toString()), emphasize_local(source_path.toString()));
47 + System.out.printf(
"%s ➔ %s.%n", emphasize_local(source_path.toString()), emphasize_local(target_path.toString()));
49 + Files.createDirectories(target_path);
52 + Files.createDirectories(target_path.getParent());
55 + Files.createSymbolicLink(source_path, target_path);
56 + }
catch (
Exception __) {
62 + var operating_system
= System.getProperty(
"os.name");
63 + if(operating_system.toLowerCase().contains(
"win")){
64 + var process
= new ProcessBuilder();
65 + var command
= process.command();
66 + command.add(
"cmd.exe");
68 + command.add(
"mklink");
72 + command.add(target_path.toString());
73 + command.add(source_path.toString());
82 + static String hostname()
throws Exception {
83 + var process
= new ProcessBuilder()
84 + .command(
"hostname")
88 + try(
var reader
= new InputStreamReader(process.getInputStream()))
91 + var output
= new StringBuilder();
92 + while((character
= reader.read())
!= -1){
93 + if(character
== '\n' || character
== '\r')
continue;
94 + output.append((
char)character);
96 + return output.toString();
99 + static void usage() {
100 + System.out.printf(
"Bootstraps bugabingas %s.%n", emphasize_local(
"dorkfiles"));
101 + System.out.printf(
"%s: java bootstripper.java <dotfiles root path>%n", emphasize_global(
"Usage"));
103 + static void exit() {
106 + static String emphasize_global(
String message) {
107 + return "\033[4m" + message
+ "\033[0m";
109 + static String emphasize_local(
String message) {
110 + return "\033[3m" + message
+ "\033[0m";
112 + static void fail(
String message,
Object... arguments) {
113 + System.out.printf(message, arguments);
116 + static void fail() {