Determine lxc root according to the running user.

This commit is contained in:
Omer Katz 2018-07-29 13:16:41 +03:00
parent 07cafb80ec
commit e5b740e223
No known key found for this signature in database
GPG Key ID: 12A53B890119D176
1 changed files with 9 additions and 0 deletions

View File

@ -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 {