-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-qpdfview.sh
executable file
·77 lines (61 loc) · 2.01 KB
/
setup-qpdfview.sh
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
74
75
76
77
#!/bin/bash
# script that modifies GLOBAL qpdfview desktop startup configuration to omit the
# --unique cmdline parameter which causes new PDF opens to open in a new tab of
# any existing qpdfview window/session (I find this behavior very annoying and
# unproductive.
# Ensure the script is being run as root
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root." >&2
exit 1
fi
# Step 1: Define variables
DESKTOP_DIR="/usr/share/applications"
DESKTOP_FILE="$DESKTOP_DIR/qpdfview.desktop"
APT_HOOK="/etc/apt/apt.conf.d/99-qpdfview-remove-unique"
SED_COMMAND=("sed" "-i" "s/--unique/--non-unique/g" "$DESKTOP_FILE")
showDesktopEntrySection() {
awk '/^\[Desktop Entry\]/ {p=1; next} p && /^\[/ {exit} p' "$DESKTOP_FILE";
}
refreshDesktopDatabase() {
echo "Refreshing the desktop database..."
update-desktop-database "$DESKTOP_DIR"
}
echo "before:"
showDesktopEntrySection
# Step 2: Apply the initial sed command
echo "Applying sed command to remove --unique..."
"${SED_COMMAND[@]}"
echo
echo "after:"
showDesktopEntrySection
refreshDesktopDatabase
exit 0
# Step 3: Verify the change
echo "Verifying the change..."
grep -F "Exec=" "$DESKTOP_FILE" | grep -- "--unique" && {
echo "Error: --unique still found in $DESKTOP_FILE. Aborting."
exit 1
} || echo "Success: --unique removed from $DESKTOP_FILE."
# Step 4: Create an APT hook to reapply the sed command after upgrades
echo "Creating APT hook in $APT_HOOK..."
if test -f "$APT_HOOK"; then
echo "before: $APT_HOOK"
cat "$APT_HOOK"
fi
cat <<EOF > "$APT_HOOK"
DPkg::Post-Invoke {
$(printf '%q ' "${SED_COMMAND[@]}") || true;
};
EOF
if test -f "$APT_HOOK"; then
echo "after: $APT_HOOK"
cat "$APT_HOOK"
fi
exit 0
# Step 5: Refresh the desktop database
echo "Refreshing the desktop database..."
update-desktop-database /usr/share/applications/
# Step 6: Verify the desktop database is updated
echo "Verifying desktop entry..."
grep -F "Exec=" "$DESKTOP_FILE"
echo "Setup complete! The --unique option has been removed and the APT hook is in place."