Advertisement
Guest User

Untitled

a guest
Apr 19th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 10.63 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. echo "# script PARA USUARIOS DO UBUNTU 11.10 baixa e compila kernel tudo automaticamente CRIADO PELOS USUÁRIOS DO FORUM UBUNTU BR:
  4. # http://ubuntuforum-br.org/index.php/topic,29799.3960.html
  5. #
  6. #
  7. # Com ele você compila o kernel, independente da versão (caso ela esteja disponível)
  8. # Escolhe os patchs do con kolivas
  9. # Adiciona os patchs da equipe do ubuntu
  10. # Altera as flags do compilador para melhor performance
  11. #
  12. ################################################################################################";
  13.  
  14.  
  15. # @Todo:
  16. #   * Verificar a existencia do arquivo de configuração do compilador e carregar as opções
  17. #   * Se ele não configurou alguma opção no arquivo de configuração, mostre um erro ou peça para ele configurar
  18. #       * 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)
  19. #       * Dar a opção de usar um patch alternativo (passando o link do .patch)
  20. #       * Perguntar se deseja rodar o make menuconfig
  21. #       * Fazer a função compilar
  22. #            Ela verifica todas as opções do script, baixa o kernel,
  23. #               aplica os patchs, .config, roda menuconfig
  24. #
  25.  
  26.  
  27. #############
  28. # Funções
  29. #############
  30.  
  31. ###### Úteis
  32. ## Validação Sim/não
  33. function valida {
  34.     read opcao
  35.     if [ "$opcao" == "s" ]; then
  36.         return 0
  37.     else
  38.         return 1
  39.     fi
  40. }
  41.  
  42. ###### Sistema
  43. ## Função pra ler as configurações, caso exista um arquivo, leia-o e use suas configurações
  44. ## Se não existir, coloque algumas opções por padrão.
  45.  
  46. function init {
  47.     #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
  48.     if [ -d "config.json" ]; then
  49.         #Nada implementado ainda
  50.                 #confirmar
  51.                 echo ".."
  52.     else
  53.         #Se ela não existe usa essas aí:
  54.         kernel=3.3
  55.         patchkernel=3.3.2
  56.         ubuntu_patchs=true
  57.         ck_patchs=false
  58.         ck_patchs_bfs=true
  59.         ck_patchs_dirty=true
  60.         ck_patchs_1000mhz=true
  61.         config_file=$(locate /boot/config-* | sort -r | head -1)
  62.                 localmodcofig=true
  63.         #arquitetura: amd64 ou i386
  64.         arqt=$(dpkg --print-architecture)
  65.                 init_config
  66.     fi
  67.         confirmar
  68. }
  69.  
  70. #Funções de configuração
  71. #Init_config();
  72.  
  73. function init_config {
  74.     kernel
  75.     kernelpatch
  76.     if check_avancadas
  77.     then
  78.         patchs_ubuntu
  79.         patchs_ck
  80.         check_config
  81.         cflags
  82.         #patch_alternativo
  83.     fi
  84. }
  85.  
  86. #kernel
  87. function kernel {
  88.     #versão do kernel a ser compilado
  89.     echo "Digite a versão do kernel a ser compilada (Exemplo: 3.3, 3.2, 2.6)"
  90.     read kernel
  91.     if ! [[ "$kernel" =~ ^[0-9]+([.][0-9]+)?$ ]] ;  then
  92.        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";
  93.        kernel
  94.     fi
  95. }
  96.  
  97. #Kernelpatch
  98. function kernelpatch {
  99.     #patch de atualização
  100.     echo "Digite o patch de atualização desejado para a versão (Exemplo: $kernel.3, $kernel.4 )"
  101.     read patchkernel
  102.     if ! [[ "$patchkernel" =~ $kernel([.][0-9]+)?$ ]] ;  then
  103.        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.";
  104.        kernelpatch
  105.     fi
  106. }
  107.  
  108. #check_avancadas
  109. function check_avancadas {
  110.     #patch ck
  111.     echo "Você deseja ver as opções avançadas de configuração? [s/n]"
  112.     if valida
  113.     then
  114.         return 0
  115.     else
  116.         return 1
  117.     fi
  118. }
  119.  
  120. ##Avançadas
  121. #Patchs do ubuntu
  122. function patchs_ubuntu {
  123.     echo "Deseja usar os patchs da equipe do Ubuntu? [s/n]"
  124.     if valida
  125.     then
  126.         ubuntu_patchs=true
  127.     else
  128.         ubuntu_patchs=false
  129.     fi
  130. }
  131.  
  132. #ck patchs
  133. function patchs_ck {
  134.     echo "Deseja usar os patchs do Con Kolivas? [s/n]"
  135.     if valida
  136.     then
  137.         ck_patchs=true
  138.         #config_ck_patchs
  139.                 #Desativado, não fiz ainda as funções que verificam quais
  140.                     #patchs especificos o usuário quer
  141.     fi
  142. }
  143.  
  144. #cflags
  145. function cflags {
  146.     echo "Deseja alterar as flags do C? [s/n]"
  147.     if valida
  148.     then
  149.         cflags=true
  150.     fi 
  151. }
  152.  
  153. #Arquivo .config
  154. function check_config {
  155.         echo "Escolha o .config que deseja usar"
  156.     echo "[1] Nenhum"
  157.     echo "[2] .config existente na pasta /boot"
  158.     echo "[3] .config do liquorix"
  159.     echo "[4] Desejo especificar o caminho de um .config"
  160.     echo "Qual .config você deseja usar? [1-4]:"
  161.     read opt
  162.     case $opt in
  163.     1)
  164.         echo 'Nenhum .config será usando'
  165.         config_file=false
  166.         ;;
  167.     2)
  168.         echo 'O script irá procurar o .config na pasta /boot'
  169.             config_file=$(locate /boot/config-* | sort -r | head -1)
  170.         ;;
  171.     3)
  172.         echo 'O script irá baixar o .config do site do liquorix'
  173.         config_file="/tmp/kernel-script-config"
  174.         wget -O $config_file "http://liquorix.net/sources/$kernel/config.$arqt"
  175.         ;;
  176.     4)
  177.         echo 'Especifique o caminho:'
  178.         read config_file
  179.         if ! [ -d $config_file ]; then
  180.             echo "Opps, não encontrei o .config no caminho especificado"
  181.         fi
  182.         check_config
  183.         ;;
  184.     *)
  185.         echo 'Opção inválida'
  186.         check_config
  187.         ;;
  188.     esac
  189.         echo "Deseja usar localmodconfig? (Use com muito cuidado) [s/n]"
  190.         if valida
  191.         then
  192.         echo 'localmodconfig será usado'
  193.         localmodcofig=true
  194.         fi
  195. }
  196.  
  197. #function config_ck_patchs {
  198.     #Essa função acessa a página do kolivas e verifica se ele tem patchs pro
  199.     #kernel escolhido, lista eles e pergunta quais quer usar
  200. #}
  201.  
  202. function confirmar {
  203.     echo "Você irá compilar o kernel  $kernel com o patch $kernelpatch"
  204.     [[ $ubuntu_patchs = true ]] && usepatch="" || usepatch="não "
  205.     echo "Você $usepatchirá usar os patchs dos desenvolvedores do ubuntu"
  206.     [[ $ck_patchs = true ]] && usepatch="" || usepatch="não "
  207.     echo "Você $usepatchusará os patchs do con kolivas"
  208.     [[ $cflags = true ]] && usepatch="" || usepatch="não "
  209.     echo "Você $usepatchirá alterar as cflags do computador"
  210.     echo "Você irá usar o seguinte arquivo de configuração: $config_file"
  211.     [[ $localmodcofig = true ]] && usepatch="" || usepatch="não "
  212.     echo "Você $usepatchirá usar o localmodconfig"
  213.     echo "Verifique se os dados estão corretos"
  214.     echo "Digite [P para Prosseguir, C para Corrigir ou S para Sair"
  215.     read opt
  216.     case $opt in
  217.         p)
  218.             compilar
  219.             ;;
  220.         c)
  221.             init
  222.             ;;
  223.         s)
  224.             exit 1
  225.             ;;
  226.         *)
  227.             echo "Opção inválida"
  228.             confirmar
  229.     esac
  230. }
  231. init
  232. exit 0
  233.  
  234. patchck=$kernel-ck1
  235.  
  236. #sufixo
  237. ckk=ck1
  238.  
  239.  
  240. #.config antigo
  241. kernelantigo=atual
  242.  
  243. ############################################
  244.  
  245. # não precisa mexer em mais nada aqui
  246.  
  247. #CL=CONCURRENCY_LEVEL do processador
  248. CL=$(grep -c processor /proc/cpuinfo)
  249. ##################################
  250.  
  251. sudo apt-get update
  252. sudo apt-get install kernel-package gcc-4.6 libncurses5 libncurses5-dev build-essential patch -y
  253.  
  254.  
  255. cd /usr/src
  256. wget -c http://www.kernel.org/pub/linux/kernel/v3.x/linux-$kernel.tar.bz2
  257.  
  258.  
  259. sudo tar -jxpvf /usr/src/linux-$kernel.tar.bz2
  260. sudo mv /usr/src/linux-$kernel /usr/src/linux-$patchkernel-$ckk
  261.  
  262.  
  263. wget -c http://www.kernel.org/pub/linux/kernel/v3.x/patch-$patchkernel.bz2
  264. wget -c http://ck.kolivas.org/patches/3.0/$kernel/$patchck/patch-$patchck.bz2
  265.  
  266. #ubuntu patch
  267. wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.3.2-precise/0001-base-packaging.patch
  268. wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.3.2-precise/0002-debian-changelog.patch
  269. wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.3.2-precise/0003-default-configs.patch
  270.  
  271.  
  272.  
  273. sudo bunzip2 /usr/src/patch-$patchkernel.bz2
  274. sudo bunzip2 /usr/src/patch-$patchck.bz2
  275.  
  276.  
  277. cd /usr/src/linux-$patchkernel-$ckk
  278.  
  279. sudo patch -p1 < /usr/src/patch-$patchkernel
  280. sudo patch -p1 < /usr/src/patch-$patchck
  281. sudo patch -p1 < /usr/src/0001-base-packaging.patch
  282. sudo patch -p1 < /usr/src/0002-debian-changelog.patch
  283. sudo patch -p1 < /usr/src/0003-default-configs.patch
  284.  
  285.  
  286. ######################
  287. #sudo cp /boot/config-$kernelantigo /usr/src/linux-$patchkernel-$ckk/.config
  288.  
  289. sudo cp $config_file /usr/src/linux-$patchkernel-$ckk
  290.  
  291. #########################
  292.  
  293. #sudo gedit Makefile  
  294.  
  295. sleep 3
  296.  
  297. sudo make menuconfig
  298.  
  299. sudo 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
  300.  
  301. sleep 3
  302.  
  303. ############ script do grande Stivekx #######################
  304.  
  305. #!/bin/bash
  306.  
  307. #Script para automatizar a mudança das flags na hora de compilar o kernel.
  308. #Mais informações sobre como compilar o kernel para seu processador:
  309. #http://ubuntuforum-br.org/index.php/topic,81718.0.html
  310.  
  311. #Modo de usar:
  312. #Após baixar o kernel, descompactar, criar um link simbólico para ele no /usr/src/linux:
  313. # cd /usr/src/linux
  314. # sudo su
  315. # chmod +x script.sh
  316. # ./script.sh
  317. #O script deve ser executado como root. Recomendo que use sudo su - e rode o script ao invés de sudo sh script.sh
  318.  
  319.  
  320. #Script criado por André Steinn
  321.  
  322. #Aqui é a lista de arquivos que ele vai dar replace no -march= por -march=native. Você pode mudar essa lista de arquivos passando a lista pela opção a e separados pro virgula
  323. #e.g.: ./script.sh -a arch/x86/boot/compressed/Makefile,arch/x86/boot/Makefile,arquivo1,arquivo2,arquivo3
  324.  
  325. 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")
  326.  
  327. #Aqui eu verifico se a pessoa passou algum argumento na hora de executar o script
  328. while getopts ":a:c" opt; do
  329.   case $opt in
  330.     a)
  331.       echo "Você setou uma lista de arquivos personalizada: $OPTARG" >&2
  332.     IFS=',' read -ra arquivos <<< "$OPTARG"
  333.       ;;
  334.     \?)
  335.       echo "Opção inválida: -$OPTARG" >&2
  336.       exit 1
  337.       ;;
  338.   esac
  339. done
  340.  
  341. #Aqui eu faço um loop e altero os arquivos, removendo o -march=() por -march=native
  342. for i in "${arquivos[@]}"
  343. do
  344.     echo "Aplicando patch no arquivo:"$i
  345.     sed -e 's/-march=\([A-Z0-9a-z]\+\)/-march=native -Ofast/g'  $i > "$i.file_changed"
  346.     mv "$i.file_changed" $i
  347. done
  348.  
  349.  
  350.  
  351. ################
  352.  
  353. sleep 3
  354.  
  355.  
  356. #time sudo CONCURRENCY_LEVEL=2 make-kpkg --initrd kernel_image kernel_headers modules_image
  357.  
  358. time sudo CONCURRENCY_LEVEL=$CL make-kpkg --initrd kernel_image kernel_headers modules_image
  359.  
  360.  
  361. cd /usr/src
  362. sudo dpkg -i linux-image-$patchkernel-$ckk\_$patchkernel-$ckk-10.00.Custom_$arqt.deb linux-headers-$patchkernel-$ckk\_$patchkernel-$ckk-10.00.Custom_$arqt.deb
  363.  
  364. sleep 3
  365.  
  366. cd /lib/modules
  367. sudo mkinitramfs -o /boot/initrd.img-$patchkernel-$ckk $patchkernel-$ckk
  368. sudo update-grub
  369.  
  370. sleep 5
  371. echo 'tudo belezinha'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement