command line script: fuse_git_bare_fs

overview

fuse_git_bare_fs has two subcommands:

repo

Mount the working tree of a [git] repository as a filesystem in user space ([FUSE]).

tree

Mount the working tree of git repositories in a directory tree.

Instead of these subcommands you can also use the flag ‘-o’ to use fuse_git_bare_fs as a mount program(cf. [vfs_fuse], [mount]). For example to mount ‘/foo’ to ‘/bar’ as the user ‘sr’ and the group ‘grp’, you can add the following line to your ‘/etc/fstab’ (cf. [fstab]:

/foo /bar fuse.fuse_git_bare_fs uid=sr,gid=grp,tree,root_object=master,ro 0 0

For a non persistent mount you can use fuse_git_bare_fs directly:

fuse_git_bare_fs tree -uid=sr -gid=grp /foo /bar

These commands are explained in more detail in the following (help output):

References:

git

https://git-scm.com/

FUSE

https://en.wikipedia.org/wiki/Filesystem_in_Userspace, https://github.com/libfuse/libfuse

vfs_fuse

https://www.kernel.org/doc/html/latest/filesystems/vfs.html, https://www.kernel.org/doc/html/latest/filesystems/fuse.html

mount

https://linux.die.net/man/8/mount

fstab

https://en.wikipedia.org/wiki/Fstab

help output

“fuse_git_bare_fs” is a tool to mount the working tree(s) of git bare repositories as a filesystem in user space (fuse). It gives only read access. For a write access you should do a git commit and use git.

usage: fuse_git_bare_fs [-h] [-o OPT] {repo,tree} ...

Positional Arguments

subparser_name

Possible choices: repo, tree

There are different sub-commands with there own flags.

Named Arguments

-o

These options are splitted at “,” and used as seperated options. The sub-commands are extracted as well. The flag “-daemon” is used in any case. This allows to use this program as mount program e. g. in /etc/fstab. Example: “a,b=c” will become “-a -b c”; “a,tree,b=c” will become “tree -a -b c”. Example usage: fuse_git_bare_fs -o “repo,allow_other” foo bar

Default: [None]

Sub-commands:

repo

“fuse_git_bare_fs repo” is a tool to mount the working tree of a git bare repository as a filesystem in user space (fuse). It gives only read access. For a write access you should do a git commit and use git. This script needs about 7.6 MB of memory to run. More memory is necessary for large working trees or to provide file content.

fuse_git_bare_fs repo [-h] [-root_object ROOT_OBJECT]
                      [-cache_size MAX_CACHE_SIZE] [-daemon] [-logfile f]
                      [-threads] [-allow_other] [-default_permissions]
                      [-file_st_modes file executable link directory]
                      [-uid UID] [-gid GID] [-ro] [-nofail] [-dev] [-suid]
                      src_dir target_dir
Positional Arguments
src_dir

This is the path to a git bare repository. The working tree of its root_object (e. g. master) will be transparent available in the target_dir.

target_dir

This is the mountpoint.

Named Arguments
-root_object

Defines the root repository object of the working tree. This will be given as a parameter to “git cat-file”; hence you can look in the relevant man page of “git cat-file” to understand how to specify the branch and or revision. default: master

Default: [‘master’]

-cache_size

Defines the maximal used cache size. default: 1073741824 (1 GB)

Default: [1073741824]

-daemon

If given, go to background and work as a daemon. To unmount you can do: fusermount -u target_dir

Default: True

-logfile

If given, the log output is stored in this file. If running as a daemon this could be done, but is not common. It is only for debugging. Maybe there is too much information stored. Further the used WatchedFileHandler is not thread safe. The initial file permission is read and write for the owner, but if the file is recreated (e. g. logging after file delete) the file permission is read for everyone and write for owner and group.

-threads

If given, the fuse mount will be threaded. This is not tested.

Default: True

-allow_other

If given, allows other users to use the fuse mount point. Therefore you have to allow this in /etc/fuse.conf by uncommenting “user_allow_other” there.

Default: False

-default_permissions

If given, the file permissions will be used by fuse. This is important to use together with “-allow_other” and “-file_st_modes”.

Default: False

-file_st_modes

Set the file modes used to provide the files. The default 33188, 33261, 41471, 16877 reflect the modes used by git. The values are for normal file, executable file, symbolic link and for a directory. For example if other users should not be allowed to read something you can set: 33184 33256 41471 16872. Normally these permission modes are ignored by fuse. Therefore you have to set the parameter “-default_permissions”. If you want to use this with “-o” flag, set: -o file_st_modes=33184=33256=41471=16872. Example: fuse_git_bare_fs -o “repo,file_st_modes=33184=33256=41471=16872” foo bar

Default: [33188, 33261, 41471, 16877]

-uid

The program is run under this uid. The current direcotry and the home directory are set appropriate. This allows to use this program as mount program e. g. in /etc/fstab. On default nothing is done (the calling user is used).

Default: [None]

-gid

The program is run under this gid. On default nothing is done. This allows to use this program as mount program e. g. in /etc/fstab.

Default: [None]

-ro

Make a read only mountpoint. This is always the case! This allows to use this program as mount program e. g. in /etc/fstab.

Default: False

-nofail

Try to exit without error if initial mount fails. Only works if the program runs as a daemon. This helps to use this program as mount program e. g. in /etc/fstab.

Default: False

-dev

This is ignored. This allows to use this program as mount program e. g. in /etc/fstab.

Default: False

-suid

This is ignored. This allows to use this program as mount program e. g. in /etc/fstab.

Default: False

Examples:

fuse_git_bare_fs repo a b

sudo -u www-data fuse_git_bare_fs repo a b

Author: Daniel Mohr Date: 2021-10-06 License: GNU GENERAL PUBLIC LICENSE, Version 2, June 1991.

tree

“fuse_git_bare_fs tree” is a tool to mount the working tree of git bare repositories in a directory tree as a filesystem in user space (fuse). The idea is to provide the git repositories manage by a gitolite instance. Therefore parameters for this purpose are available. It is assumed that the bare repositories are named like “*.git”. It gives only read access. For a write access you should do a git commit and use git. For unmount just press ctrl-c, kill the program or do “fusermount -u target_dir”.

fuse_git_bare_fs tree [-h] [-root_object ROOT_OBJECT]
                      [-cache_size MAX_CACHE_SIZE] [-daemon] [-logfile f]
                      [-threads] [-allow_other] [-default_permissions]
                      [-file_st_modes file executable link directory]
                      [-uid UID] [-gid GID] [-ro] [-nofail] [-dev] [-suid]
                      [-get_user_list_from_gitolite] [-provide_htaccess]
                      [-htaccess_template HTACCESS_TEMPLATE]
                      [-gitolite_cmd GITOLITE_CMD]
                      [-gitolite_user_file GITOLITE_USER_FILE]
                      src_dir target_dir
Positional Arguments
src_dir

This is the path to the directory tree of git bare repositories. The working trees of their root_object (e. g. master) will be transparent available in the target_dir.

target_dir

This is the mountpoint.

Named Arguments
-root_object

Defines the root repository object of the working tree. This will be given as a parameter to “git cat-file”; hence you can look in the relevant man page of “git cat-file” to understand how to specify the branch and or revision. default: master

Default: [‘master’]

-cache_size

Defines the maximal used cache size. default: 1073741824 (1 GB)

Default: [1073741824]

-daemon

If given, go to background and work as a daemon. To unmount you can do: fusermount -u target_dir

Default: True

-logfile

If given, the log output is stored in this file. If running as a daemon this could be done, but is not common. It is only for debugging. Maybe there is too much information stored. Further the used WatchedFileHandler is not thread safe. The initial file permission is read and write for the owner, but if the file is recreated (e. g. logging after file delete) the file permission is read for everyone and write for owner and group.

-threads

If given, the fuse mount will be threaded. This is not tested.

Default: True

-allow_other

If given, allows other users to use the fuse mount point. Therefore you have to allow this in /etc/fuse.conf by uncommenting “user_allow_other” there.

Default: False

-default_permissions

If given, the file permissions will be used by fuse. This is important to use together with “-allow_other” and “-file_st_modes”.

Default: False

-file_st_modes

Set the file modes used to provide the files. The default 33188, 33261, 41471, 16877 reflect the modes used by git. The values are for normal file, executable file, symbolic link and for a directory. For example if other users should not be allowed to read something you can set: 33184 33256 41471 16872. Normally these permission modes are ignored by fuse. Therefore you have to set the parameter “-default_permissions”. If you want to use this with “-o” flag, set: -o file_st_modes=33184=33256=41471=16872. Example: fuse_git_bare_fs -o “repo,file_st_modes=33184=33256=41471=16872” foo bar

Default: [33188, 33261, 41471, 16877]

-uid

The program is run under this uid. The current direcotry and the home directory are set appropriate. This allows to use this program as mount program e. g. in /etc/fstab. On default nothing is done (the calling user is used).

Default: [None]

-gid

The program is run under this gid. On default nothing is done. This allows to use this program as mount program e. g. in /etc/fstab.

Default: [None]

-ro

Make a read only mountpoint. This is always the case! This allows to use this program as mount program e. g. in /etc/fstab.

Default: False

-nofail

Try to exit without error if initial mount fails. Only works if the program runs as a daemon. This helps to use this program as mount program e. g. in /etc/fstab.

Default: False

-dev

This is ignored. This allows to use this program as mount program e. g. in /etc/fstab.

Default: False

-suid

This is ignored. This allows to use this program as mount program e. g. in /etc/fstab.

Default: False

-get_user_list_from_gitolite

This creates subdirectories for each user. The users are extracted from the gitolite-admin repository included in the given src_dir. In every user directory only the repositories are mounted, which are accessable for the appropriate user. It is suposed that the command “gitolite” is available and that the gitolite-admin repository is called “gitolite-admin”. Additional configuration can be given with the flags “-gitolite_cmd” and “-gitolite_user_file”.

Default: False

-provide_htaccess

This creates “.htaccess” files in the user directories. This only appears if the flag “-get_user_list_from_gitolite” is given.

Default: False

-htaccess_template

A htaccess template can be given. It is “Require user [username]” added. On default only “Require user [username]” is used.

Default: [None]

-gitolite_cmd

Defines the gitolite command. You can give an absolute path. default: gitolite

Default: [‘gitolite’]

-gitolite_user_file

If given, the list of users is created from the content of this file and the gitolite command “list-users”. You can give an absolute path. If not given (default) only the gitolite command “list-users” is used to create the list of users. If the file does not exist, it is ignored until it is available. This is useful if gitolite only knows groups and the users are defined elsewhere (e. g. LDAP configuration of gitolite). You should update the given file regularly (e. g. by a cron job) from the source (e. g. directory service). Further you could overwrite the default gitolite command by a command, which return nothing for “list-users” and otherwise uses the normal gitolite command.

Default: [None]

Examples:

fuse_git_bare_fs tree a b

sudo -u gitolite fuse_git_bare_fs tree -daemon -allow_other -get_user_list_from_gitolite -provide_htaccess /var/lib/gitolite/repositories /var/www/gitolite/webdav

mount -t fuse.fuse_git_bare_fs -o uid=gitolite,gid=gitolite,tree,allow_other,get_user_list_from_gitolite,provide_htaccess,root_object=master,ro /var/lib/gitolite/repositories /var/www/gitolite/webdav

Example (put the following line to /etc/fstab):

/var/lib/gitolite/repositories /var/www/gitolite/webdav fuse.fuse_git_bare_fs uid=gitolite,gid=gitolite,tree,allow_other,get_user_list_from_gitolite,provide_htaccess,root_object=master,ro 0 0

Author: Daniel Mohr Date: 2021-10-06 License: GNU GENERAL PUBLIC LICENSE, Version 2, June 1991.

Author: Daniel Mohr Date: 2022-01-13 License: GNU GENERAL PUBLIC LICENSE, Version 2, June 1991.