public
Last active

Wrapper around unionfs-fuse that uses a file-based branches configuration.

  • Download Gist
modfs.sh
Shell
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
#! /bin/bash
 
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.
 
: ${UNIONFS:=unionfs}
readonly MODFS_BIN="$0"
 
modfs.usage() {
cat << EOM
Usage: $MODFS_BIN [options] branches.d mountpoint
 
options:
Any valid $UNIONFS options.
 
branches.d:
Directory containing the configuration files describing the branches to mount.
Configuration filenames must end with the .conf extension. Adding a new branch in a configuration files is done using the following syntax:
MODFS_BRANCHES+=("/path/to/branch=mode")
mode can be either RO (read-only) or RW (read-write).
 
mountpoint:
Destination mountpoint.
 
EOM
}
 
modfs.main() {
local -a options=()
local branchesDir
local mountpoint
local -a MODFS_BRANCHES=()
local i
local branches=""
# Read arguments
(( $# < 2 )) && modfs.usage && return 1
until (( $# == 2 )); do
options+=("$1")
shift
done
branchesDir="$1"
mountpoint="$2"
# Configuration
for i in "$branchesDir"/*.conf; do
[[ -f "$i" ]] && . "$i"
done
# Mount
for i in "${MODFS_BRANCHES[@]}"; do
[[ -z "$branches" ]] || branches+=":"
branches+="$i"
done
$UNIONFS "${options[@]}" "$branches" "$mountpoint"
}
 
modfs.main "$@"

Requires unionfs-fuse

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.