add the ability to pass mount options to fusermount
This commit is contained in:
parent
7fad1c2b43
commit
3cffbbf8a9
|
@ -2,6 +2,10 @@ fs:
|
||||||
# The mountpoint. Can be overwritten via the command line.
|
# The mountpoint. Can be overwritten via the command line.
|
||||||
#mountpoint: /mnt
|
#mountpoint: /mnt
|
||||||
|
|
||||||
|
# Mount options to pass to `fusermount` as its `-o` argument. Can be overwritten via the command line.
|
||||||
|
# See mount.fuse(8) for the full list of options.
|
||||||
|
#mountoptions: nodev,nosuid
|
||||||
|
|
||||||
gitlab:
|
gitlab:
|
||||||
# The gitlab url.
|
# The gitlab url.
|
||||||
url: https://gitlab.com
|
url: https://gitlab.com
|
||||||
|
|
10
fs/root.go
10
fs/root.go
|
@ -28,6 +28,9 @@ type FSParam struct {
|
||||||
Git git.GitClonerPuller
|
Git git.GitClonerPuller
|
||||||
Gitlab gitlab.GitlabFetcher
|
Gitlab gitlab.GitlabFetcher
|
||||||
|
|
||||||
|
RootGroupIds []int
|
||||||
|
UserIds []int
|
||||||
|
|
||||||
staticInoChan chan uint64
|
staticInoChan chan uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,17 +73,18 @@ func (n *rootNode) OnAdd(ctx context.Context) {
|
||||||
fmt.Println("Mounted and ready to use")
|
fmt.Println("Mounted and ready to use")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Start(mountpoint string, rootGroupIds []int, userIds []int, param *FSParam, debug bool) error {
|
func Start(mountpoint string, mountoptions []string, param *FSParam, debug bool) error {
|
||||||
fmt.Printf("Mounting in %v\n", mountpoint)
|
fmt.Printf("Mounting in %v\n", mountpoint)
|
||||||
|
|
||||||
opts := &fs.Options{}
|
opts := &fs.Options{}
|
||||||
|
opts.MountOptions.Options = mountoptions
|
||||||
opts.Debug = debug
|
opts.Debug = debug
|
||||||
|
|
||||||
param.staticInoChan = make(chan uint64)
|
param.staticInoChan = make(chan uint64)
|
||||||
root := &rootNode{
|
root := &rootNode{
|
||||||
param: param,
|
param: param,
|
||||||
rootGroupIds: rootGroupIds,
|
rootGroupIds: param.RootGroupIds,
|
||||||
userIds: userIds,
|
userIds: param.UserIds,
|
||||||
}
|
}
|
||||||
|
|
||||||
go staticInoGenerator(root.param.staticInoChan)
|
go staticInoGenerator(root.param.staticInoChan)
|
||||||
|
|
37
main.go
37
main.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/badjware/gitlabfs/fs"
|
"github.com/badjware/gitlabfs/fs"
|
||||||
"github.com/badjware/gitlabfs/git"
|
"github.com/badjware/gitlabfs/git"
|
||||||
|
@ -20,7 +21,8 @@ type (
|
||||||
Git GitConfig `yaml:"git,omitempty"`
|
Git GitConfig `yaml:"git,omitempty"`
|
||||||
}
|
}
|
||||||
FSConfig struct {
|
FSConfig struct {
|
||||||
Mountpoint string `yaml:"mountpoint,omitempty"`
|
Mountpoint string `yaml:"mountpoint,omitempty"`
|
||||||
|
MountOptions string `yaml:"mountoptions,omitempty"`
|
||||||
}
|
}
|
||||||
GitlabConfig struct {
|
GitlabConfig struct {
|
||||||
URL string `yaml:"url,omitempty"`
|
URL string `yaml:"url,omitempty"`
|
||||||
|
@ -53,7 +55,8 @@ func loadConfig(configPath string) (*Config, error) {
|
||||||
|
|
||||||
config := &Config{
|
config := &Config{
|
||||||
FS: FSConfig{
|
FS: FSConfig{
|
||||||
Mountpoint: "",
|
Mountpoint: "",
|
||||||
|
MountOptions: "nodev,nosuid",
|
||||||
},
|
},
|
||||||
Gitlab: GitlabConfig{
|
Gitlab: GitlabConfig{
|
||||||
URL: "https://gitlab.com",
|
URL: "https://gitlab.com",
|
||||||
|
@ -136,8 +139,16 @@ func makeGitConfig(config *Config) (*git.GitClientParam, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
configPath := flag.String("config", "", "the config file")
|
configPath := flag.String("config", "", "The config file")
|
||||||
debug := flag.Bool("debug", false, "enable debug logging")
|
mountoptionsFlag := flag.String("o", "", "Filesystem mount options. See mount.fuse(8)")
|
||||||
|
debug := flag.Bool("debug", false, "Enable debug logging")
|
||||||
|
|
||||||
|
flag.Usage = func() {
|
||||||
|
fmt.Println("USAGE:")
|
||||||
|
fmt.Printf(" %s MOUNTPOINT\n\n", os.Args[0])
|
||||||
|
fmt.Println("OPTIONS:")
|
||||||
|
flag.PrintDefaults()
|
||||||
|
}
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
config, err := loadConfig(*configPath)
|
config, err := loadConfig(*configPath)
|
||||||
|
@ -152,10 +163,21 @@ func main() {
|
||||||
mountpoint = flag.Arg(0)
|
mountpoint = flag.Arg(0)
|
||||||
}
|
}
|
||||||
if mountpoint == "" {
|
if mountpoint == "" {
|
||||||
fmt.Printf("usage: %s MOUNTPOINT\n", os.Args[0])
|
fmt.Println("Mountpoint is not configured in config file and missing from command-line arguments")
|
||||||
|
flag.Usage()
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Configure mountoptions
|
||||||
|
mountoptions := config.FS.MountOptions
|
||||||
|
if *mountoptionsFlag != "" {
|
||||||
|
mountoptions = *mountoptionsFlag
|
||||||
|
}
|
||||||
|
parsedMountoptions := make([]string, 0)
|
||||||
|
if mountoptions != "" {
|
||||||
|
parsedMountoptions = strings.Split(mountoptions, ",")
|
||||||
|
}
|
||||||
|
|
||||||
// Create the git client
|
// Create the git client
|
||||||
gitClientParam, err := makeGitConfig(config)
|
gitClientParam, err := makeGitConfig(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -175,9 +197,8 @@ func main() {
|
||||||
// Start the filesystem
|
// Start the filesystem
|
||||||
err = fs.Start(
|
err = fs.Start(
|
||||||
mountpoint,
|
mountpoint,
|
||||||
config.Gitlab.GroupIDs,
|
parsedMountoptions,
|
||||||
config.Gitlab.UserIDs,
|
&fs.FSParam{Git: gitClient, Gitlab: gitlabClient, RootGroupIds: config.Gitlab.GroupIDs, UserIds: config.Gitlab.UserIDs},
|
||||||
&fs.FSParam{Git: gitClient, Gitlab: gitlabClient},
|
|
||||||
*debug,
|
*debug,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue