summaryrefslogtreecommitdiff
path: root/Makefile
blob: 514d95bc67e5cf937deedcc4e08a31e8137ad734 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
snapshot_uri_base = https://snapshot.debian.org/package

sudo  !=  [ "$$(id -u)" = 0 ] || groups | grep -wo sudo
dpkg  :=  $(sudo) dpkg
apt   :=  $(sudo) apt

kernel_version          !=  uname -r
kernel_package_name     :=  $(subst :,,$(firstword $(shell dpkg -S /boot/vmlinuz-${kernel_version})))
kernel_package_version  !=  dpkg-query --showformat='$${Version}\n'         -W "$(kernel_package_name)"
kernel_source_package   !=  dpkg-query --showformat='$${source:Package}\n'  -W "$(kernel_package_name)"
kernel_arch             !=  dpkg-architecture -q DEB_HOST_ARCH

want_package   =  linux-image-${kernel_arch}
want_version   =  ${kernel_package_version}
want_filename  =  ${want_package}_${want_version}_${kernel_arch}.deb
wantvencoded   =  $(subst -,%2B,${want_version})
snapshot_uri   =  ${snapshot_uri_base}/${kernel_source_package}/${wantvencoded}/\#${want_package}_${want_version}

ifeq (,$(shell command -v hxprintlinks))
$(shell $(apt) install html-xml-utils >&2)
endif
ifeq (,$(shell command -v wget))
$(shell $(apt) install wget >&2)
endif

wanted_deb_uri != hxprintlinks "${snapshot_uri}" | \
		hxcopy -i "${snapshot_uri_base}" -o . | \
		hxclean | \
		hxselect -c -s '\n' 'a::attr(href)' | \
		grep -Fw -e '${want_filename}' | \
		head -1

.PHONY: install
install: ${want_filename}
	${dpkg} -E -i $^
	echo "${want_package} hold" | ${dpkg} --set-selections

${want_filename}:
	flock wget-log.txt \
		wget -a wget-log.txt --show-progress -c '${wanted_deb_uri}' -O $@.partial
	mv -T -- $@.partial $@

info:
	: '${want_package}'
	: '${want_version}'
	: '${want_filename}'
	: '${snapshot_uri}'
	: '${wanted_deb_uri}'
	dpkg -l linux-image\* | egrep '^.i |^[D|+]'