#!/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 cat <&2 curl `download_uri "${1}"` } unpack() { #@ simple unpack with unxz and tar in \$SOURCE_BASE_DIR (default: $SOURCE_BASE_DIR) unxz | tar -C "${SOURCE_BASE_DIR}" -xf - } fetch() { #@ [V] downloads and unpack the kernel of V (default: latest_stable) download "${1}" | unpack } update() { #@ downloads and unpack the latest_stable kernel if it isn't fetched yet 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? configs | is_listed "$2" } latest_config() { #@ Which is the latest kernel with config? 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. 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). d="${1:-`latest_fetched | print_dir`}" install_config "$d" && make -C "$d" oldconfig } install_all() { echo "=====-- $1 --=====" 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 } 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"`}" ;; *) usage >&2 exit 1 ;; esac