#!/bin/bash echo "# script PARA USUARIOS DO UBUNTU 11.10 baixa e compila kernel tudo automaticamente CRIADO PELOS USUÁRIOS DO FORUM UBUNTU BR: # http://ubuntuforum-br.org/index.php/topic,29799.3960.html # # # Com ele você compila o kernel, independente da versão (caso ela esteja disponível) # Escolhe os patchs do con kolivas # Adiciona os patchs da equipe do ubuntu # Altera as flags do compilador para melhor performance # ################################################################################################"; # @Todo: # * Verificar a quantidade de patchs do con colivas para aquele kernel existente e exibir ao usuário (verifica se existe patchs como o bfs e pergunta se que usá-lo) # * Verificar por erros durante o compilar() e parar. # * Dar a opção de usar um patch alternativo (passando o link do .patch) # * Perguntar se deseja rodar o make menuconfig # ############# # Funções ############# ###### Úteis ## Validação Sim/não function valida { read opcao if [ "$opcao" == "s" ]; then return 0 else return 1 fi } ###### Sistema ## Função pra ler as configurações, caso exista um arquivo, leia-o e use suas configurações ## Se não existir, coloque algumas opções por padrão. function init { if [[ $EUID -ne 0 ]]; then echo "Este script deve ser executado como root (sudo ./kernelscript.sh)" 1>&2 exit 1 fi #Essa função inicia o sistema, começamos verificando se ele tem o arquivo de configuração, se tiver entendesse que deve prosseguir a configuração if [ -d "config.json" ]; then #Nada implementado ainda #confirmar echo ".." else #Se ela não existe usa essas aí: kernel=3.3 patchkernel=3.3.2 ubuntu_patchs=true ck_patchs=false ck_patchs_bfs=true ck_patchs_dirty=true ck_patchs_1000mhz=true config_file=$(locate /boot/config-* | sort -r | head -1) localmodcofig=true use_cflags=false arquivos=( "arch/x86/boot/compressed/Makefile" "arch/x86/boot/Makefile" "arch/x86/kernel/acpi/realmode/Makefile" "arch/x86/Kconfig.cpu" "arch/x86/Makefile" "arch/x86/Makefile_32.cpu") #arquitetura: amd64 ou i386 arqt=$(dpkg --print-architecture) init_config fi confirmar } #Funções de configuração #Init_config(); function init_config { kernel kernelpatch if check_avancadas then patchs_ubuntu patchs_ck check_config cflags #patch_alternativo fi } #kernel function kernel { #versão do kernel a ser compilado echo "Digite a versão do kernel a ser compilada (Exemplo: 3.3, 3.2, 2.6)" read kernel if ! [[ "$kernel" =~ ^[0-9]+([.][0-9]+)?$ ]] ; then echo "Erro: Versão inválida. Digite apenas pontos e números. Não digite a versão inteira, ao invés de 3.2.3, digite apenas 3.2"; kernel fi } #Kernelpatch function kernelpatch { #patch de atualização echo "Digite o patch de atualização desejado para a versão (Exemplo: $kernel.3, $kernel.4 )" read patchkernel if ! [[ "$patchkernel" =~ $kernel([.][0-9]+)?$ ]] ; then echo "Erro: Versão inválida. Digite apenas pontos e números. A versão do patch deve equivaler a versão do kernel escolhida."; kernelpatch fi } #check_avancadas function check_avancadas { #patch ck echo "Você deseja ver as opções avançadas de configuração? [s/n]" if valida then return 0 else return 1 fi } ##Avançadas #Patchs do ubuntu function patchs_ubuntu { echo "Deseja usar os patchs da equipe do Ubuntu? [s/n]" if valida then ubuntu_patchs=true else ubuntu_patchs=false fi } #ck patchs function patchs_ck { echo "Deseja usar os patchs do Con Kolivas? [s/n]" if valida then ck_patchs=true #config_ck_patchs #Desativado, não fiz ainda as funções que verificam quais #patchs especificos o usuário quer fi } #cflags function cflags { echo "Deseja alterar as flags do C? [s/n]" if valida then use_cflags=true fi } #Arquivo .config function check_config { echo "Escolha o .config que deseja usar" echo "[1] Nenhum" echo "[2] .config existente na pasta /boot" echo "[3] .config do liquorix" echo "[4] Desejo especificar o caminho de um .config" echo "Qual .config você deseja usar? [1-4]:" read opt case $opt in 1) echo 'Nenhum .config será usando' config_file=false ;; 2) echo 'O script irá procurar o .config na pasta /boot' config_file=$(locate /boot/config-* | sort -r | head -1) ;; 3) echo 'O script irá baixar o .config do site do liquorix' config_file="/tmp/kernel-script-config" wget -O $config_file "http://liquorix.net/sources/$kernel/config.$arqt" ;; 4) echo 'Especifique o caminho:' read config_file if ! [ -d $config_file ]; then echo "Opps, não encontrei o .config no caminho especificado" fi check_config ;; *) echo 'Opção inválida' check_config ;; esac echo "Deseja usar localmodconfig? (Use com muito cuidado) [s/n]" if valida then echo 'localmodconfig será usado' localmodcofig=true fi } #function config_ck_patchs { #Essa função acessa a página do kolivas e verifica se ele tem patchs pro #kernel escolhido, lista eles e pergunta quais quer usar #} function confirmar { echo "Você irá compilar o kernel $kernel com o patch $patchkernel" [[ $ubuntu_patchs = true ]] && usepatch="" || usepatch="não " echo "Você $usepatch irá usar os patchs dos desenvolvedores do ubuntu" [[ $ck_patchs = true ]] && usepatch="" || usepatch="não " echo "Você $usepatch usará os patchs do con kolivas" [[ $use_cflags = true ]] && usepatch="" || usepatch="não " echo "Você $usepatch irá alterar as cflags do computador" echo "Você irá usar o seguinte arquivo de configuração: $config_file" [[ $localmodcofig = true ]] && usepatch="" || usepatch="não " echo "Você $usepatch irá usar o localmodconfig" echo "Verifique se os dados estão corretos" echo "Digite [P] - para Prosseguir, [C] - para Corrigir ou [S] - para Sair" read opt case $opt in p|P) compilar ;; c|C) init ;; s|S) exit 1 ;; *) echo "Opção inválida" confirmar esac } function cflags { sed "s/HOSTCFLAGS/HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -0fast -march=native -pipe \n#HOSTCFLAGS/g" Makefile > Makefile2 mv Makefile2 Makefile #Aqui eu faço um loop e altero os arquivos, removendo o -march=() por -march=native for i in "${arquivos[@]}" do echo "Aplicando patch no arquivo:"$i sed -e 's/-march=\([A-Z0-9a-z]\+\)/-march=native -Ofast/g' $i > "$i.file_changed" mv "$i.file_changed" $i done } function compilar { patchck=$kernel-ck1 #sufixo ckk=ck1 apt-get update apt-get install kernel-package gcc-4.6 libncurses5 libncurses5-dev build-essential patch -y case $kernel in 3.0) kernv=v3.0 ;; 2.6) kernv=v2.6 ;; 3.*) kernv=v3.x ;; *) echo 'Erro ao calcular a versão do kernel. Use apenas 2.6+ e 3.0+' exit 1 ;; esac cd /usr/src wget -q -c http://www.kernel.org/pub/linux/kernel/$kernv/linux-$kernel.tar.bz2 if ! [ -f linux-$kernel.tar.bz2 ] ; then echo "Ooops, erro ao baixar o kernel ..." exit 1; fi tar -jxpvf /usr/src/linux-$kernel.tar.bz2 mv /usr/src/linux-$kernel /usr/src/linux-$patchkernel-$ckk wget -q -c http://www.kernel.org/pub/linux/kernel/$kernv/patch-$patchkernel.bz2 if ! [ -f patch-$patchkernel.bz2 ] ; then echo "Ooops, erro ao baixar o patch do kernel ..." exit 1; fi #ubuntu patch `wget -O /tmp/mainline http://kernel.ubuntu.com/~kernel-ppa/mainline/` er="${patchkernel}-[a-z]\+"; v2=$(grep -o -e "$er" /tmp/mainline |head -1); wget -q -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v$v2/0001-base-packaging.patch wget -q -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v$v2/0002-debian-changelog.patch wget -q -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v$v2/0003-default-configs.patch bunzip2 -q /usr/src/patch-$patchkernel.bz2 bunzip2 -q /usr/src/patch-$patchck.bz2 cd /usr/src/linux-$patchkernel-$ckk if $use_cflags then echo 'Alterando cflags' cflags fi patch -p1 < /usr/src/patch-$patchkernel patch -p1 < /usr/src/0001-base-packaging.patch patch -p1 < /usr/src/0002-debian-changelog.patch patch -p1 < /usr/src/0003-default-configs.patch if $ck_patchs then wget -c http://ck.kolivas.org/patches/3.0/$kernel/$patchck/patch-$patchck.bz2 patch -p1 < /usr/src/patch-$patchck fi if $config_file then cp $config_file /usr/src/linux-$patchkernel-$ckk/.config fi if $localmodcofig then chmod +x ./scripts/kconfig/streamline_config.pl && ./scripts/kconfig/streamline_config.pl > config_strip mv config_strip .config fi ######################### #gedit Makefile sleep 3 make menuconfig sed 's/CONFIG_RTS5139=m/# CONFIG_RTS5139 is not set/g' /usr/src/linux-$patchkernel-$ckk/.config > /usr/src/linux-$patchkernel-$ckk/cc mv /usr/src/linux-$patchkernel-$ckk/cc /usr/src/linux-$patchkernel-$ckk/.config ################ sleep 2 make sleep 1 make modules_install install sleep 2 echo 'tudo belezinha' exit 0 } init