added few scripts
This commit is contained in:
parent
f80a73aae3
commit
c1c1c18ca0
|
|
@ -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
|
||||||
|
|
@ -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:<title>([^<]*?)</title><pubDate>([^<]*?)</pubDate>:\2 -- \1\n:g" | \
|
||||||
|
sed -r "s:>:>:" | \
|
||||||
|
sed -r "s:<:<:" | \
|
||||||
|
tr -s " " | \
|
||||||
|
cut -d " " --complement -f 1,5,6 | \
|
||||||
|
head -n5 # 5 of the most recent news items seems reasonable?
|
||||||
|
|
||||||
|
# syu prompt
|
||||||
|
printf "\nLaunch sudo pacman -Syu? (y/N) "
|
||||||
|
read -r CONT
|
||||||
|
if [ "$CONT" = "y" ] || [ "$CONT" = "Y" ]; then
|
||||||
|
printf "\n"
|
||||||
|
sudo pacman -Syu
|
||||||
|
else
|
||||||
|
printf "\nUpdate cancelled.\n"
|
||||||
|
fi
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Daniel Crisman's ANSI color chart script from
|
||||||
|
# The Bash Prompt HOWTO: 6.1. Colours
|
||||||
|
# http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
|
||||||
|
#
|
||||||
|
# This function echoes a bunch of color codes to the
|
||||||
|
# terminal to demonstrate what's available. Each
|
||||||
|
# line is the color code of one forground color,
|
||||||
|
# out of 17 (default + 16 escapes), followed by a
|
||||||
|
# test use of that color on all nine background
|
||||||
|
# colors (default + 8 escapes).
|
||||||
|
|
||||||
|
T='•••' # The text for the color test
|
||||||
|
|
||||||
|
echo -e "\n def 40m 41m 42m 43m 44m 45m 46m 47m";
|
||||||
|
|
||||||
|
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \
|
||||||
|
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \
|
||||||
|
' 36m' '1;36m' ' 37m' '1;37m';
|
||||||
|
|
||||||
|
do FG=${FGs// /}
|
||||||
|
echo -en " $FGs \033[$FG $T "
|
||||||
|
|
||||||
|
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
|
||||||
|
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m";
|
||||||
|
done
|
||||||
|
echo;
|
||||||
|
done
|
||||||
|
echo
|
||||||
Loading…
Reference in New Issue