blob: 165ebdeae2c5b15d54c829fd10d06208002c1e6a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#!/usr/bin/env bash
set -euo pipefail
# pacdiff-merge - Merge .pacnew files using pacdiff and meld (or $MERGE_TOOL)
MERGE_TOOL="${MERGE_TOOL:-/usr/bin/meld}"
REQUIRED_CMDS=(pacdiff sudo snapper "$MERGE_TOOL")
SKIP_MERGE=("/etc/pacman.d/mirrorlist")
function check_can_write {
local target_file="$1"
if lsattr "$target_file" 2>/dev/null | grep -q '^.\{4\}i'; then
echo "Error: $target_file is immutable (chattr +i). Remove immutable flag with: sudo chattr -i $target_file"
return 1
fi
return 0
}
for cmd in "${REQUIRED_CMDS[@]}"; do
command -v "${cmd%% *}" >/dev/null 2>&1 || {
echo "Missing required command: $cmd"
exit 1
}
done
export SUDO_EDITOR="$MERGE_TOOL"
mapfile -t pacfiles < <(/usr/bin/pacdiff --output)
if [[ ${#pacfiles[@]} -eq 0 ]]; then
echo "No .pacnew files found. Nothing to merge."
if [[ -t 0 ]]; then
read -rp "Press enter to finish."
fi
exit 0
fi
echo "Creating pre-merge snapshot..."
snap=$(sudo snapper create -d "Before PacDiff merge" -p)
echo "Created snapshot ${snap}"
for i in "${pacfiles[@]}"; do
echo -e "\nMerging ${i} ..."
if ! check_can_write "${i/.pacnew/}"; then
echo "Skipping ${i} due to immutability."
continue
fi
if [[ " ${SKIP_MERGE[*]} " =~ [[:space:]]${i/.pacnew/}[[:space:]] ]]; then
echo "Skipping ${i}, in skip list. (Deleting .pacnew file.)"
/usr/bin/sudo rm -f "${i}"
continue
fi
/usr/bin/sudo -e "${i}" "${i/.pacnew/}"
while true; do
read -erp 'Were the files successfully merged? (delete .pacnew) [y/N/q] ' answer
case "$answer" in
[Yy]*)
echo "Deleting ${i}..."
sudo rm "${i}"
break
;;
[Qq]*)
echo "Aborting."
exit 1
;;
[Nn]* | "") break ;;
*) echo "Invalid input. Please enter 'y', 'n', or 'q'." ;;
esac
done
done
echo -e "\nAll .pacnew files processed."
read -rp "Press enter to finish."
|