aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/.local/bin/pacsync
blob: 2e5d60fb4444c5c8a1d34b43f4a89d750e2a5328 (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
#!/bin/sh

# Run only if user logged in (prevent cron errors)
w | grep "^$USER\W" >/dev/null || exit

# Don't try to sync if pacman is already running
if pidof pacman; then
  exit
fi

# Check several times before giving up, useful when just waking up from sleep
# since internet is usually not available right away
wget -q --tries=5 --timeout=20 --spider 1.1.1.1 > /dev/null || exit

# Source the needed env variables so that it can function properly from cron
. ~/.cache/sessionenv

notify-send " System upgrade" "Syncing repositories and downloading packages..."

touch ~/.cache/pacsynclive
killall -41 waybar

sudo pacman -Syuw --noconfirm || notify-send " System upgrade" \
  "Error downloading updates. Check your internet connection or that you have the required permissions"

rm -f ~/.cache/pacsynclive
killall -41 waybar

upno=$(pacman -Qu | wc -l)

if [ $upno -lt 0 ]; then
  notify-send " System upgrade" "Repository sync finished. $upno updates are available"
fi