aboutsummaryrefslogtreecommitdiffstats
path: root/bin/pacman-offline
blob: 9976742d2bf1878d01925521b8f3e32f247d9f20 (plain) (blame)
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
#!/bin/sh

set -e

function help() {
	echo "usage: ${0} [OPTIONS]"
	echo
	echo ' -f  force if other system-update is pending'
	echo ' -h  this help'
	echo ' -y  update sync databases'
}

while getopts 'fhy' opt; do
	case ${opt} in
		f)
			rm -f /system-update
			;;
		h)
			help
			exit 0
			;;
		y)
			pacman -Sy
			;;
	esac
done

# make sure no other update is pending
if [ -e '/system-update' -a "$(readlink '/system-update')" != '/var/cache/pacman/pkg' ]; then
	echo 'Another update is pending.' >&2
	exit 1
fi

# remove the symlink for now, will be recreated it later
rm -f /system-update

# check for available updates
if [ "$(pacman -Sup | wc -l)" -eq 0 ]; then
	echo "No updates available."
	exit 0
fi

# download packages
pacman -Suw --noconfirm

# enable system update
ln -sf /var/cache/pacman/pkg /system-update