Skip to content

Commit

Permalink
Added 'boxhome' argument to toolbox create command
Browse files Browse the repository at this point in the history
Relates to issues containers#348, containers#467
Added optional boxhome argument to create command.
Boxhome is concatenated with homedir in order to be under host's home dir.
Homedir is still mounted. No worries.
Being under host's home enables easy file sharing, and prevents privilage issues.
When boxhome argument is not given, system works as before (uses user's home dir)
  • Loading branch information
onuruluag committed Apr 4, 2021
1 parent e935ed8 commit 11d1c99
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
distro string
image string
release string
boxhome string
}

createToolboxShMounts = []struct {
Expand Down Expand Up @@ -90,6 +91,12 @@ func init() {
"",
"Create a toolbox container for a different operating system release than the host")

flags.StringVarP(&createFlags.boxhome,
"boxhome",
"b",
"",
"Create a toolbox container with a different home path than the host.")

createCmd.SetHelpFunc(createHelp)
rootCmd.AddCommand(createCmd)
}
Expand Down Expand Up @@ -381,6 +388,7 @@ func createContainer(container, image, release string, showCommandToEnter bool)
"init-container",
"--gid", currentUser.Gid,
"--home", currentUser.HomeDir,
"--boxhome", createFlags.boxhome,
"--shell", userShell,
"--uid", currentUser.Uid,
"--user", currentUser.Username,
Expand Down
11 changes: 9 additions & 2 deletions src/cmd/initContainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
initContainerFlags struct {
gid int
home string
boxhome string
homeLink bool
mediaLink bool
mntLink bool
Expand Down Expand Up @@ -87,6 +88,12 @@ func init() {
"Create a user inside the toolbox container whose login directory is HOME")
initContainerCmd.MarkFlagRequired("home")

fmt.Println(initContainerFlags.boxhome)
flags.StringVar(&initContainerFlags.boxhome,
"boxhome",
"",
"Create a user inside the toolbox container whose login directory is not HOME.")

flags.BoolVar(&initContainerFlags.homeLink,
"home-link",
false,
Expand Down Expand Up @@ -228,7 +235,7 @@ func initContainer(cmd *cobra.Command, args []string) error {
if _, err := user.Lookup(initContainerFlags.user); err != nil {
if err := configureUsers(initContainerFlags.uid,
initContainerFlags.user,
initContainerFlags.home,
initContainerFlags.home+"/"+initContainerFlags.boxhome,
initContainerFlags.shell,
initContainerFlags.homeLink,
false); err != nil {
Expand All @@ -237,7 +244,7 @@ func initContainer(cmd *cobra.Command, args []string) error {
} else {
if err := configureUsers(initContainerFlags.uid,
initContainerFlags.user,
initContainerFlags.home,
initContainerFlags.home+"/"+initContainerFlags.boxhome,
initContainerFlags.shell,
initContainerFlags.homeLink,
true); err != nil {
Expand Down

0 comments on commit 11d1c99

Please sign in to comment.