Got an iPhone or iPad? We have a brand new Pastebin App for both devices, and it's totally free! Click here to download the new Pastebin App for iOS.
Guest

Anderson H D

By: a guest on Jan 13th, 2010  |  syntax: Bash  |  size: 2.33 KB  |  hits: 217  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. #! /bin/bash
  2. #Script para alterar a imagem de fundo do GRUB aleatóriamente a cada boot
  3.  
  4. DIR="" #caminho do diretório contendo as imagens de origem. Altere de acordo com suas necessidades. Preferencialmente use o caminho absoluto
  5.  
  6. ## grande POG para determinar qual o programa usado para invocar poderes de ROOT
  7. TIAKE_NORIS="gksu"
  8. if [ -z "`which gksu`" ]
  9. then
  10.         if [ -z "`which kdesu`" ]
  11.         then
  12.                 TIAKE_NORIS="sudo"
  13.         else
  14.                 TIAKE_NORIS="kdesu"
  15.         fi
  16. fi     
  17.  
  18.        
  19. [ -e $HOME/.gbg-changer ] || mkdir "$HOME/.gbg-changer" #cria o diretório de trabalho na home do usuário, se não existir
  20. [ -e /boot/grub/splashimages ] || $TIAKE_NORIS mkdir /boot/grub/splashimages #gambiarra para que quem não tem o pacote "grub-splashimages" possa usar este script também
  21. [ -w /boot/grub/splashimages ] || $TIAKE_NORIS chmod 777 /boot/grub/splashimages #dá permissão de gravar no diretório splashimages caso isso não seja permitido
  22.  
  23.  
  24. [ -z "`cat /boot/grub/menu.lst | grep /boot/grub/splashimages/gbg-changer.xpm.gz`" ] && xmessage -center -title 'gbg-changer' 'Por favor, adicione manualmente a entrada ao arquivo "/boot/grub/menu.lst"
  25. para usar como splash o arquivo "/boot/grub/splashimages/gbg-changer.xpm.gz"
  26.  
  27. Ela sera algo como:
  28.  
  29.     splashimage=(hdX,Y)/boot/grub/splashimages/gbg-changer.xpm.gz
  30.  
  31. onde X e Y variam de acordo com a disposicao das particoes do sistema.'
  32.  
  33.  
  34. function fillList()
  35. {
  36.   ls -B1 $DIR > $HOME/.gbg-changer/list
  37.   cat -n $HOME/.gbg-changer/list > $HOME/.gbg-changer/indexedList
  38. }
  39.  
  40. function getLimit()
  41. {
  42.   LIMIT=`wc -l "$HOME/.gbg-changer/list"`
  43.   LIMIT=${LIMIT%$HOME/.gbg-changer/list}
  44. }
  45.  
  46. function choose()
  47. {
  48.   CHOSEN=$RANDOM
  49.   let "CHOSEN %= $LIMIT"
  50.   CHOSEN=$(($CHOSEN+1))
  51. }
  52.  
  53. function getFile()
  54. {
  55.   FILE=`cat $HOME/.gbg-changer/indexedList | grep -w "  $CHOSEN"`
  56.   FILE="$DIR/${FILE#*"$CHOSEN   "}"
  57. }
  58.  
  59. function checkPrevious()
  60. {
  61.   PREVIOUS=`cat $HOME/.gbg-changer/previous`
  62.   if [ "$PREVIOUS" != "$FILE" ]
  63.   then
  64.     setBg
  65.   else
  66.     choose
  67.     getFile
  68.     checkPrevious
  69.   fi
  70.   echo "$FILE" > $HOME/.gbg-changer/previous
  71. }
  72.  
  73. function setBg()
  74. {
  75.   convert "$FILE" -resize 640x480! -colors 14 /tmp/gbg-changer.xpm
  76.   gzip -c /tmp/gbg-changer.xpm > /boot/grub/splashimages/gbg-changer.xpm.gz
  77.   echo "File ${FILE#$DIR'/'} foi definido como plano de fundo do GRUB!"
  78. }
  79.  
  80. fillList
  81. getLimit
  82. choose
  83. getFile
  84. checkPrevious