summaryrefslogtreecommitdiff
path: root/uninit.d/50vcs-uninit
diff options
context:
space:
mode:
authorDavid De La Harpe Golden (Squared Financial) <dgolden@squaredfinancial.com>2012-05-31 18:27:06 +0100
committerJoey Hess <joey@kitenet.net>2012-06-02 18:05:30 -0400
commit6e7aab39cced00eae03040753c85527aab573319 (patch)
tree30431d5c28204fe2797668bfa9b6691089ae383b /uninit.d/50vcs-uninit
parent40eeedebb6be23035aea9d15aed1be706479ce79 (diff)
Preserve unmanaged ignore file entries on uninit (#673996)
Signed-off-by: David De La Harpe Golden (Squared Financial) <dgolden@squaredfinancial.com>
Diffstat (limited to 'uninit.d/50vcs-uninit')
-rwxr-xr-xuninit.d/50vcs-uninit34
1 files changed, 33 insertions, 1 deletions
diff --git a/uninit.d/50vcs-uninit b/uninit.d/50vcs-uninit
index eb9f13a..165d415 100755
--- a/uninit.d/50vcs-uninit
+++ b/uninit.d/50vcs-uninit
@@ -19,6 +19,38 @@ managed_by_etckeeper="managed by etckeeper"
if ! grep -q "$managed_by_etckeeper" "$file"; then
echo "etckeeper: "$file" does not contain \"$managed_by_etckeeper\" comment; not removing"
+ exit 0
else
- rm -f $file
+ realfile="$file"
+ if [ -n "`type -p tempfile`" ]; then
+ tempfile="tempfile"
+ elif [ -n "`type -p mktemp`" ]; then
+ tempfile="mktemp"
+ else
+ echo "etckeeper warning: can't find tempfile or mktemp" >&2
+ exit 1
+ fi
+ file=$($tempfile)
+ otherentries=
+ skipping=
+ while read line; do
+ if echo "$line" | grep -q "$managed_by_etckeeper"; then
+ if [ ! "$skipping" ]; then
+ skipping=1
+ else
+ skipping=
+ fi
+ elif [ ! "$skipping" ]; then
+ echo "$line" >> "$file"
+ otherentries=1
+ fi
+ done <"$realfile"
+
+ if [ "$otherentries" ]; then
+ echo "etckeeper: "$realfile" nonempty after \"$managed_by_etckeeper\" section removal; preserving other entries"
+ mv -f "$file" "$realfile"
+ else
+ rm -f "$file"
+ rm -f "$realfile"
+ fi
fi