dotfiles/scripts/sysupdate

42 lines
1.3 KiB
Text
Executable file

#!/usr/bin/env scriptisto
(*
scriptisto-begin
script_src: sysupdate.ml
build_cmd: dune build sysupdate.exe
target_bin: ./_build/default/sysupdate.exe
files:
- path: dune
content: (executable (name sysupdate) (libraries clap unix))
scriptisto-end
*)
let run cmd =
let splits = String.split_on_char ' ' cmd in
let pipe = Unix.open_process_in ("which " ^ (List.nth splits 0)) in
let status = Unix.close_process_in pipe in
match status with
| Unix.WEXITED 0 ->
let sep_string = String.make (8 + String.length cmd) '=' in
Stdlib.print_endline sep_string;
Stdlib.print_endline ("Running \u{001b}[32m" ^ cmd ^ "\u{001b}[0m");
Stdlib.print_endline sep_string;
let status = Sys.command cmd in
if status != 0 then
raise
(Failure
(String.concat " "
[ "Command"; cmd; "exited with code"; string_of_int status ]))
| _ ->
String.concat " " [ "Command"; cmd; "not found." ] |> Stdlib.print_endline
let () =
Clap.description "Update the system";
let background = Clap.flag ~set_long:"background" ~set_short:'b' false in
Clap.close ();
if not background then
run "nvim '+:PackerSync' '+:CocUpdate' '+:TSUpdate'";
run "paru -Syu --noconfirm";
run "rustup update";
run "fw sync"