#!/bin/bash
###################################################################################
# This work is licensed under a Creative Commons Reconocimiento-NoComercial 3.0 Unported License.
# http://creativecommons.org/licenses/by-nc/3.0/deed.es_ES
# Creado por Paulo Lira Gutiérrez ([email protected])
# Actualizado por lighta ([email protected])
# Se concede permiso para copiar, distribuir y/o modificar este programa siempre
# y cuando se cite al autor y la fuente de http://kernel-netbook.blogspot.com
# y según los términos de la GNU General Public License, Versión 3 o cualquiera
# posterior publicada por la Free Software Foundation.
# Este script construye paquetes .deb del kernel netbook, con ayuda del repositorio de 'dieghen89'.
#Uso:
#Si no desea realizar el paso de descargar el repositorio de Github, deberá de descargarse la configuración del archivo config situado en:
# https://github.com/dieghen89/kernel-netbook/blob/master/config y copiarlo en una nueva carpeta llamada kernel-netbook dentro de la carpeta personal.
#Además, deberá de descargarse el código fuente de la versión del kernel a construir (en una carpeta llamada Programas dentro de la carpeta personal), debe de coincidir con la versión del archivo de configuración (.config).
YELLOW="\033[1;33m"
ENDCOLOR="\033[0m"
RED="\033[0;31m"
if [ $USER != root ]; then
echo -e $RED"Error: debes ser root"
echo -e $YELLOW"Saliendo..."$ENDCOLOR
exit 0
fi
echo -e $YELLOW"Comprobando conexión a Internet..."$ENDCOLOR
ping www.google.com -c 3 >/dev/null 2>&1
if [ $? = 0 ]; then
echo -e $YELLOW"Si hay conexión a internet"$ENDCOLOR
else
echo -e $RED"No se ha podido establecer una conexión a internet"$ENDCOLOR
exit
fi
echo -e $YELLOW"Actualizando repositorio de kernel-netbook"$ENDCOLOR
if [ -d $HOME/kernel-netbook ]; then
cd ~/kernel-netbook
git pull https://github.com/dieghen89/kernel-netbook.git
else
echo -e $YELLOW"\tDebug, Creando directorio kernel-netbook"$ENDCOLOR
git clone https://github.com/dieghen89/kernel-netbook.git $HOME/kernel-netbook
cd $HOME/kernel-netbook
fi
sleep 5
VERSION_CONFIG=$(cat $HOME/kernel-netbook/config | head -3 |tail -1 | grep -o '[0123456789.]*' | head -3 |tail -1)
echo -e $YELLOW"La versión del archivo de configuración kernel-netbook/config es la $VERSION_CONFIG"$ENDCOLOR
sleep 4
if [ ! -d $HOME/Programas ]; then
echo -e $YELLOW"\tDebug, Creando directorio Programas"$ENDCOLOR
mkdir $HOME/Programas;
# En esta carpeta deberán existir las fuentes del kernel que se quieren construir.
fi
cd ~/Programas
#VERSION=$(w3m -dump http://kernel.org/kdist/finger_banner | head -2 |tail -1 | awk '{ print $11 }')
VERSION=$(w3m -dump http://kernel.org/kdist/finger_banner | grep 'The latest stable '[0123456789.]*'' | head -1 | awk '{ print $11 }')
LINUX_VERSION_TAR=linux-$VERSION.tar.bz2
LINUX_VERSION=linux-$VERSION
VERSION_CONFIG=$(cat $HOME/kernel-netbook/config | head -3 |tail -1 | grep -o '[0123456789.]*' | head -3 |tail -1)
VERSION_LISTADO=$(ls *.tar.bz2 | grep -o '[0123456789.]*'| head -1 | sed 's/.$//g')
LISTAR=$(ls *.tar.bz2)
if [ $VERSION_CONFIG = $VERSION_LISTADO ]; then
echo -e $YELLOW"Instalando dependencias..."$ENDCOLOR
sudo apt-get install git w3m zenity build-essential gcc libncurses5-dev
sleep 3
sudo cp ~/Programas/$LISTAR /usr/src/$LISTAR
cd /usr/src
echo -e $YELLOW"Listando archivos .tar.bz2 en Programas..."$ENDCOLOR
echo $LISTAR
if [ $? = 0 ]; then
echo -e "Se encontraron las fuentes del kernel"
else
echo -e $RED"No se encotraron las fuentes del kernel"$ENDCOLOR
exit
fi
sleep 1
echo -e $YELLOW"Limpiando directorio /usr/src/linux-$VERSION_LISTADO"$ENDCOLOR
sudo rm -rf /usr/src/linux-$VERSION_LISTADO
echo -e $YELLOW"Descomprimiendo el código fuente en /usr/src/linux-$VERSION_LISTADO..."$ENDCOLOR
sleep 2
sudo tar -xjvf $LISTAR
echo -e $YELLOW"Borrando archivo $LISTAR..."$ENDCOLOR
sudo rm $LISTAR
sleep 2
echo -e $YELLOW"Creando enlace simbólico hacia carpeta linux-$VERSION_LISTADO..."$ENDCOLOR
sudo rm -rf linux
sudo ln -s linux-$VERSION_LISTADO linux
sleep 2
cd /usr/src/linux
################################################################################################
# PARCHES #
# ALGUNAS PARTES TOMADAS DEL PKGBUILD DE DIEGUEN89
#https://github.com/dieghen89/kernel-netbook/blob/master/PKGBUILD
TUX_ON_ICE="n"
BROADCOM_WL="n"
UKSM="y"
LOCALMODCONFIG="n"
GCONFIG="n"
INSTALL="n"
### HOW-TO:
#
## >> Details for: TUX_ON_ICE
# Set it to "n" you you don't want the Tux On Ice support
#
## >> Details for: BROADCOM_WL
# Set is to "y" if you need the iw module for your wireless card
#
#
# P.S. this pkgbuild supports the graysky's modprobe_db package
#
#
## >> Details for: UKSM
# Set it to "y" to enable the testing uKSM patch, more info here:
# http://kerneldedup.org
#
## >> The previous BFQ_IO_SCHEDULER is useless, read the wiki page in google code
#
##########
DIR_FUENTE=/usr/src/linux
_basekernel=3.9
pkgver=${_basekernel}.2
pkgrel=1
#Broadcom-wl:
broadcom_ver=5.100.82.112
broadcom="hybrid-portsrc_x86_32-v${broadcom_ver//./_}"
#BFS: - http://users.on.net/~ckolivas/kernel/ -
_ckpatchversion=1
_ckpatchname="patch-${_basekernel}-ck${_ckpatchversion}"
#BFQ: - http://algo.ing.unimo.it/people/paolo/disk_sched/ -
_bfqpath="http://www.algogroup.unimo.it/people/paolo/disk_sched/patches/3.9.0-v6r1"
#TuxOnIce:
#New official patch
#_toipatch="tuxonice-for-linux-3.8.0-2013-02-24.patch"
_toipatch="$HOME/kernel-netbook/toi-3.9.patch"
#uKSM:
_uksm="http://kerneldedup.org/download/uksm/0.1.2.2"
_uksm_name="uksm-0.1.2.2-for-v3.9.ge.1"
echo -e $YELLOW"Descargando parche BFS..."$ENDCOLOR
wget http://ck.kolivas.org/patches/3.0/3.9/${_basekernel}-ck${_ckpatchversion}/${_ckpatchname}.bz2
echo -e $YELLOW"Descargando parche uKSM..."$ENDCOLOR
wget ${_uksm}/${_uksm_name}.patch
echo -e $YELLOW"Descargando parche BFQ..."$ENDCOLOR
wget "${_bfqpath}/0001-block-cgroups-kconfig-build-bits-for-BFQ-v6r1-3.9.patch"
wget "${_bfqpath}/0002-block-introduce-the-BFQ-v6r1-I-O-sched-for-3.9.patch"
wget "${_bfqpath}/0003-block-bfq-add-Early-Queue-Merge-EQM-to-BFQ-v6r1-for-3.9.0.patch"
echo -e $YELLOW"Descargando parche Broadcom..."$ENDCOLOR
wget http://www.broadcom.com/docs/linux_sta/${broadcom}.tar.gz
cp $_toipatch $DIR_FUENTE
cp $HOME/kernel-netbook/linux-recent.patch linux-recent.patch
cp $HOME/kernel-netbook/license.patch license.patch
cp $HOME/kernel-netbook/user-ioctl.patch user-ioctl.patch
echo -e $YELLOW"Según su configuración,se aplicarán los parches BFS, BFQ, uKSM y TuxOnIce"$ENDCOLOR
# --> BFS
#Adjust localversion
bzip2 -d patch-3.9-ck1.bz2
sed -i -e "s/-ck${_ckpatchversion}//g" $DIR_FUENTE/${_ckpatchname}
patch -Np1 -i $DIR_FUENTE/patch-3.9-ck1
if [ $? = 0 ]; then
if [ $TUX_ON_ICE = "y" ] ; then
# --> TOI
patch -Np1 -i ${_toipatch}
if [ $? = 0 ]; then
# --> BFQ
for patch in $(ls $DIR_FUENTE/000*BFQ*.patch) ; do
patch -Np1 -i $patch
done
if [ $? = 0 ]; then
# --> uKSM
if [ $UKSM = "y" ] ; then
patch -Np1 -i $DIR_FUENTE/${_uksm_name}.patch
fi
fi
fi
fi
else
zenity --error --text="Hubo un error al aplicar los parches"
exit
fi
##Section: Broadcom-wl
if [ "${BROADCOM_WL}" == "y" ] ; then
zenity --info --text="Compilando módulo Broadcom"
cp -ar src/wl src/wl_orig
patch -p1 -N -i linux-recent.patch
patch -p1 -N -i license.patch
patch -p1 -N -i user-ioctl.patch
make -C $DIR_FUENTE/linux-$_basekernel M=`pwd`
install -D -m 755 wl.ko ${pkgdir}/lib/modules/${_extramodules}/wl.ko
rm -r src/wl
mv src/wl_orig src/wl
fi
echo -e $YELLOW"Limpiando el árbol del directorio fuente..."$ENDCOLOR
sudo make mrproper
# FIN DE PARCHES #
################################################################################################
echo -e $YELLOW"Copiando fichero kernel-netbook/config como .config"$ENDCOLOR
sudo cp $HOME/kernel-netbook/config /usr/src/linux/.config
sleep 6
if [ $GCONFIG = "y" ] ; then
echo -e $YELLOW"Iniciando gconfig"$ENDCOLOR
sudo make gconfig
fi
echo -e $YELLOW"Limpiando el kernel..."$ENDCOLOR
sleep 3
sudo make-kpkg clean
if [ ! $? = 0 ]; then
echo -e $RED"Hubo un error al limpiar el kernel"$ENDCOLOR
zenity --error --text="Hubo un error al limpiar el kernel"
exit
fi
sleep 3
if [ $LOCALMODCONFIG = "y" ] ; then
echo -e $YELLOW"Se están incluyendo los módulos que estén corriendo en este momento"$ENDCOLOR
sleep 3
zenity --warning --text="Por favor conecte los periféricos necesarios"
sleep 10
sudo make localmodconfig
echo -e $YELLOW"Ahora puede desconectar los periféricos, se han añadido los módulos necesarios al archivo de configuración"$ENDCOLOR
sleep 3
fi
echo -e $YELLOW"Asegúrese que se haya añadido el archivo .config"$ENDCOLOR
cat /usr/src/linux/.config | grep CONFIG_MATOM
sleep 3
echo -e $YELLOW"Copiando fichero .config a Ubuntu One"$ENDCOLOR
sudo cp /usr/src/linux/.config $HOME/"Ubuntu One"/kernel-netbook/kernel-netbook-$VERSION_LISTADO
echo -e $YELLOW"Compilando el kernel..."$ENDCOLOR
rm ~/Programas/linux*.deb
sudo make-kpkg -j2 --initrd linux_headers linux_image
if [ ! $? = 0 ]; then
echo -e $RED"Hubo un error al construir el kernel, saliendo..."$ENDCOLOR
zenity --error --text="Hubo un error al construir el kernel"
exit 0
fi
sleep 3
zenity --info --title="kernel-netbook-$VERSION_LISTADO" --text="Se construyó existosamente el kernel-netbook"
FILENAME=$(ls linux-image-$VERSION-netbook_${VERSION}_i386.deb)
if [ ! -e $FILENAME ]; then
echo -e $RED"linux-image-$VERSION-netbook_${VERSION}_i386.deb no encontrado, saliendo..."$ENDCOLOR
exit 0
fi
FILENAME=$(ls linux-headers-$VERSION-netbook_${VERSION}_i386.deb)
if [ ! -e $FILENAME ]; then
echo -e $RED"linux-headers-$VERSION-netbook_${VERSION}_i386.deb no encontrado, saliendo..."$ENDCOLOR
exit 0
fi
echo -e $YELLOW"Cambiando propietario..."$ENDCOLOR
USUARIO=$(echo ${HOME:6})
sudo chown $USUARIO $HOME/Programas/linux*.deb
echo -e $YELLOW"Moviendo archivos .deb a Programas"$ENDCOLOR
sudo mv /usr/src/linux*.deb $HOME/Programas
cd $HOME/Programas
sleep 5
#######################CAMBIO DE LA DESCRIPCIÓN DE LOS PAQUETES LINUX-IMAGE####################
mkdir linux-image-"$VERSION_CONFIG"-netbook_"$VERSION_CONFIG"_i386
dpkg -x linux-image-"$VERSION_CONFIG"-netbook_"$VERSION_CONFIG"_i386.deb linux-image-"$VERSION_CONFIG"-netbook_"$VERSION_CONFIG"_i386
dpkg -e linux-image-"$VERSION_CONFIG"-netbook_"$VERSION_CONFIG"_i386.deb linux-image-"$VERSION_CONFIG"-netbook_"$VERSION_CONFIG"_i386/DEBIAN
cd linux-image-"$VERSION_CONFIG"-netbook_"$VERSION_CONFIG"_i386/DEBIAN
sed '17,26d' control > $$.tmp && mv $$.tmp control
sleep 2
sed "12a Homepage: code.google.com/p/kernel-netbook" control > $$.tmp && mv $$.tmp control
echo -e " Static kernel for netbooks with Intel Atom N270/N280/N450/N550/N570 such as eeepc with the add-on of external firmware (broadcom-wl) and patchset (BFS + TOI + BFQ optional) - Only Intel GPU - Give more power to your netbook!.\n ." >> control
echo -e $YELLOW"Construyendo paquete modificado del archivo de control de linux-image"$ENDCOLOR
cd $HOME/Programas
fakeroot dpkg -b linux-image-"$VERSION_CONFIG"-netbook_"$VERSION_CONFIG"_i386
sleep 3
#######################CAMBIO DE LA DESCRIPCIÓN DE LOS PAQUETES LINUX-HEADERS####################
mkdir linux-headers-"$VERSION_CONFIG"-netbook_"$VERSION_CONFIG"_i386
dpkg -x linux-headers-"$VERSION_CONFIG"-netbook_"$VERSION_CONFIG"_i386.deb linux-headers-"$VERSION_CONFIG"-netbook_"$VERSION_CONFIG"_i386
dpkg -e linux-headers-"$VERSION_CONFIG"-netbook_"$VERSION_CONFIG"_i386.deb linux-headers-"$VERSION_CONFIG"-netbook_"$VERSION_CONFIG"_i386/DEBIAN
cd linux-headers-"$VERSION_CONFIG"-netbook_"$VERSION_CONFIG"_i386/DEBIAN
sed '16,21d' control > $$.tmp && mv $$.tmp control
sleep 2
sed "12a Homepage: code.google.com/p/kernel-netbook" control > $$.tmp && mv $$.tmp control
echo -e " Static kernel for netbooks with Intel Atom N270/N280/N450/N550/N570 such as eeepc with the add-on of external firmware (broadcom-wl) and patchset (BFS + TOI + BFQ optional) - Only Intel GPU - Give more power to your netbook!.\n ." >> control
echo -e $YELLOW"Construyendo paquete modificado del archivo de control de linux-headers"$ENDCOLOR
cd $HOME/Programas
fakeroot dpkg -b linux-headers-"$VERSION_CONFIG"-netbook_"$VERSION_CONFIG"_i386
sleep 3
##########################################################################################################
echo -e $YELLOW"Eliminando archivos innecesarios.."$ENDCOLOR
sudo rm -rf linux-image-"$VERSION_CONFIG"-netbook_"$VERSION_CONFIG"_i386
sudo rm -rf linux-headers-"$VERSION_CONFIG"-netbook_"$VERSION_CONFIG"_i386
sudo rm control *.tmp
if [ $INSTALL = "y" ] ; then
echo -e $YELLOW"Instalando linux-image y linux_headers..."$ENDCOLOR
sudo dpkg -i linux-image-$VERSION_CONFIG-netbook_"$VERSION_CONFIG"_i386.deb linux-headers-$VERSION_CONFIG-netbook_"$VERSION_CONFIG"_i386.deb
fi
echo -e $YELLOW"Subiendo linux-image y linux-headers a 4shared..."$ENDCOLOR
cadaver --rcfile=$HOME/.4shared-kernel
sleep 5
sudo rm -rf /usr/src/linux-$VERSION_LISTADO
sleep 3
else
echo -e $RED"Las versiones difieren..."$ENDCOLOR
sleep 5
echo -e $YELLOW"Saliendo..."$ENDCOLOR
exit 0
fi