blob: 208fc4d53e6d0a05d0c30fecafd8f62fee897818 (
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
#!/bin/bash
set -e
PKG_FILE="${HOME}/.config/dpw/packages.ini"
# Check if PACMAN is not set and find an available helper
AUR_HELPERS=("pacaur" "pikaur" "yay" "aura" "paru" "aurman")
if [ -z "${PACMAN}" ]; then
for HELPER in "${AUR_HELPERS[@]}"; do
if command -v "$HELPER" > /dev/null 2>&1; then
PACMAN="$HELPER"
break
fi
done
if [ -z "${PACMAN}" ]; then
printf "\033[1m::\033[0m No available AUR helper found."
exit 1
fi
fi
# Show help menu
if [ "${1}" = "help" ]; then
printf "\033[1m:: \033[1;31mdpw\033[0m - Executes the program normally, using the existing packages.ini or creating a new one if it doesn't exist yet.\n"
printf "\033[1m:: \033[1;31mdpw edit\033[0m - Opens the packages.ini file in the user's selected editor (defined via the EDITOR variable).\n"
printf "\033[1m:: \033[1;31mdpw update\033[0m - Overwrites the current contents of the package.ini file with the currently installed package. Useful after using pacman or paru directly to install new packages.\n"
printf "\033[1m:: \033[1;31mdpw help\033[0m - Shows this menu.\n"
exit
fi
# Generate packages.ini if it does not exist
if [ ! -e "${PKG_FILE}" ]; then
printf "\033[1m::\033[0m Packages file '%s' does not exist.\n" "${PKG_FILE}"
while true; do
printf "\033[1m::\033[0m Do you wish to generate one using the currently installed packages [Y/n]? "
read -r YN
case ${YN:-Y} in
[Yy]*)
mkdir --parents "${PKG_FILE%/*}"
"${PACMAN}" --query --explicit --quiet > "${PKG_FILE}"
break;;
[Nn]*)
exit;;
esac
done
fi
# Edit packages.ini
if [ "${1}" = "edit" ]; then
${EDITOR} "${PKG_FILE}"
exit
fi
# Update packages.ini
if [ "${1}" = "update" ]; then
while true; do
printf "\033[1m::\033[0m Do you wish to update the currently existing packages.ini [y/N]? "
read -r YN
case ${YN:-N} in
[Yy]*)
"${PACMAN}" --query --explicit --quiet > "${PKG_FILE}"
break;;
[Nn]*)
exit;;
esac
done
fi
# Calculate changes
function diff { comm -23 <(echo -n "$1") <(echo -n "$2"); }
PKG_DECLARED=$(sed 's/#.*$//;s/\s*//g; /./!d' "${PKG_FILE}" | sort --unique)
PKG_INSTALLED=$("${PACMAN}" -Q --quiet | sort --unique)
PKG_INSTALLED_EXPLICIT=$("${PACMAN}" -Q --quiet --explicit | sort --unique)
PKG_INSTALLED_UNREQUIRED=$("${PACMAN}" -Q --quiet --explicit --unrequired --unrequired | sort --unique)
PKG_EXPLICIT_NOT_DECLARED=$(diff "${PKG_INSTALLED_EXPLICIT}" "${PKG_DECLARED}")
PKG_MARK_DEPENDENCY=$(diff "${PKG_EXPLICIT_NOT_DECLARED}" "${PKG_INSTALLED_UNREQUIRED}")
PKG_REMOVE=$(diff "${PKG_EXPLICIT_NOT_DECLARED}" "${PKG_MARK_DEPENDENCY}")
PKG_DECLARED_NOT_EXPLICIT=$(diff "${PKG_DECLARED}" "${PKG_INSTALLED_EXPLICIT}")
PKG_INSTALL=$(diff "${PKG_DECLARED_NOT_EXPLICIT}" "${PKG_INSTALLED}")
PKG_MARK_EXPLICIT=$(diff "${PKG_DECLARED_NOT_EXPLICIT}" "${PKG_INSTALL}")
# Print summary
if [ -n "${PKG_REMOVE}" ]; then
printf "\033[1m::\033[1;31m Remove\033[0m %s\n" "$(echo "${PKG_REMOVE}" | tr '\n' ' ')"
fi
if [ -n "${PKG_INSTALL}" ]; then
printf "\033[1m::\033[1;32m Install\e[0m %s\n" "$(echo "${PKG_INSTALL}" | tr '\n' ' ')"
fi
if [ -n "${PKG_MARK_DEPENDENCY}" ]; then
printf "\033[1m::\033[1;33m Mark dependency\e[0m %s\n" "$(echo "${PKG_MARK_DEPENDENCY}" | tr '\n' ' ')"
fi
if [ -n "${PKG_MARK_EXPLICIT}" ]; then
printf "\033[1m::\033[1;33m Mark explicit\e[0m %s\n" "$(echo "${PKG_MARK_EXPLICIT}" | tr '\n' ' ')"
fi
# Do actions
if [ -n "${PKG_REMOVE}" ]; then
"${PACMAN}" --remove --recursive --unneeded ${PKG_REMOVE}
fi
if [ -n "${PKG_INSTALL}" ]; then
"${PACMAN}" --sync ${PKG_INSTALL}
fi
if [ -n "${PKG_MARK_DEPENDENCY}" ]; then
"${PACMAN}" --database --asdeps ${PKG_MARK_DEPENDENCY}
fi
if [ -n "${PKG_MARK_EXPLICIT}" ]; then
"${PACMAN}" --database --asexplicit ${PKG_MARK_EXPLICIT}
fi
# Check for newly unused dependencies arising from the database changes
PKG_INSTALLED_UNUSED=$("${PACMAN}" -Q --quiet --deps --unrequired --unrequired | sort --unique)
if [ -n "${PKG_INSTALLED_UNUSED}" ]; then
printf "\033[1m::\033[1;31m Prune\033[0m %s\n" "$(echo "${PKG_INSTALLED_UNUSED}" | tr '\n' ' ')"
"${PACMAN}" --remove --recursive ${PKG_INSTALLED_UNUSED}
fi
# Do a system upgrade
echo -e "\033[1m::\033[1;36m Upgrade\033[0m all"
"${PACMAN}" --sync --sysupgrade --refresh
|