summaryrefslogtreecommitdiff
path: root/savelocaltweaks
diff options
context:
space:
mode:
Diffstat (limited to 'savelocaltweaks')
-rwxr-xr-xsavelocaltweaks27
1 files changed, 14 insertions, 13 deletions
diff --git a/savelocaltweaks b/savelocaltweaks
index aff588a..b1fd355 100755
--- a/savelocaltweaks
+++ b/savelocaltweaks
@@ -8,11 +8,11 @@ TEMP="`getopt -s sh -o t:f -l target:,force -n "$PRG" -- "$@"`"
if [ $? != 0 ] ; then echo >&2 "ERROR: Internal getopt error." ; exit 1 ; fi
eval set -- "$TEMP"
-realtargetdir=''
+targetdir=''
force='no'
while true ; do
case "$1" in
- -t|--target) realtargetdir="$2" ; shift 2 ;;
+ -t|--target) targetdir="$2" ; shift 2 ;;
-f|--force) force="yes" ; shift ;;
--) shift ; break ;;
*) echo >&2 "ERROR: Internal error resolving options." ; exit 1 ;;
@@ -20,20 +20,21 @@ while true ; do
done
basedir="/etc"
-targetdir="$(mktemp -td localtweaks.XXXXXX)"
includefile="/etc/local/localtweaks.include"
excludefile="/etc/local/localtweaks.exclude"
extensions=".orig .old"
-if [ -n "$realtargetdir" ] && [ -e "$realtargetdir" ]; then
+if [ -n "$targetdir" ] && [ -e "$targetdir" ]; then
if [ "$force" = "yes" ]; then
- rm -rf "$realtargetdir"
+ rm -rf "$targetdir"
else
echo >&2 "Error: Target directory exists already."
exit 1
fi
fi
+tempdir="$(mktemp -td localtweaks.XXXXXX)"
+
for ext in $extensions; do
extfiles="$(find $basedir -name "*$ext")"
for extfile in $extfiles; do
@@ -77,20 +78,20 @@ for file in $files; do
fi
done
- newdir="$targetdir/$basedir/$(dirname "$file")"
+ newdir="$tempdir/$basedir/$(dirname "$file")"
mkdir -p "$newdir"
cp -af "$basedir/$file" "$newdir"
# Only diff against existing and non-empty files.
if [ -n "$ext" ] && [ -s "$basedir/$file$ext" ]; then
- diff -ruN "$basedir/$file$ext" "$basedir/$file" > "$targetdir/$basedir/$file.diff" || [ $? -lt 2 ]
- chown --reference="$basedir/$file" "$targetdir/$basedir/$file.diff"
- chmod --reference="$basedir/$file" "$targetdir/$basedir/$file.diff"
- chmod a-x "$targetdir/$basedir/$file.diff"
+ diff -ruN "$basedir/$file$ext" "$basedir/$file" > "$tempdir/$basedir/$file.diff" || [ $? -lt 2 ]
+ chown --reference="$basedir/$file" "$tempdir/$basedir/$file.diff"
+ chmod --reference="$basedir/$file" "$tempdir/$basedir/$file.diff"
+ chmod a-x "$tempdir/$basedir/$file.diff"
fi
done
-if [ -n "$realtargetdir" ]; then
- mv "$targetdir" "$realtargetdir"
- rm -rf "$targetdir"
+if [ -n "$targetdir" ]; then
+ mv "$tempdir" "$targetdir"
+ rm -rf "$tempdir"
fi