54
54
return fmt.Sprintf("snappy-classic_%s_%s.scope", ti, helpers.MakeRandomString(5))
57
// RunShell runs a shell in the classic environment
58
func RunShell() error {
57
func runInClassicEnv(cmdStr ...string) error {
59
58
// setup the bind mounts
60
59
for _, m := range bindMountDirs {
61
60
if err := bindmount(m.src, m.dst, m.remount); err != nil {
66
// drop to the calling user
67
sudoUser := os.Getenv("SUDO_USER")
72
65
// run chroot shell inside a systemd "scope"
73
66
unitName := genClassicScopeName()
74
cmd := exec.Command("systemd-run", "--quiet", "--scope", fmt.Sprintf("--unit=%s", unitName), "--description=Snappy Classic shell", "chroot", dirs.ClassicDir, "sudo", "debian_chroot=classic", "-u", sudoUser, "-i")
67
args := []string{"systemd-run", "--quiet", "--scope", fmt.Sprintf("--unit=%s", unitName), "--description=Snappy Classic shell", "chroot", dirs.ClassicDir}
68
args = append(args, cmdStr...)
69
cmd := exec.Command(args[0], args[1:]...)
75
70
cmd.Stdin = os.Stdin
76
71
cmd.Stdout = os.Stdout
77
72
cmd.Stderr = os.Stderr
76
// RunShell runs a shell in the classic environment
77
func RunShell() error {
78
// drop to the calling user
79
sudoUser := os.Getenv("SUDO_USER")
83
runInClassicEnv("sudo", "debian_chroot=classic", "-u", sudoUser, "-i")
80
85
// We could inform the user here that
81
86
// "systemctl stop $unitName"