#! /bin/bash # set -e set -u ProgName="$0" KVer='' ERROR=0 WGET=$(which wget) if [[ -z $WGET ]]; then echo "missing wget" ERROR=1 fi if (( ERROR )); then exit 1 fi function Md5Compare () { if [[ $(cat $2 | cut -d' ' -f1) \ != $(md5sum $1 | cut -d' ' -f1) ]]; then echo "Bad md5 detected on $1" exit 1 fi } function GetDownloadPath() { local v1=$(echo $KVer | cut -d'.' -f1) local v2=$(echo $KVer | cut -d'.' -f2) local v3=$(echo $KVer | cut -d'.' -f3) local v4=$(echo $KVer | cut -d'.' -f4) local path="kernel/$v1/$v1.$v2" if (( $v1 == 2 )); then if [[ -z $v3 ]]; then path="$path/$v1.$v2" else path="$path/$v1.$v2.$v3" if [[ -z $v4 ]]; then path="$path/$v1.$v2.$v3" else path="$path/$v1.$v2.$v3.$v4" fi fi else if [[ -z $v3 ]]; then path="$path/$v1.$v2" else path="$path/$v1.$v2.$v3" fi fi echo $path } function Download() { echo "Downloading files" local path=$(GetDownloadPath) local f='' for f in Modules.tar.gz Modules.tar.gz.md5 uImage uImage.md5 System.map; do if [[ ! -f d2plug-$KVer-$f ]]; then local sites="http://www.xilka.com/sheeva" local s='' for s in $sites; do if $WGET -c $s/$path/d2plug-$KVer-$f && [[ -f d2plug-$KVer-$f ]]; then break fi done if [[ ! -f d2plug-$KVer-$f ]]; then echo "Unable to retrieve d2plug-$KVer-$f" exit 1 fi fi done Md5Compare d2plug-$KVer-Modules.tar.gz d2plug-$KVer-Modules.tar.gz.md5 Md5Compare d2plug-$KVer-uImage d2plug-$KVer-uImage.md5 } function ExtractModules() { local v1=$(echo $KVer | cut -d'.' -f1) local v2=$(echo $KVer | cut -d'.' -f2) local v3=$(echo $KVer | cut -d'.' -f3) local depmodVer=$KVer [[ ! -z $v3 ]] || depmodVer="$v1.$v2.0" local extractDir='/' [[ ! -L '/lib' ]] || extractDir=$(dirname $(readlink '/lib')) [[ -d $extractDir ]] || extractDir="/$extractDir" echo "Extracting modules" tar x -C $extractDir --overwrite -zf d2plug-$KVer-Modules.tar.gz [[ -d /boot ]] || mkdir /boot cp d2plug-$KVer-System.map /boot/ depmod -eF /boot/d2plug-$KVer-System.map $depmodVer-dove-5.4.2 } function RootKernel() { echo "Writing kernel to /boot" [[ -d /boot ]] || mkdir /boot cp d2plug-$KVer-uImage /boot/ echo "****************************************************************" echo " create a link from /boot/d2plug-$KVer-uImage to /boot/uImage" echo "****************************************************************" } function Usage() { echo "Use $ProgName VERSION to write kernel to /boot" echo echo " where VERSION is something like 2.6.32.55" } if (( $# < 1 )) || [[ $1 == "--help" ]]; then Usage exit 1 fi KVer="$1" Download ExtractModules RootKernel