-
Notifications
You must be signed in to change notification settings - Fork 1
/
rpi-headers
119 lines (100 loc) · 3.59 KB
/
rpi-headers
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
set -o nounset
set -o errexit
HEAD_PACKAGE=linux-headers-$(uname -r)
# Check if already installed
function check_headers() {
if [[ -e "/lib/modules/$(uname -r)/build/arch/arm" ]]; then
if [[ ! -e "/lib/modules/$(uname -r)/build/kernel/time/timeconst.bc" ]]; then
# https://github.com/raspberrypi/linux/issues/1441
# https://www.niksula.hut.fi/~mhiienka/Rpi/linux-headers-rpi/linux-headers-4.4.11-v7+_4.4.11-v7+-2_armhf.deb
return 1
fi
return 0
fi
return 1
}
check_headers && (
echo "${HEAD_PACKAGE} already installed"
echo ""
exit 0
)
# Try APT (likely to fail)
check_headers || (
echo "Checking apt-cache for ${HEAD_PACKAGE} ..."
echo " Running apt-get update ..."
sudo apt-get update > /dev/null || true
# niksula.hut.fi package shows up in "apt-cache search"
DPKG_LIST=$(dpkg --list "${HEAD_PACKAGE}" 2>&1 | grep "no package" || true)
if [[ "${DPKG_LIST}" == "" ]]; then
echo " Uninstalling old package ..."
sudo dpkg --remove --force-remove-reinstreq "${HEAD_PACKAGE}" &> /dev/null
fi
APT_CACHE=$(apt-cache search "${HEAD_PACKAGE}")
if [[ "${APT_CACHE}" != "" ]]; then
echo " Found package, installing ..."
sudo apt-get -y install "${HEAD_PACKAGE}" > /dev/null
else
echo " Did not find package"
fi
echo ""
)
# Try niksula.hut.fi/~mhiienka
check_headers || (
echo "Checking https://www.niksula.hut.fi/~mhiienka for ${HEAD_PACKAGE} ..."
WGET_PACKAGE=$(wget https://www.niksula.hut.fi/~mhiienka/Rpi/linux-headers-rpi/ -qq --tries 3 -O - | sed -n "s/.*href=\"\([^\"\/]\+\).*/\1/p" | sed 's/%2B/+/ig' | grep \.deb | grep "${HEAD_PACKAGE}" || true)
if [[ "${WGET_PACKAGE}" != "" ]]; then
cd /usr/src
if [[ -e "${WGET_PACKAGE}" ]]; then
echo " Deleting ${WGET_PACKAGE} ..."
sudo rm -f "${WGET_PACKAGE}" > /dev/null
fi
echo " Downloading ${WGET_PACKAGE} ..."
sudo wget --quiet --tries 3 "https://www.niksula.hut.fi/~mhiienka/Rpi/linux-headers-rpi/${WGET_PACKAGE}" > /dev/null
if [[ -e "${WGET_PACKAGE}" ]]; then
DPKG_LIST=$(dpkg --list "${HEAD_PACKAGE}" 2>&1 | grep "no package" || true)
if [[ "$DPKG_LIST" == "" ]]; then
echo " Uninstalling old package ..."
sudo dpkg --remove --force-remove-reinstreq "${HEAD_PACKAGE}" &> /dev/null
fi
if [[ -e "${HEAD_PACKAGE}" ]]; then
echo " Deleting $(pwd)/${HEAD_PACKAGE}/ ..."
sudo rm -rf "${HEAD_PACKAGE}" > /dev/null
fi
echo " Installing package ..."
sudo dpkg --install "${WGET_PACKAGE}" > /dev/null || true
sudo rm -f "${WGET_PACKAGE}" > /dev/null
check_headers && (
echo " Installing apt-get missing dependencies ..."
sudo apt-get -y check > /dev/null
sudo apt-get -fy install > /dev/null
) || (
echo " Install failed, removing ..."
sudo dpkg --remove --force-remove-reinstreq "${HEAD_PACKAGE}" &> /dev/null
sudo rm -rf "/lib/modules/$(uname -r)"
)
else
echo " Download failed"
fi
else
echo " Did not find package"
fi
echo ""
)
check_headers || (
echo "Attempting to build from source ..."
TEMP_DIR=$(mktemp -d) && cd ${TEMP_DIR}
KERNEL_BASE=$(echo $(uname -r) | sed -n "s/\([0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/p")
echo " Downloading https://github.com/emmercm/rpi-kernel ..."
wget --quiet --tries 3 --timestamping https://raw.githubusercontent.com/emmercm/rpi-kernel/master/rpi-kernel && chmod +x rpi-kernel > /dev/null
if [[ -e "rpi-kernel" ]]; then
echo ""
./rpi-kernel --version ${KERNEL_BASE} modules || (
echo " Build failed, consider running rpi-kernel to build the entire kernel and headers together"
)
else
echo " Download failed"
fi
echo ""
)
check_headers || exit 1