initial commit
This commit is contained in:
commit
660c5922f9
|
@ -0,0 +1,20 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright 2020 "fox"
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,34 @@
|
|||
lyr
|
||||
====
|
||||
|
||||
an abbreviation of "layer."
|
||||
|
||||
maintains a repository of overlayfs upper directories, work directories, and
|
||||
mount paths at LYRREPO. simplifies mounting, unmounting, creating, and
|
||||
deleting layers.
|
||||
|
||||
62 ELOC.
|
||||
|
||||
usage: lyr.sh [command] <layer name>
|
||||
|
||||
commands:
|
||||
workdir
|
||||
returns the work directory path for the layer.
|
||||
|
||||
upperdir
|
||||
returns the upper directory path for the layer.
|
||||
|
||||
mountdir
|
||||
returns the mount directory path for the layer.
|
||||
|
||||
mk
|
||||
create a new layer with the given name.
|
||||
|
||||
rm
|
||||
unmount and delete the layer with the given name.
|
||||
|
||||
up [<lower path>[:<lower path>]]
|
||||
mount the given layer with the given lower paths. print the mount path.
|
||||
|
||||
dn
|
||||
unmount the given layer.
|
|
@ -0,0 +1,80 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
export LYRROOT="$(dirname "$(readlink -f "$0")")"
|
||||
export LYRREPO="${LYRREPO:-/usr/var/lyr}"
|
||||
|
||||
[ -n "$1" ] || { \
|
||||
echo "
|
||||
usage: $(basename $0) <command> <layer name>
|
||||
|
||||
commands:
|
||||
workdir
|
||||
returns the work directory path for the layer.
|
||||
|
||||
upperdir
|
||||
returns the upper directory path for the layer.
|
||||
|
||||
mountdir
|
||||
returns the mount directory path for the layer.
|
||||
|
||||
mk
|
||||
create a new layer with the given name.
|
||||
|
||||
rm
|
||||
unmount and delete the layer with the given name.
|
||||
|
||||
up [<lower path>[:<lower path>]]
|
||||
mount the given layer with the given lower paths. print the mount path.
|
||||
|
||||
dn
|
||||
unmount the given layer.
|
||||
" && exit 0; }
|
||||
|
||||
# if this is running on an interactive
|
||||
# terminal (as opposed to in a script), if tput is installed, and if tput
|
||||
# knows some color codes, then set the color values.
|
||||
if [ -t 1 ] && [ "$(tput colors 2>/dev/null || echo 0)" -ge 8 ]; then
|
||||
_clr="$(tput sgr0)"
|
||||
_blu="$(tput setaf 6)"
|
||||
_ylw="$(tput setaf 3)"
|
||||
_red="$(tput setaf 1)"
|
||||
fi
|
||||
log() { echo "$_blu[LOG]$_clr $@"; }
|
||||
wrn() { echo "$_ylw[WRN]$_clr $@" >&2; }
|
||||
err() { echo "$_red[ERR]$_clr $@" >&2; exit 1; }
|
||||
|
||||
case "$1" in
|
||||
workdir) echo "$LYRREPO/work/$2";;
|
||||
upperdir) echo "$LYRREPO/upper/$2";;
|
||||
mountdir) echo "$LYRREPO/mount/$2";;
|
||||
mk) mkdir -p "$LYRREPO/upper/$2";;
|
||||
|
||||
rm)
|
||||
{ ! mountpoint -q "$LYRREPO/mount/$2" || umount "$LYRREPO/mount/$2"; } \
|
||||
&& rm -fr "$LYRREPO/upper/$2" "$LYRREPO/mount/$2" "$LYRREPO/work/$2"
|
||||
;;
|
||||
|
||||
up)
|
||||
[ -n "$3" ] && { layer="$3" && lower="$2"; } || layer="$2"
|
||||
work="$LYRREPO/work/$layer"
|
||||
upper="$LYRREPO/upper/$layer"
|
||||
mnt="$LYRREPO/mount/$layer"
|
||||
[ -d "$upper" ] || err "layer '$layer' not recognized!"
|
||||
|
||||
mkdir -p "$work" "$mnt"
|
||||
|
||||
if [ -n "$lower" ]; then
|
||||
mount -t overlay -o lowerdir=$lower,upperdir=$upper,workdir=$work \
|
||||
none "$mnt"
|
||||
else
|
||||
mount -o bind "$upper" "$mnt"
|
||||
fi
|
||||
|
||||
echo "$mnt"
|
||||
;;
|
||||
|
||||
dn) umount "$LYRREPO/mount/$2" && rm -r "$LYRREPO/mount/$2";;
|
||||
*) err "unrecognized command '$1'";;
|
||||
esac
|
|
@ -0,0 +1,15 @@
|
|||
SRCDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
|
||||
PREFIX ?= /usr
|
||||
DESTDIR ?= $(PREFIX)/bin
|
||||
LYRREPO ?= $(PREFIX)/var/lyr
|
||||
LYRROOT ?= $(PREFIX)/share/lyr
|
||||
|
||||
install:
|
||||
mkdir -p $(LYRREPO)
|
||||
ln -sf $(SRCDIR) $(LYRROOT)
|
||||
ln -sf $(LYRROOT)/lyr.sh $(DESTDIR)/lyr
|
||||
|
||||
uninstall:
|
||||
rm $(DESTDIR)/lyr
|
||||
rm $(LYRROOT)
|
||||
rm -fr $(LYRREPO)
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/sh
|
||||
|
||||
# find all *.sh files not under `pkg` that are not symbolic links, strip all
|
||||
# trailing whitespace, then all leading whitespace, then all lines starting
|
||||
# with '#', then all empty lines. then count the remaining lines.
|
||||
|
||||
find . -name "*.sh" ! -path "**/pkg/**" ! -type l \
|
||||
| xargs sed 's/[[:space:]]*$//g; s/^[[:space:]]*//g; s/^#.*$//g; /^$/d' \
|
||||
| wc -l - \
|
||||
| cut -d' ' -f1
|
||||
|
||||
# note that this script's ELOC is also included in the count.
|
Loading…
Reference in New Issue