mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-12-24 10:53:56 +01:00
port sysupdate script to ocaml
This commit is contained in:
parent
bc7b64b5b4
commit
5a6e1ffc39
1 changed files with 38 additions and 43 deletions
|
@ -1,47 +1,42 @@
|
||||||
#!/usr/bin/env lua
|
#!/usr/bin/env scriptisto
|
||||||
local function run(cmd)
|
|
||||||
-- check if the command exists
|
|
||||||
local pname = cmd:gmatch("%S+")()
|
|
||||||
local handle = io.popen("which " .. pname .. " 2> /dev/null")
|
|
||||||
handle:read("*a")
|
|
||||||
_, _, exit_code = handle:close()
|
|
||||||
|
|
||||||
if exit_code == 0 then
|
(*
|
||||||
-- 8 is len of text around "running" prompt
|
scriptisto-begin
|
||||||
local len = #cmd + 8
|
script_src: sysupdate.ml
|
||||||
local hr = string.rep("=", len)
|
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 ]))
|
||||||
|
| _ ->
|
||||||
|
Stdlib.print_endline (String.concat " " [ "Command"; cmd; "not found." ])
|
||||||
|
|
||||||
print(
|
let () =
|
||||||
string.format(
|
Clap.description "Update the system";
|
||||||
"%s\nrunning \27[32m%s\27[0m\n%s\n",
|
let background = Clap.flag ~set_long:"background" ~set_short:'b' false in
|
||||||
hr,
|
Clap.close ();
|
||||||
cmd,
|
|
||||||
hr
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
os.execute(cmd)
|
if not background then
|
||||||
else
|
run "nvim '+:PackerSync' '+:CocUpdate' '+:TSUpdate'";
|
||||||
print("\27[31mCouldn't find process with name " .. pname .. "\27[0m in path.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- commands that require interaction
|
|
||||||
local function run_fg()
|
|
||||||
run [[nvim '+:PackerSync' '+:CocUpdate' '+:TSUpdate']]
|
|
||||||
end
|
|
||||||
|
|
||||||
-- commands that require no interaction
|
|
||||||
local function run_bg(args)
|
|
||||||
run [[paru -Syu --noconfirm]]
|
|
||||||
run [[rustup update]]
|
|
||||||
run [[fw sync]]
|
|
||||||
end
|
|
||||||
|
|
||||||
-- if "bg" was passed as argument, only run uninteractive commands
|
|
||||||
if arg[1] ~= "bg" then
|
|
||||||
run_fg()
|
|
||||||
end
|
|
||||||
|
|
||||||
run_bg()
|
|
||||||
|
|
||||||
|
run "paru -Syu --noconfirm";
|
||||||
|
run "rustup update";
|
||||||
|
run "fw sync"
|
||||||
|
|
Loading…
Reference in a new issue