parent
ba5041579a
commit
d55cba0a45
98
misc/bind-dirs
Executable file
98
misc/bind-dirs
Executable file
@ -0,0 +1,98 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
# vim: set ts=4 sw=4 sts=4 et :
|
||||||
|
#
|
||||||
|
# bind-dirs
|
||||||
|
# Binds directories which allows changes in TemplateBasedVM to persist.
|
||||||
|
#
|
||||||
|
# To umount all bind-dirs, just pass any arg in $1, like umount
|
||||||
|
#
|
||||||
|
# Copyright (C) 2014 - 2015 Jason Mehring <nrgaway@gmail.com>
|
||||||
|
# Copyright (C) 2014 - 2015 Patrick Schleizer <adrelanos@riseup.net>
|
||||||
|
# License: GPL-2+
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
set -x
|
||||||
|
|
||||||
|
prerequisite() {
|
||||||
|
qubes_vm_persistence="$(qubesdb-read /qubes-vm-persistence)"
|
||||||
|
if [ ! "$qubes_vm_persistence" = "rw-only" ]; then
|
||||||
|
true "No TemplateBasedVM detected. Exiting."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
[ -n "$rw_dest_dir" ] || rw_dest_dir="/rw/bind-dirs"
|
||||||
|
mkdir --parents "$rw_dest_dir"
|
||||||
|
}
|
||||||
|
|
||||||
|
legacy() {
|
||||||
|
if [ -d /rw/srv/qubes-whonix ]; then
|
||||||
|
mv /rw/srv/qubes-whonix /rw/bind-dirs || true
|
||||||
|
fi
|
||||||
|
if [ -d /rw/srv/whonix ]; then
|
||||||
|
mv /rw/srv/whonix /rw/bind-dirs || true
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
bind_dirs() {
|
||||||
|
## fso: file system object
|
||||||
|
## ro: read-only
|
||||||
|
## rw: read-write
|
||||||
|
for fso_ro in ${binds[@]}; do
|
||||||
|
fso_rw="${rw_dest_dir}${fso_ro}"
|
||||||
|
|
||||||
|
# Make sure ro directory is not mounted
|
||||||
|
umount "$fso_ro" 2> /dev/null || true
|
||||||
|
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
echo "Umounting $1 only..."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Initially copy over data directories to /rw if rw directory does not exist
|
||||||
|
if [ -d "$fso_ro" ]; then
|
||||||
|
if [ ! -d "$fso_rw" ]; then
|
||||||
|
cp --archive --parents --recursive "$fso_ro" "$rw_dest_dir"
|
||||||
|
fi
|
||||||
|
elif [ -f "$fso_ro" ]; then
|
||||||
|
if [ ! -f "$fso_rw" ]; then
|
||||||
|
cp --archive --recursive "$fso_ro" "$fso_rw"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Bind the directory
|
||||||
|
mount --bind "$fso_rw" "$fso_ro"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
prerequisite ${1+"$@"}
|
||||||
|
init ${1+"$@"}
|
||||||
|
legacy ${1+"$@"}
|
||||||
|
bind_dirs ${1+"$@"}
|
||||||
|
}
|
||||||
|
|
||||||
|
for folder in /usr/lib/qubes-bind-dirs.d /etc/qubes-bind-dirs.d /rw/config/qubes-bind-dirs.d ; do
|
||||||
|
if [ ! -d "$folder" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
for file_name in "$folder/"*".conf" ; do
|
||||||
|
bash -n "$file_name"
|
||||||
|
source "$file_name"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
main ${1+"$@"}
|
Loading…
Reference in New Issue
Block a user