linux-update/linux-update

182 lines
3.8 KiB
Plaintext
Raw Normal View History

2012-11-22 12:07:02 +01:00
#!/bin/sh
[ 0 = "`id -u`" ] || exec sudo http_proxy="$http_proxy" "$0" "$@"
SOURCE_BASE_DIR=/usr/src
SOURCE_BASE_URI=http://www.kernel.org/pub/linux/kernel/v3.x/
usage() {
echo "Usage: $0 $(help | sed -ne '3,$s/^\([^'"`printf '\t'`"']*\)'"`printf '\t'`"'.*$/\1/p' | tr '\n' '|' | sed -e 's/|/ | /g;s/ | $//')"
}
help() { #@ Print this help message
2012-11-22 12:07:02 +01:00
cat <<EOH
$0 Command
possible commands:
EOH
}
cache() {
eval "$1() { echo '$(echo "$2" | sed -e 's/'\''/'"'\\\''"'/g')'; }"
$1
}
_latest_stable() {
curl -s http://www.kernel.org/kdist/finger_banner | sed -E -ne 's/^The latest stable .* version of the Linux kernel is: *([0-9.]*).*/\1/p' | head -1
}
latest_stable() { #@ prints the latest stable available version on kernel.org
2012-11-22 12:07:02 +01:00
cache latest_stable "`_latest_stable`"
}
print_version() {
while read v d
do
echo "$v"
done
}
print_dir() {
while read v d
do
echo "$d"
done
}
kernelversion_of() {
make -isC "$1" kernelversion
}
dir_of() {
w="${1}"
fetched | while read v d
do
[ "$w" = "$v" ] && echo "$d"
done
}
fetched() { #@ prints all fetched versions
2012-11-22 12:07:02 +01:00
for d in "${SOURCE_BASE_DIR}"/linux-*
do
v="`kernelversion_of "$d"`"
if [ "$v" ]
then
echo "$v $d"
fi
done
}
latest_version() {
sort -rV | head -1
}
latest_fetched() { #@ prints the latest fetched version
2012-11-22 12:07:02 +01:00
fetched | latest_version
}
is_listed() {
awk \""${1}"'"==$1{print$0;exit}'
}
latest_stable_is_fetched() {
fetched | is_listed "`latest_stable`"
}
update_available() { #@ prints the latest stable available version on kernel.org if it isn't fetched yet
2012-11-22 12:07:02 +01:00
[ -z "`latest_stable_is_fetched`" ]
}
download_uri() { #@ [V] prints the uri of V (default: latest_stable)
2012-11-22 12:07:02 +01:00
echo "${SOURCE_BASE_URI}/linux-${1:-`latest_stable`}.tar.xz"
}
download() { #@ [V] downloads the kernel of V (default: latest_stable)
echo "Download $1" >&2
2012-11-22 12:07:02 +01:00
curl `download_uri "${1}"`
}
unpack() { #@ simple unpack with unxz and tar in \$SOURCE_BASE_DIR (default: $SOURCE_BASE_DIR)
2012-11-22 12:07:02 +01:00
unxz | tar -C "${SOURCE_BASE_DIR}" -xf -
}
fetch() { #@ [V] downloads and unpack the kernel of V (default: latest_stable)
download "${1}" | unpack
2012-11-22 12:07:02 +01:00
}
update() { #@ downloads and unpack the latest_stable kernel if it isn't fetched yet
2012-11-22 12:07:02 +01:00
if update_available
then
echo Update available: `latest_stable`
fetch
else
echo "Upto date."
return 1
fi
}
configs() {
fetched | while read v d
do
[ -e "$d/.config" ] && echo "$v $d"
done
}
has_config() { #@ [V] This kernel has a config?
2012-11-22 12:07:02 +01:00
configs | is_listed "$2"
}
latest_config() { #@ Which is the latest kernel with config?
2012-11-22 12:07:02 +01:00
configs | latest_version
}
copy_to_dir_config() {
cp "${2:-`latest_config | print_dir`}/.config" "${1:-`latest_fetched | print_dir`}"
}
install_config() { #@ [V] Copys the config of the newest kernel with config to V.
2012-11-22 12:07:02 +01:00
d="${1:-`latest_fetched | print_dir`}"
s="${2:-`latest_config | print_dir`}"
[ -e "$d/.config" ] || copy_to_dir_config "${d}" "${s}"
}
oldconfig() { #@ [V] Run oldconfig (calls install_config previeusly).
2012-11-22 12:07:02 +01:00
d="${1:-`latest_fetched | print_dir`}"
install_config "$d" && make -C "$d" oldconfig
}
install_all() {
echo "=====-- $1 --====="
2012-11-22 12:07:02 +01:00
d="${1:-`latest_fetched | print_dir`}"
echo "===== $d ====="
oldconfig "$d" && \
make -j3 -C "$d" all && \
make -j3 -C "$d" modules_install && \
make -j3 -C "$d" install
2012-11-22 12:07:02 +01:00
}
cmd="$1"
shift
case "$cmd" in
latest_stable) latest_stable ;;
fetched) fetched ;;
latest_fetched) latest_fetched ;;
update_available) update_available ;;
fetch) fetch "$@" ;;
download_uri) download_uri "$@" ;;
download) download "$@" ;;
unpack) unpack ;;
update) update ;;
help|--help|-h) help ;;
usage) usage ;;
latest_stable_is_fetched) latest_stable_is_fetched ;;
oldconfig) oldconfig "${1:+`dir_of "$1"`}" ;;
configs) configs "${1:+`dir_of "$1"`}" ;;
install) install_all "${1:+`dir_of "$1"`}" ;;
all) update "$1" && install_all "${1:+`dir_of "$1"`}" ;;
2012-11-22 12:07:02 +01:00
*)
usage >&2
exit 1
;;
esac