Skip to content

Commit

Permalink
Merge pull request #17 from jlaunay/develcheck
Browse files Browse the repository at this point in the history
check devel-updates from AUR with last commit
  • Loading branch information
savely-krasovsky authored Dec 26, 2023
2 parents eec7872 + 21c44a7 commit aa5b017
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 10 deletions.
5 changes: 5 additions & 0 deletions po/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Poedit 3.2.2\n"

msgid "%d devel-update available from AUR"
msgid_plural "%d devel-updates available from AUR"
msgstr[0] "%d mise à jour devel disponible via AUR"
msgstr[1] "%d mises à jour devel disponibles via AUR"

msgid "%d update available from AUR"
msgid_plural "%d updates available from AUR"
msgstr[0] "%d mise à jour disponible via AUR"
Expand Down
6 changes: 6 additions & 0 deletions po/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ msgstr ""
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : 2);\n"
"X-Generator: Poedit 3.2.2\n"

msgid "%d devel-update available from AUR"
msgid_plural "%d devel-updates available from AUR"
msgstr[0] "%d devel-обновление доступно из AUR"
msgstr[1] "%d devel-обновления доступно из AUR"
msgstr[2] "%d devel-обновлений доступно из AUR"

msgid "%d update available from AUR"
msgid_plural "%d updates available from AUR"
msgstr[0] "%d обновление доступно из AUR"
Expand Down
5 changes: 5 additions & 0 deletions po/tr_TR.po
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.3.1\n"

msgid "%d devel-update available from AUR"
msgid_plural "%d devel-updates available from AUR"
msgstr[0] "AUR'dan %d devel-güncellemesi mevcut"
msgstr[1] "AUR'dan %d devel-güncellemesi mevcut"

# In Turkish, the plural suffix is not used if the number of the mentioned entity is specified. That's why singular and plural translations are the same.
msgid "%d update available from AUR"
msgid_plural "%d updates available from AUR"
Expand Down
112 changes: 102 additions & 10 deletions waybar-updates
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ usage() {
echo "Usage: waybar-updates [options]
-i, --interval Interval between checks
-c, --cycles Cycles between online checks (e.g. 6s * 600 cycles = 3600s = 1h between online checks)
-l, --packages-limit Maximum number of packages to be shown in notifications and tooltip"
-l, --packages-limit Maximum number of packages to be shown in notifications and tooltip
-d, --devel Enable devel checks"
exit 2
}

interval=6
cycles_number=600
packages_limit=10
devel=false

PARSED_ARGUMENTS=$(getopt -o "hi:c:l:" --long "help,interval,cycles,packages-limit" --name "waybar-updates" -- "$@")
PARSED_ARGUMENTS=$(getopt -o "hi:c:l:d::" --long "help,interval,cycles,packages-limit,devel::" --name "waybar-updates" -- "$@")
eval set -- "$PARSED_ARGUMENTS"
while :; do
case "$1" in
Expand All @@ -28,6 +30,10 @@ while :; do
packages_limit="$2"
shift 2
;;
-d | --devel)
devel=true
shift 2
;;
-h | --help) usage ;;
--)
shift
Expand All @@ -51,6 +57,60 @@ function check_pacman_updates() {
pacman_updates_count=$(echo "$pacman_updates" | grep -vc ^$)
}

function check_devel_updates() {
ignored_packages=$(pacman-conf IgnorePkg)
if [ "$1" == "online" ]; then
develsuffixes="git"
develpackages=$(pacman -Qm | grep -Ee "$develsuffixes")
if [ -n "$ignored_packages" ]; then
develpackages=$(grep -vF "$ignored_packages" <<< "$develpackages")
fi
rm -f "$tmp_devel_packages_file"
tmp_devel_packages_file=$(mktemp --suffix -waybar-updates)
build_devel_list "$develpackages" "online"
elif [ "$1" == "offline" ]; then
new_devel_packages=$(pacman -Qm | grep -Ee "$develsuffixes")
old_devel_packages=$(awk '{printf ("%s %s\n", $1, $3)}' "$tmp_devel_packages_file")

develpackages=$(LC_ALL=C join <(echo "$old_devel_packages") <(echo "$new_devel_packages"))
echo "d:$develpackages"

if [[ $(echo "$develpackages" | grep -vc ^$) -ne 0 ]]; then
develpackages=$(awk '{printf ("%s %s %s\n", $1, $3, $2)}' <<< "$develpackages")
build_devel_list "$develpackages" "offline"
fi
fi
devel_updates=$(awk '{printf ("%s %s\n", $1, $2)}' "$tmp_devel_packages_file")
devel_updates_checksum=$(echo "$devel_updates" | sha256sum)
devel_updates_count=$(echo "$devel_updates" | grep -vc ^$)
}

function build_devel_list() {
custom_pkgbuild_vars="_gitname=\|_githubuser=\|_githubrepo=\|_gitcommit=\|url=\|_pkgname=\|_gitdir=\|_repo_name=\|_gitpkgname=\|source_dir=\|_name="

truncate -s 0 "$tmp_devel_packages_file"

i=0
while read -r pkgname version source
do
(( i++ ))
if [ -z "$source" ]; then
eval "$(curl -s "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=$pkgname" | grep "$custom_pkgbuild_vars")"
eval source="$(curl -s "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=$pkgname" | \
grep -zPo '(?s)source=\(.*?\)' | \
awk '/git/{print "source="$1}' | \
sed 's/source=//g' | sed '/http/p' | \
sed 's/(//;s/)//g' | tr -d '\0' | head -1)"
source=$(sed 's/^\(.*\)\(http.*$\)/\2/;s/\"//;s/'\''//' <<< "$source")
source=$(cut -f1 -d"#" <<< "$source")
fi
lastcommit=$(git ls-remote --heads "$source" | awk '{ print $1}' | cut -c1-7)
if ! echo "$version" | grep -q "$lastcommit"; then
echo "$pkgname $version $source ${lastcommit//$'\n'/ }" >> "$tmp_devel_packages_file"
fi
done <<< "$1"
}

function check_aur_updates() {
ignored_packages=$(pacman-conf IgnorePkg)
if [ -n "$ignored_packages" ]; then
Expand All @@ -70,7 +130,7 @@ function check_aur_updates() {
fi

aur_updates=$(LC_ALL=C join <(echo "$old_aur_packages") <(echo "$new_aur_packages") |
while read -r pkg a b; do
while LC_ALL=C read -r pkg a b; do
case "$(vercmp "$a" "$b")" in
-1) printf "%s %s -> %s\n" "$pkg" "$a" "$b" ;;
esac
Expand All @@ -84,12 +144,17 @@ function check_updates() {
if [ "$1" == "online" ]; then
check_pacman_updates online
check_aur_updates online
if [ $devel == true ];then check_devel_updates online; fi
elif [ "$1" == "offline" ]; then
check_pacman_updates offline
check_aur_updates offline
if [ $devel == true ];then check_devel_updates offline; fi
fi
if [ $devel == true ];then
total_updates_count=$((pacman_updates_count + aur_updates_count + devel_updates_count))
else
total_updates_count=$((pacman_updates_count + aur_updates_count))
fi
total_updates_count=$((pacman_updates_count + aur_updates_count))
}
function json() {
Expand All @@ -104,13 +169,15 @@ function json() {
function cleanup() {
echo "Cleaning up..."
rm -f "$tmp_aur_packages_file"
rm -f "$tmp_devel_packages_file"
exit 0
}
# sync at the first start
check_updates online
pacman_updates_checksum=""
aur_updates_checksum=""
devel_updates_checksum=""
# count cycles to check updates using network sometime
cycle=0
Expand All @@ -120,6 +187,7 @@ trap cleanup SIGINT SIGTERM
while true; do
previous_pacman_updates_checksum=$pacman_updates_checksum
previous_aur_updates_checksum=$aur_updates_checksum
if [ $devel == true ];then previous_devel_updates_checksum=$devel_updates_checksum; fi
if [ "$cycle" -ge "$cycles_number" ]; then
check_updates online
Expand All @@ -128,9 +196,19 @@ while true; do
check_updates offline
cycle=$((cycle + 1))
fi
if [ "$previous_pacman_updates_checksum" == "$pacman_updates_checksum" ] &&
[ "$previous_aur_updates_checksum" == "$aur_updates_checksum" ]; then
if [ $devel == true ];then
condition (){
{ [ "$previous_pacman_updates_checksum" == "$pacman_updates_checksum" ] &&
[ "$previous_aur_updates_checksum" == "$aur_updates_checksum" ] &&
[ "$previous_devel_updates_checksum" == "$devel_updates_checksum" ] ;}
}
else
condition (){
{ [ "$previous_pacman_updates_checksum" == "$pacman_updates_checksum" ] &&
[ "$previous_aur_updates_checksum" == "$aur_updates_checksum" ] ;}
}
fi
if condition; then
sleep "$interval"
continue
fi
Expand All @@ -141,7 +219,7 @@ while true; do
if [ "$pacman_updates_count" -gt 0 ]; then
template=$(ngettext "waybar-updates" "%d update available from pacman" "%d updates available from pacman" "$pacman_updates_count")
# shellcheck disable=SC2059
notify-send -u normal -i software-update-available-symbolic \
notify-send -a waybar-updates -u normal -i software-update-available-symbolic \
"$(printf "$template" "$pacman_updates_count")" \
"$(echo "$pacman_updates" | head -n "$packages_limit")"
Expand All @@ -150,7 +228,7 @@ while true; do
if [ "$aur_updates_count" -gt 0 ]; then
template=$(ngettext "waybar-updates" "%d update available from AUR" "%d updates available from AUR" "$aur_updates_count")
# shellcheck disable=SC2059
notify-send -u normal -i software-update-available-symbolic \
notify-send -a waybar-updates -u normal -i software-update-available-symbolic \
"$(printf "$template" "$aur_updates_count")" \
"$(echo "$aur_updates" | head -n "$packages_limit")"
Expand All @@ -160,7 +238,21 @@ while true; do
tooltip+="\n$aur_updates"
fi
fi
if [ $devel == true ];then
if [ "$devel_updates_count" -gt 0 ]; then
template=$(ngettext "waybar-updates" "%d devel-update available from AUR" "%d devel-updates available from AUR" "$devel_updates_count")
# shellcheck disable=SC2059
notify-send -a waybar-updates -u normal -i software-update-available-symbolic \
"$(printf "$template" "$devel_updates_count")" \
"$(echo "$devel_updates" | head -n "$packages_limit")"
if [ -z "$tooltip" ]; then
tooltip+="$devel_updates"
else
tooltip+="\n$devel_updates"
fi
fi
fi
if [ "$total_updates_count" -gt 0 ]; then
json $total_updates_count "pending-updates" "$(echo -e "$tooltip" | head -n "$packages_limit")" "pending-updates"
else
Expand Down

0 comments on commit aa5b017

Please sign in to comment.