From e5b740e22322e0e455c2b1f9584c64cc252bedb6 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sun, 29 Jul 2018 13:16:41 +0300 Subject: [PATCH] Determine lxc root according to the running user. --- builder/lxc/step_lxc_create.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/builder/lxc/step_lxc_create.go b/builder/lxc/step_lxc_create.go index 0c89ce190..1526ed715 100644 --- a/builder/lxc/step_lxc_create.go +++ b/builder/lxc/step_lxc_create.go @@ -3,6 +3,8 @@ package lxc import ( "context" "fmt" + "log" + "os/user" "path/filepath" "github.com/hashicorp/packer/helper/multistep" @@ -19,6 +21,13 @@ func (s *stepLxcCreate) Run(_ context.Context, state multistep.StateBag) multist // TODO: read from env lxc_dir := "/var/lib/lxc" + user, err := user.Current() + if err != nil { + log.Print("Cannot find current user. Falling back to /var/lib/lxc...") + } + if user.Uid != "0" && user.HomeDir != "" { + lxc_dir = filepath.Join(user.HomeDir, ".local", "share", "lxc") + } rootfs := filepath.Join(lxc_dir, name, "rootfs") if config.PackerForce {