From 9da3828ee4bbe45242f6e7da696dceee510b4a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20ULUA=C4=9E?= Date: Sun, 20 Sep 2020 21:15:23 +0300 Subject: [PATCH] Added 'boxhome' argument to toolbox create command Relates to issues #183, #348, #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) --- src/cmd/create.go | 8 ++++++++ src/cmd/initContainer.go | 11 +++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/cmd/create.go b/src/cmd/create.go index f90ec2d4e..8423ac04a 100644 --- a/src/cmd/create.go +++ b/src/cmd/create.go @@ -45,6 +45,7 @@ var ( container string image string release string + boxhome string } createToolboxShMounts = []struct { @@ -83,6 +84,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) } @@ -316,6 +323,7 @@ func createContainer(container, image, release string, showCommandToEnter bool) "toolbox", "--verbose", "init-container", "--home", currentUser.HomeDir, + "--boxhome", createFlags.boxhome, } entryPoint = append(entryPoint, slashHomeLink...) diff --git a/src/cmd/initContainer.go b/src/cmd/initContainer.go index 169153310..2b0c32b62 100644 --- a/src/cmd/initContainer.go +++ b/src/cmd/initContainer.go @@ -36,6 +36,7 @@ import ( var ( initContainerFlags struct { home string + boxhome string homeLink bool mediaLink bool mntLink bool @@ -75,6 +76,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, @@ -236,7 +243,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 { @@ -245,7 +252,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 {