modules: misc: Add a small helper module

Maybe I'll collect enough small snippets that I can keep them in here
until they get split out elsewhere to more appropriate places.
This commit is contained in:
James Shubin
2024-09-26 12:43:26 -04:00
parent 13fc711657
commit 9a752da13d
2 changed files with 19 additions and 0 deletions

19
modules/misc/main.mcl Normal file
View File

@@ -0,0 +1,19 @@
import "os"
# ssh_keygen creates an ssh key pair in the user's home directory if the private
# key doesn't exist.
# TODO: add more parameters such as key size and type in the future
class ssh_keygen($user) {
panic($user == "") # panic if $user is empty
$p = os.expand_home("~${user}/") # eg: ~james/
exec "ssh-keygen-${user}" {
cmd => "/usr/bin/ssh-keygen",
args => [
"-t", "rsa", # type
"-f", "${p}.ssh/id_rsa", # private key file
"-N", "", # empty password
],
creates => "${p}.ssh/id_rsa",
user => $user,
}
}

View File