1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
// Copyright (c) 2019-2020, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package cli
import (
"fmt"
"github.com/spf13/cobra"
"github.com/sylabs/singularity/v4/docs"
"github.com/sylabs/singularity/v4/internal/app/singularity"
"github.com/sylabs/singularity/v4/pkg/cmdline"
"github.com/sylabs/singularity/v4/pkg/sylog"
)
// -a|--add
var fakerootConfigAdd bool
var fakerootConfigAddFlag = cmdline.Flag{
ID: "fakerootConfigAddFlag",
Value: &fakerootConfigAdd,
DefaultValue: false,
Name: "add",
ShortHand: "a",
Usage: "add a fakeroot mapping entry for a user allowing him to use the fakeroot feature",
}
// -r|--remove
var fakerootConfigRemove bool
var fakerootConfigRemoveFlag = cmdline.Flag{
ID: "fakerootConfigRemoveFlag",
Value: &fakerootConfigRemove,
DefaultValue: false,
Name: "remove",
ShortHand: "r",
Usage: "remove the user fakeroot mapping entry preventing him to use the fakeroot feature",
}
// -e|--enable
var fakerootConfigEnable bool
var fakerootConfigEnableFlag = cmdline.Flag{
ID: "fakerootConfigEnableFlag",
Value: &fakerootConfigEnable,
DefaultValue: false,
Name: "enable",
ShortHand: "e",
Usage: "enable a user fakeroot mapping entry allowing him to use the fakeroot feature (the user mapping must be present)",
}
// -d|--disable
var fakerootConfigDisable bool
var fakerootConfigDisableFlag = cmdline.Flag{
ID: "fakerootConfigDisableFlag",
Value: &fakerootConfigDisable,
DefaultValue: false,
Name: "disable",
ShortHand: "d",
Usage: "disable a user fakeroot mapping entry preventing him to use the fakeroot feature (the user mapping must be present)",
}
// configFakerootCmd singularity config fakeroot
var configFakerootCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
PreRun: CheckRoot,
RunE: func(cmd *cobra.Command, args []string) error {
username := args[0]
var op singularity.FakerootConfigOp
if fakerootConfigAdd {
op = singularity.FakerootAddUser
} else if fakerootConfigRemove {
op = singularity.FakerootRemoveUser
} else if fakerootConfigEnable {
op = singularity.FakerootEnableUser
} else if fakerootConfigDisable {
op = singularity.FakerootDisableUser
} else {
return fmt.Errorf("you must specify an option (eg: --add/--remove)")
}
if err := singularity.FakerootConfig(username, op); err != nil {
sylog.Fatalf("%s", err)
}
return nil
},
Use: docs.ConfigFakerootUse,
Short: docs.ConfigFakerootShort,
Long: docs.ConfigFakerootLong,
Example: docs.ConfigFakerootExample,
}
func init() {
addCmdInit(func(cmdManager *cmdline.CommandManager) {
cmdManager.RegisterFlagForCmd(&fakerootConfigAddFlag, configFakerootCmd)
cmdManager.RegisterFlagForCmd(&fakerootConfigRemoveFlag, configFakerootCmd)
cmdManager.RegisterFlagForCmd(&fakerootConfigEnableFlag, configFakerootCmd)
cmdManager.RegisterFlagForCmd(&fakerootConfigDisableFlag, configFakerootCmd)
})
}
|