--- a/setup/command.go Sun Mar 06 23:52:21 2022 -0600
+++ b/setup/command.go Mon Mar 07 01:07:26 2022 -0600
@@ -1,8 +1,9 @@
-//go:generate esc -o resources.go -pkg setup -include resources\/.+ -prefix resources/ .
@@ -20,6 +21,9 @@
AdminSSHPubkey string `kong:"flag,name='admin-pubkey',env='HGK_ADMIN_PUBKEY',help='the path to the ssh pubkey to use for the admin',required='true',type='existingfile'"`
@@ -36,32 +40,34 @@
func (c *Command) createAdminRepo(reposPath, adminRepo string) error {
- path := filepath.Join(reposPath, adminRepo)
+ adminPath := filepath.Join(reposPath, adminRepo) - if err := runCmd(hg.Init(path)); err != nil {
+ if err := runCmd(hg.Init(adminPath)); err != nil { - // walk through the embedded resources and dump them into the directory
- for name, data := range _escData {
- // skip directories as we only add the ones were we have files
+ err := fs.WalkDir(resources, "resources", func(path string, entry fs.DirEntry, err error) error { - // we're copying a regular file now, so figure out the paths so we can
- // create them if necessary. We have to special case dothg because
- // using .hg causes issues
- if strings.HasPrefix(name, "/dothg/") {
- absname = filepath.Join(path, ".hg", name[7:])
- absname = filepath.Join(path, name)
+ // Remove the resources prefix. + stripped := strings.TrimPrefix(path, "resources") + // Figure out the absolute path of the target file. + absname := filepath.Join(adminPath, stripped) + // We can't start a name with . so we have to manually replace it. + absname = strings.Replace(absname, "/dothg", "/.hg", 1) + // We need to know the directory name so we can create it. dirname := filepath.Dir(absname)
// if we don't have the directory create it
@@ -76,10 +82,15 @@
// If this is a template file, execute it
- if filepath.Ext(name) == ".template" {
- absname = absname[:len(absname)-len(".template")]
+ if filepath.Ext(absname) == ".template" { + absname = strings.TrimSuffix(absname, ".template") - tplate, err := template.New(name).Parse(FSMustString(false, name))
+ data, err := resources.ReadFile(path) + tplate, err := template.New(path).Parse(string(data)) @@ -104,12 +115,18 @@
// If it's not a template just write it out
- if err := ioutil.WriteFile(absname, FSMustByte(false, name), 0644); err != nil {
+ data, err := resources.ReadFile(path) + if err := ioutil.WriteFile(absname, data, 0644); err != nil { - rel, err := filepath.Rel(path, absname)
+ // Figure out which files need to be committed to the repository. + rel, err := filepath.Rel(adminPath, absname) @@ -117,10 +134,15 @@
if !strings.HasPrefix(rel, fmt.Sprintf(".hg%c", filepath.Separator)) {
filenames = append(filenames, rel)
// create our keys directory
- keysDir := filepath.Join(path, "keys")
+ keysDir := filepath.Join(adminPath, "keys") if err := os.MkdirAll(keysDir, 0755); err != nil {
@@ -132,7 +154,7 @@
adminPubkey := filepath.Join(keysDir, c.AdminUsername)
- relAdminPubkey, err := filepath.Rel(path, adminPubkey)
+ relAdminPubkey, err := filepath.Rel(adminPath, adminPubkey) @@ -143,12 +165,12 @@
- if err := runCmd(hg.Add(path, filenames...)); err != nil {
+ if err := runCmd(hg.Add(adminPath, filenames...)); err != nil { - if err := runCmd(hg.Commit(path, hgUsername, commitMessage)); err != nil {
+ if err := runCmd(hg.Commit(adminPath, hgUsername, commitMessage)); err != nil {