diff --git a/.config/Scripts/arch-updates.sh b/.config/Scripts/arch-updates.sh new file mode 100755 index 0000000..f1977a8 --- /dev/null +++ b/.config/Scripts/arch-updates.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +path=${HOME}/.config/Scripts/ +#trap 'exit' SIGINT + +function main_loop { + while true; do + echo '' > ~/.config/Scripts/status + check_for_updates + sleep 600 + done +} + +function status { + echo $$ > ${path}polybar_updates.pid + while true; do + cat ~/.config/Scripts/status + sleep 1 + done +} + +function check_for_updates { + checkupdates | nl -w2 -s '. ' >| ${path}repo.pkgs + yay -Qu --aur | nl -w2 -s '. ' >| ${path}aur.pkgs + updates=$(cat ${path}*.pkgs | wc -l) + + echo "0" >| ${path}status + [ $updates -gt 0 ] && echo "%{F#e60053}$updates" >| ${path}status + + >| ${path}packages + [ -s ${path}repo.pkgs ] && cat ${path}repo.pkgs >> ${path}packages + [ -s ${path}repo.pkgs ] && [ -s ${path}aur.pkgs ] && printf "\n" >> ${path}packages + [ -s ${path}aur.pkgs ] && sed '1iAUR Updates' ${path}aur.pkgs >> ${path}packages +} + +function notify { +if [[ $(cat ~/.config/Scripts/status) -eq 0 ]] +then + notify-send 0 +else + notify-send "$(cat ~/.config/Scripts/packages)" +fi +} + +function upgrade { +urxvt -e yay --noconfirm -Syu +echo "0" > ~/.config/polybar/scripts/arch/status +} + + +[[ $# -eq 0 ]] && main_loop +[[ $1 == "-s" ]] && status +[[ $1 == "-c" ]] && echo '' > ~/.config/Scripts/status && check_for_updates +[[ $1 == "-n" ]] && notify diff --git a/.config/Scripts/archnews b/.config/Scripts/archnews new file mode 100755 index 0000000..7096f64 --- /dev/null +++ b/.config/Scripts/archnews @@ -0,0 +1,96 @@ +#!/bin/bash + +# This is a simple script that refines the output of checkupdates and +# grabs the latest news from the Arch RSS news feed. The idea is to +# have some extra info before committing to grabbing a fresh copy +# of the package database via pacman -Sy. +# +# Prerequisites: bc, xmllint + +printf "Fetching data, please wait...\n\n" + +CULIST=$(checkupdates) +if [[ $CULIST = "" ]]; then + echo "No new packages" + exit +fi + +# calculate the number of packages +IFS=$'\n' +for i in $CULIST +do + pacnum=$((pacnum+1)) +done +echo "$pacnum new packages found" + +# extract package names and then feed them to pacman -Si +PNAMES="" +for i in $CULIST +do + PNAMES+=$(printf "%s" "$i" | awk '{print $1}')" " +done +IFS='' +PSI="pacman -Si $PNAMES" +PSI="$(eval "$PSI")" + +# extract the relevant info from pacman -Si +PSI=$(echo "$PSI" | grep -E 'Repository|Download Size') +PSI=$(echo "$PSI" | \ + awk -F ": " '{if (NR%2 == 0) printf "%s\n", $2; else printf "%s ", $2}') + +# combine pacman -Si info with the output of checkupdates +OUT=$(paste <(echo "$PSI") <(echo "$CULIST") | column -t | tr -s " ") + +# calculate total download size and refine the output further +IFS=$'\n' +totsize_mb="0" +for i in $OUT +do + cursize_bib=$(echo "$i" | cut -d ' ' -f 2,3) + + # generate appropriate conversion multipliers + if [ "$(echo "$cursize_bib" | awk '{print $2}')" = "KiB" ]; then + mul=0.001024 + else # assumes MiB + mul=1.048576 + fi + + cursize_mb=$(echo "scale=1;($(echo "$cursize_bib" | \ + awk '{print $1}')*$mul)" | bc) + totsize_mb=$(echo "scale=1;$totsize_mb+$cursize_mb" | bc) +done + +# final output for the checkupdate stage +IFS='' +printf "\n%s\n" "$(echo -e "$OUT" | cut -d ' ' --complement -f 2,3 | \ + sort -d | column -t )" +printf "\nTotal download size: %.2f MB or %.2f MiB\n" \ + "$totsize_mb" "$(echo "$totsize_mb"*0.953674 | bc)" + +############################################################################### + +# arch news +printf "\n==============================\n" +printf "https://www.archlinux.org/news\n" +printf "==============================\n" + +# nicked from some forum, not an ideal solution, but seems to work, +# formatting has been a little bit improved here +curl -s https://www.archlinux.org/feeds/news/ | \ +xmllint --xpath //item/title\ \|\ //item/pubDate /dev/stdin | \ +sed -r -e "s: