Created
March 1, 2011 12:17
-
-
Save fleger/849049 to your computer and use it in GitHub Desktop.
Wrapper around unionfs-fuse that uses a file-based branches configuration.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires unionfs-fuse