summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Brown <ben.brown@codethink.co.uk>2013-11-15 16:42:35 (GMT)
committerBen Brown <ben.brown@codethink.co.uk>2014-01-13 09:07:40 (GMT)
commit0949e7e253ed0c2cb2a7889917e0696216b715ff (patch)
treed4f307f222c68a45f986975815c8364e4bce1924
parent20e5304f40148d43c6ab57dea0abe400475e7e9f (diff)
downloadtbdiff-benbrown/understanding-bscs.tar.gz
'Playing' with bscs.benbrown/understanding-bscs
-rwxr-xr-xbaserock-system-config-sync/baserock-system-config-sync76
-rwxr-xr-xbaserock-system-config-sync/mount-system-versions-dir6
2 files changed, 34 insertions, 48 deletions
diff --git a/baserock-system-config-sync/baserock-system-config-sync b/baserock-system-config-sync/baserock-system-config-sync
index cb5984d..09b4198 100755
--- a/baserock-system-config-sync/baserock-system-config-sync
+++ b/baserock-system-config-sync/baserock-system-config-sync
@@ -62,11 +62,6 @@ check_same_type() {
merge() {
local vp_dir="$1" # version being processed
- local v1_dir="$2" # factory version
- local vu_dir="$3" # user modified version
- local v2_dir="$4" # unmodified new deployed version
- local vt_dir="$5" # target version where the result of the
- # merge should be placed
# use `find "$vp_dir/"*` instead of `find "$vp_dir"` because
# the last one also gives $vp_dir in the list of directories
@@ -76,10 +71,10 @@ merge() {
local stripped_filename=${f#$vp_dir/}
local vp="$vp_dir/$stripped_filename"
- local v1="$v1_dir/$stripped_filename"
- local vu="$vu_dir/$stripped_filename"
- local v2="$v2_dir/$stripped_filename"
- local vt="$vt_dir/$stripped_filename"
+ v1="$v1_dir/$stripped_filename"
+ vu="$vu_dir/$stripped_filename"
+ v2="$v2_dir/$stripped_filename"
+ vt="$vt_dir/$stripped_filename"
if [ ! -e "$vt" ]; then
if [ -e "$v1" -a -e "$vu" ]; then
@@ -104,7 +99,7 @@ merge() {
cp -a "$v1" "$vt"
fi
elif [ -f "$vp" ]; then
- merge_regular_file "$v1" "$vu" "$v2" "$vt"
+ merge_regular_file
else
die "ERROR: unexpected error"
fi
@@ -114,10 +109,6 @@ merge() {
merge_regular_file() {
- local v1="$1"
- local vu="$2"
- local v2="$3"
- local vt="$4"
# Reference table for merging a regular file
#
# V1 Vuser V2 action
@@ -167,48 +158,44 @@ merge_regular_file() {
}
-if [ "$#" = 0 ]; then
+if [ "$#" != 2 ]; then
usage "$0"
fi
+tempdir=$(mktemp -d)
+version_label="$2"
if [ "$1" = "merge" ]; then
- if [ "$#" != 2 ]; then
- usage "$0"
+ "$mounting_script" "$tempdir"
+ if [ ! -d "$tempdir/systems/$version_label" ]; then
+ "$unmount" "$tempdir"
+ die "Error: version not found - '$version_label'"
fi
- new_version="$2"
- mounting_point=$(mktemp -d)
- "$mounting_script" "$mounting_point"
- if [ ! -d "$mounting_point/systems/$new_version" ]; then
- "$unmount" "$mounting_point"
- die "Error: version not found - '$new_version'"
- fi
- v1_dir="$mounting_point/systems/default/orig/etc"
- vu_dir="$mounting_point/systems/default/run/etc"
- v2_dir="$mounting_point/systems/$new_version/run/etc"
- vt_dir="$mounting_point/systems/$new_version/run/etc.new"
- mkdir "$vt_dir"
- trap 'rm -rvf "$vt_dir"; "$unmount" "$mounting_point"' EXIT
+ factory_etc="$tempdir/systems/default/orig/etc" # factory version
+ user_etc="$tempdir/systems/default/run/etc" # user modified version
+ new_etc="$tempdir/systems/$version_label/run/etc" # newly deployed version
+ merge_etc="$tempdir/systems/$version_label/run/etc.new" # target version
+
+ mkdir "$merge_etc"
+ trap 'rm -rvf "$merge_etc"; "$unmount" "$tempdir"' EXIT INT TERM
# For every pathname in V1, Vuser, or V2
- merge "$v1_dir" "$v1_dir" "$vu_dir" "$v2_dir" "$vt_dir"
- merge "$vu_dir" "$v1_dir" "$vu_dir" "$v2_dir" "$vt_dir"
- merge "$v2_dir" "$v1_dir" "$vu_dir" "$v2_dir" "$vt_dir"
+ merge "$factory_etc"
+ merge "$user_etc"
+ merge "$new_etc"
- rm -rf "$v2_dir"
- mv "$vt_dir" "$v2_dir"
+ rm -rf "$new_etc"
+ mv "$merge_etc" "$new_etc"
elif [ "$1" = "sync" ]; then
- canonical_version="$2"
- mounting_point=$(mktemp -d)
- "$mounting_script" "$mounting_point"
- trap '"$unmount" "$mounting_point"' EXIT
- if [ ! -d "$mounting_point/systems/$canonical_version" ]; then
- die "Error: version not found - '$canonical_version'"
+ "$mounting_script" "$tempdir"
+ trap '"$unmount" "$tempdir"' EXIT INT TERM
+ if [ ! -d "$tempdir/systems/$version_label" ]; then
+ die "Error: version not found - '$version_label'"
fi
- for version_dir in "$mounting_point/systems/"*; do
+ for version_dir in "$tempdir/systems/"*; do
version="$(basename "$version_dir")"
if [ -d "$version_dir" -a ! -h "$version_dir" \
- -a $version != $canonical_version ]; then
- cp -a "$mounting_point/systems/$canonical_version/run/etc" \
+ -a $version != $version_label ]; then
+ cp -a "$tempdir/systems/$version_label/run/etc" \
"$version_dir/run/etc.new"
mv "$version_dir/run/etc" "$version_dir/run/etc.old"
mv "$version_dir/run/etc.new" "$version_dir/run/etc"
@@ -218,4 +205,3 @@ elif [ "$1" = "sync" ]; then
else
usage "$0"
fi
-
diff --git a/baserock-system-config-sync/mount-system-versions-dir b/baserock-system-config-sync/mount-system-versions-dir
index 6028ea4..b41f3a6 100755
--- a/baserock-system-config-sync/mount-system-versions-dir
+++ b/baserock-system-config-sync/mount-system-versions-dir
@@ -30,11 +30,11 @@ if [ "$#" != 1 ]; then
fi
-mouting_point="$1"
+mounting_point="$1"
disk=$(awk '{ if ($1 != "rootfs" && $2 == "/") print $1 }' /proc/mounts)
-mkdir -p "$mouting_point"
+mkdir -p "$mounting_point"
-mount "$disk" "$mouting_point"
+mount "$disk" "$mounting_point"