/.sml Secret
Last active
September 12, 2022 14:02
Revisions
-
lf94 revised this gist
Sep 11, 2022 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -121,4 +121,9 @@ exec [ ] "file" (cwd ^ "/../*") ] (* TODO: Use configuration templates for things like nginx This will be simple: copy (Local [template "templates/nginx.conf" [["key","value"]]]) (Remote ["some place"]) template will return a path to a temporary file It will invoke whatever templating tech you'd like. *) -
lf94 revised this gist
Sep 11, 2022 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -120,3 +120,5 @@ exec [ remote "cd /home/len/www/$(basename $file).git/ && git config --bool core.bare true" ] "file" (cwd ^ "/../*") ] (* TODO: Use configuration templates for things like nginx *) -
lf94 revised this gist
Sep 11, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -105,7 +105,7 @@ exec [ (*------------------------------------------------------------------------------ Example: self-host git projects *) val cwd = "/home/len/Code/len/git-self-host"; exec [ ensure (User "len") Exists, -
lf94 revised this gist
Sep 11, 2022 . 1 changed file with 27 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -76,6 +76,13 @@ fun createSession (user, host, port) in (copy, ensure, remote) end; fun each statements var path = String.concat [ String.concat ["for ", var, " in ", path, "; do "], join "; " statements, "; done" ]; fun shell cmd = cmd; fun exec cmds = print (join " && " cmds); @@ -93,4 +100,23 @@ exec [ shell "/home/len/Wiki/rss.sh > /home/len/Wiki/feed.xml", copy (Local ["/home/len/Wiki/public", "/home/len/Wiki/feed.xml", "/home/len/Wiki/index.css"]) (Remote ["/home/len/www/"]) ] (*------------------------------------------------------------------------------ Example: self-host git projects *) val cwd = "/home/lee/Code/lee/git-self-host"; exec [ ensure (User "len") Exists, ensure (Software "rsync") Exists, ensure (Software "git") Exists, shell String.concat [cwd, "/rss.sh > ", cwd, "/code.xml"], copy (Local [cwd ^ "/code.xml", cwd ^ "/index.css"]) (Remote ["/home/len/www/"]), each [ copy (Local ["$file/.git/"]) (Remote ["/home/len/www/$(basename $file).git"]), remote "cd /home/len/www/$(basename $file).git/ && git config --bool core.bare true" ] "file" (cwd ^ "/../*") ] -
lf94 revised this gist
Sep 11, 2022 . 1 changed file with 1 addition and 9 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,15 +30,7 @@ val join = String.concatWith; fun cp (programInvocation:string) (srcs:string list) (dest:string) = join " " [programInvocation, join " " srcs, dest] ; datatype State = Exists | Fresh datatype OSObject = User of string | Directory of string | Software of string; datatype Location -
lf94 revised this gist
Sep 11, 2022 . 1 changed file with 18 additions and 3 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,21 @@ Write SML programs to output shell code for installations and deployments. Modify as needed. -------------------------------------------------------------------------------- Why not just use shell scripts directly? The lack of a type-system in all shell scripting languages is, when you think about, horrific. It takes one bad input to destroy a system. With types this can lift the level of safety very high, as now the script will not run before it is considered correct. In hindsight it will be clear that all scripting languages should have had strong typing from the beginning. There is not much more to say than that. Hindley-Milner type systems allow a great level of type inference, which means the developer of scripts does not need to type everything. It's this gradient of typing which suits a whole spectrum of needs that is powerful. -------------------------------------------------------------------------------- Utilities *) @@ -76,14 +91,14 @@ fun exec cmds = print (join " && " cmds); (*------------------------------------------------------------------------------ Example: deploy blog to a host *) val target = ("root", "len.falken.directory", "9999"); val (copy, ensure, remote) = createSession target; exec [ ensure (User "len") Exists, ensure (Directory "/home/len/www/") Exists, ensure (Software "rsync") Exists, shell "/home/len/Wiki/rss.sh > /home/len/Wiki/feed.xml", copy (Local ["/home/len/Wiki/public", "/home/len/Wiki/feed.xml", "/home/len/Wiki/index.css"]) (Remote ["/home/len/www/"]) ] -
lf94 revised this gist
Sep 11, 2022 . 1 changed file with 8 additions and 11 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,9 +21,6 @@ fun exec (cmds: string list) = List.foldr (fn (a, b) => a ^ ";\n" ^ b) "" cmds; fun plus (a, b) = String.concat [a, " && ", b]; infix plus; fun fork (a, b) = String.concat [a, " &\n", b]; infix fork; @@ -46,7 +43,7 @@ end fun createSession (user, host, port) = let fun remote cmd = String.concat ["ssh -p ", port, " ", user, "@", host, " -C '", cmd, "'"] ; fun copy (Local from) (Remote to) @@ -57,19 +54,19 @@ fun createSession (user, host, port) = "" ; fun ensure (User user) Exists = (remote o String.concat) ["id ", user, " || useradd -m ", user] | ensure (Directory dir) Exists = (remote o String.concat) ["[ -d \"", dir, "\" ] || mkdir -p ", dir] | ensure (Directory dir) Fresh = (remote o String.concat) ["rm -rf ", dir, " && mkdir -p ", dir] | ensure (Software ware) Exists = (remote o String.concat) ["which ", ware, " || ", PackageManager.install ware] | ensure (Software ware) Fresh = (remote o String.concat) [PackageManager.install ware] | ensure _ _ = "" ; in (copy, ensure, remote) end; fun shell cmd = cmd; @@ -80,7 +77,7 @@ fun exec cmds = print (join " && " cmds); Example: deploy blog to a host *) val target = ("root", "len.falken.directory", "31336"); val (copy, ensure, remote) = createSession target; exec [ ensure (User "len") Exists, -
lf94 revised this gist
Sep 11, 2022 . 1 changed file with 13 additions and 9 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ -------------------------------------------------------------------------------- Utilities *) val join = String.concatWith; fun cp (programInvocation:string) (srcs:string list) (dest:string) = join " " [programInvocation, join " " srcs, dest] @@ -72,17 +72,21 @@ fun createSession (user, host, port) in (copy, ensure, ssh) end; fun shell cmd = cmd; fun exec cmds = print (join " && " cmds); (*------------------------------------------------------------------------------ Example: deploy blog to a host *) val target = ("root", "len.falken.directory", "31336"); val (copy, ensure, ssh) = createSession target; exec [ ensure (User "len") Exists, ensure (Directory "/home/len/www/") Exists, ensure (Software "rsync") Exists, shell "/home/lee/Wiki/rss.sh > /home/lee/Wiki/feed.xml", copy (Local ["/home/lee/Wiki/public", "/home/lee/Wiki/feed.xml", "/home/lee/Wiki/index.css"]) (Remote ["/home/len/www/"]) ] -
lf94 revised this gist
Sep 10, 2022 . 1 changed file with 31 additions and 21 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,41 +10,44 @@ -------------------------------------------------------------------------------- Utilities *) val join = String.concatWith fun cp (programInvocation:string) (srcs:string list) (dest:string) = join " " [programInvocation, join " " srcs, dest] ; fun exec (cmds: string list) = List.foldr (fn (a, b) => a ^ ";\n" ^ b) "" cmds; fun plus (a, b) = String.concat [a, " && ", b]; infix plus; fun login (user, host, port) = String.concat ["ssh -M -p ", port, " ", user, "@", host]; fun fork (a, b) = String.concat [a, " &\n", b]; infix fork; datatype State = Exists | Fresh datatype OSObject = User of string | Directory of string | Software of string; datatype Location = Local of string list | Remote of string list ; (* Change this to a prefered copy program, i.e. scp *) fun rsync (port:string) = cp (String.concat ["rsync -vv -e 'ssh -p ", port, "'"]); (* Change this to the package manager on the remote system, i.e. pacman *) structure PackageManager = struct val pkgman = "apt" fun install software = String.concat [pkgman, " install -y ", software]; end fun createSession (user, host, port) = let fun ssh cmd = String.concat ["ssh -p ", port, " ", user, "@", host, " -C '", cmd, "'"] ; fun copy (Local from) (Remote to) = rsync port from ("'" ^ user ^ "@" ^ host ^ ":" ^ (join " " to) ^ "'") @@ -54,11 +57,17 @@ fun createSession (user, host, port) = "" ; fun ensure (User user) Exists = (ssh o String.concat) ["id ", user, " || useradd -m ", user] | ensure (Directory dir) Exists = (ssh o String.concat) ["[ -d \"", dir, "\" ] || mkdir -p ", dir] | ensure (Directory dir) Fresh = (ssh o String.concat) ["rm -rf ", dir, " && mkdir -p ", dir] | ensure (Software ware) Exists = (ssh o String.concat) ["which ", ware, " || ", PackageManager.install ware] | ensure (Software ware) Fresh = (ssh o String.concat) [PackageManager.install ware] | ensure _ _ = "" ; in (copy, ensure, ssh) end; @@ -69,10 +78,11 @@ end; val target = ("root", "len.falken.directory", "31336"); val (copy, ensure, ssh) = createSession target; print ( ensure (User "joe") Exists plus ensure (Directory "/home/joe/www/") Fresh plus ensure (Software "rsync") Exists plus ensure (Software "rsync") Fresh plus copy (Local ["/home/lee/Test/1.txt", "/home/lee/Test/2.txt", "/home/lee/Test/3.txt"]) (Remote ["/home/joe/www/"]) ) -
lf94 created this gist
Sep 10, 2022 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,78 @@ (*------------------------------------------------------------------------------ REPLICARE recipere + deplicare "to receive" + "explain" Write SML programs to output shell code for installations and deployments. Modify as needed. -------------------------------------------------------------------------------- Utilities *) fun join (withStr: string) (srcs:string list) = let val (_ :: rest) = String.explode (List.foldl (fn (a, b) => b ^ withStr ^ a) "" srcs) in String.implode rest end ; fun cp (programInvocation:string) (srcs:string list) (dest:string) = join " " [programInvocation, join " " srcs, dest] ; fun exec (cmds: string list) = List.foldr (fn (a, b) => a ^ ";\n" ^ b) "" cmds; fun plus (a, b) = a ^ " && " ^ b; infix plus; fun login (user, host, port) = "ssh -M -p " ^ port ^ " " ^ user ^ "@" ^ host; fun fork (a, b) = a ^ " &\n" ^ b; infix fork; datatype Presence = Exists datatype OSObject = User of string | Directory of string | Software of string; datatype Location = Local of string list | Remote of string list ; (* Change this to a prefered copy program, i.e. scp *) fun rsync (port:string) = cp ("rsync -P " ^ port); fun createSession (user, host, port) = let fun ssh cmd = "ssh -p " ^ port ^ " " ^ user ^ "@" ^ host ^ " -C " ^ cmd ; fun copy (Local from) (Remote to) = rsync port from ("'" ^ user ^ "@" ^ host ^ ":" ^ (join " " to) ^ "'") | copy (Remote from) (Local to) = rsync port ["'" ^ user ^ "@" ^ host ^ ":" ^ (join " " from) ^ "'"] (List.nth (to, 0)) | copy _ _ = "" ; fun ensure (User user) Exists = ssh "id " ^ user | ensure (Directory dir) Exists = ssh "'[ -d \"" ^ dir ^ "\" ]'" | ensure (Software ware) Exists = ssh "which " ^ ware ; in (copy, ensure, ssh) end; (*------------------------------------------------------------------------------ Example: deploy blog to a host *) val target = ("root", "len.falken.directory", "31336"); val (copy, ensure, ssh) = createSession target; ensure (User "len") Exists plus ensure (Directory "/home/len/www") Exists plus ensure (Software "rsync") Exists plus copy (Local ["/home/lee/Wiki/public", "/home/lee/Wiki/feed.xml", "/home/lee/Wiki/index.css"]) (Remote ["/home/len/www/"]) ;