-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.zig
94 lines (76 loc) · 3.66 KB
/
main.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const std = @import("std");
const EXIT_SUCCESS = 0;
const allocator = std.heap.page_allocator;
/// Executes a command using /bin/sh (since zig requires that every field be
/// initialized.
fn execCommand(command: []const u8) void {
const result = std.process.Child.run(.{
.allocator = std.heap.page_allocator,
// slice of anonymous, read only array pointer
.argv = &[_][]const u8{ "/bin/sh", "-c", command },
});
if (result) |r| {
std.log.debug("{s}\n", .{r.stdout});
} else |err| {
std.log.err("Failed to execute: {s}, {any}\n", .{ command, err });
std.process.exit(1);
}
}
fn waitInput() void {
const stdin = std.io.getStdIn().reader();
std.log.info("Press enter to continue: ", .{});
_ = stdin.readUntilDelimiterOrEofAlloc(allocator, '\n', 5075) catch {};
}
/// This function tries to install Xcode, and if it cannot
/// it runs the xcode installer. I had to work through RunError!RunResult
/// unions that were weird.
fn installXcode() !void {
const result = try std.process.Child.run(.{
.allocator = std.heap.page_allocator,
.argv = &[_][]const u8{ "xcode-select", "-p" },
});
if (result.term.Exited == EXIT_SUCCESS) {
std.log.info("Xcode is already installed\n", .{});
return;
}
std.log.info("Installing xCode Command Line Tools...\n", .{});
execCommand("xcode-select --install");
execCommand("sudo xcodebuild -license accept");
}
// Set log level using public decl
pub const log_level: std.log.Level = .debug;
pub fn main() !void {
std.log.info("Setting up macOS\n\n", .{});
std.log.info("################################################################################\n", .{});
std.log.info("Xcode Commandline Tools\n", .{});
std.log.info("################################################################################\n", .{});
installXcode() catch {};
std.log.info("################################################################################\n", .{});
std.log.info("Homebrew Packages\n", .{});
std.log.info("################################################################################\n", .{});
execCommand("scripts/brew.sh");
std.log.info("Finished installing Homebrew packages\n", .{});
execCommand("scripts/cli.sh");
std.log.info("Finished setting up fzf completion\n", .{});
std.log.info("################################################################################\n", .{});
std.log.info("MacOS Apps\n", .{});
std.log.info("################################################################################\n", .{});
std.log.info("You should already be signed into the App Store to continue\n", .{});
waitInput();
execCommand("scripts/setup_mas.sh");
std.log.info("Finished installing mac apps\n", .{});
std.log.info("################################################################################\n", .{});
std.log.info("Tmux Plugins\n", .{});
std.log.info("################################################################################\n", .{});
execCommand("scripts/tmux_tpm.sh");
std.log.info("Finished installing tmux plugins\n", .{});
std.log.info("################################################################################\n", .{});
std.log.info("Configuration\n", .{});
std.log.info("################################################################################\n", .{});
waitInput();
execCommand("scripts/osx.sh");
std.log.info("Finished configuring MacOS defaults. NOTE: restart is needed\n", .{});
execCommand("setup_stow.sh");
std.log.info("Finished stowing dotfiles\n", .{});
std.process.exit(0);
}