Skip to content

Instantly share code, notes, and snippets.

@fleger
Created March 1, 2011 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fleger/849049 to your computer and use it in GitHub Desktop.
Save fleger/849049 to your computer and use it in GitHub Desktop.
Wrapper around unionfs-fuse that uses a file-based branches configuration.
#! /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 "$@"
@fleger
Copy link
Author

fleger commented Mar 1, 2011

Requires unionfs-fuse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment