[[ -w $file ]] || s=sudo
+ local in_section=false
if $exists; then
+ local tailn=1
local temp="$(mktemp -d)/$file_name"
cp "$file" "$temp"
cp /dev/null "$file"
- local in_section=false
while IFS= read -r line; do
- if [[ $line == $begin ]]; then
+ tailn=$(( tailn + 1 ))
+ if [[ $line == "$begin" ]]; then
in_section=true;
+ break
fi
- if ! $in_section; then
- printf '%s\n' "$line" >> $file
- fi
- if [[ $line == $end ]]; then
- in_section=false;
- fi
+ printf '%s\n' "$line" >> $file
done < "$temp"
fi
$s tee -a "$file" >/dev/null <<<"$end"
fi
+ if $exists && $in_section; then
+ while IFS= read -r line; do
+ if [[ $line == "$begin" ]]; then
+ in_section=true;
+ fi
+ if ! $in_section; then
+ printf '%s\n' "$line" >> $file
+ fi
+ if [[ $line == $end ]]; then
+ in_section=false;
+ fi
+ done < <(tail -n +$tailn "$temp")
+ fi
+
+
if ! $exists; then
ret=1
if $verbose; then
echo "backup of original at $temp"
echo diff -u "$temp" "$file":
echo "$diff"
- elif $verbose; then
- echo "No changes made to $file"
+ #elif $debug; then
+ # echo "No changes made to $file"
fi
else
# for systems like openwrt which don't have diff