você está aqui: Home  → Arquivo de Mensagens

updatoo

Colaboração: Ricardo Iramar dos Santos

Data de Publicação: 25 de December de 2008

Para quem está cansado de executar os mesmos comandos para atualizar o gentoo, este script automatiza o processo e não para de instalar os demais pacotes caso algum falhe.

  #!/bin/bash
  #
  # updatoo
  # Agent Smith (Ricardo Iramar dos Santos)
  # ricardo.iramar@gmail.com
  #
  # updatoo is a bash script that performing a simple full update in a Gentoo System.
  # You can run updatoo in two ways:
  # 1. Without parameter (default) that it will ask you for confirmation in every step.
  # 2. With --force (-f) that it won't ask you for anything.
  # Basically updatoo will synchronize your portage tree with eix-sync, create a pretend list of packages and install them.
  # If occur a problem the updatoo is aborted with code 1.
  # Everything is loged in /root/.updatoo/ where you can check anytime.
  # Please report any bug to ricardo.iramar@gmail.com or http://forums.gentoo.org/viewtopic-t-717092.html.
  #
  # ChangeLog
  # Version 0.1 (29/11/2008)
  # - First version. No bugs yet.
  #
  # Version 0.2 (07/12/2008)
  # - Gentoo look output (/etc/init.d/functions.sh").
  # - Some code fix.
  #
  # ToDo
  # - Detect masked packages.
  # - Test mode (do nothing, just create the lists).
  # - E-mail notification.
  #
  
  < A NAME="note# Begin Declare Variables " HREF="#textnote# Begin Declare Variables ">< SUP># Begin Declare Variables #
  StrVersion="v0.2"
  StrForce="no"
  StrHomeDir="$HOME/.updatoo"
  StrWorkDir="$StrHomeDir/`date +%F`"
  StrAnswer=""
  StrLine=""
  StrPackage=""
  NumPackages="0"
  NumPackage="1"
  StrFuncFile="/etc/init.d/functions.sh"
  < A NAME="note# End Declare Variables " HREF="#textnote# End Declare Variables ">< SUP># End Declare Variables #
  
  < A NAME="note# Begin SubHelp " HREF="#textnote# Begin SubHelp ">< SUP># Begin SubHelp #
  SubHelp()
  {
        echo "updatoo $StrVersion
  updatoo --help | --force
  --help (-h)    Print this help.
  --force (-f)   Don't ask me anything."
  }
  < A NAME="note# End SubHelp " HREF="#textnote# End SubHelp ">< SUP># End SubHelp #
  
  < A NAME="note# Begin SubAbort " HREF="#textnote# Begin SubAbort ">< SUP># Begin SubAbort #
  SubAbort()
  {
        eend "Aborted"
        exit 1
  }
  < A NAME="note# End SubAbort " HREF="#textnote# End SubAbort ">< SUP># End SubAbort #
  
  < A NAME="note# Begin Script " HREF="#textnote# Begin Script ">< SUP># Begin Script #
  source "$StrFuncFile"
  if [ ! -d "$StrHomeDir" ]; then mkdir "$StrHomeDir"; fi
  if [ ! -d "$StrWorkDir" ]; then mkdir "$StrWorkDir"; fi
  if [ "$USER" != "root" ]
  then
        ewarn "You need to be root to run updatoo."
        SubAbort
  elif [ ! -f "/usr/bin/eix" ]
  then
        ewarn "Please install eix first (emerge eix)."
        SubAbort
  elif [ ! -f "/usr/bin/revdep-rebuild" ]
  then
        ewarn "Please install gentoolkit first (emerge gentoolkit)."
        SubAbort
  fi
  
  if [[ "$@" =~ ^-(f|-force)$ ]]
  then
        ebegin "Starting in force mode"
        StrForce="yes"
  fi
  
  if [[ "$@" =~ ^-(h|-help)$ ]]
  then
        SubHelp
        exit 0
  elif [[ "$@" =~ ^(-(f|-force))?$ ]]
  then
        if [ -f "$StrWorkDir/eix-sync.log" -a "$StrForce" = "no" ]
        then
                ewarn "The portage tree has already synchronized today."
                einfo "Would you like to synchronize again? (Y/n)"
                read StrAnswer
        fi
        if [[ "$StrAnswer" =~ ^([yY]([eE][sS])?)?$ ]]
        then
                ebegin "Updating the portage tree with eix-sync"
                eix-sync &> "$StrWorkDir/eix-sync.log"
        fi
        ebegin "Creating package lists"
        if [ -f "$StrWorkDir/pretend.lst" -a "$StrForce" = "no" ]
        then
                ewarn "The pretend list already exits and will be overwritten."
                einfo "Would you like to continue anyway? (Y/n)"
                read StrAnswer
        fi
        if [[ "$StrAnswer" =~ ^([yY]([eE][sS])?)?$ ]]
        then
                ebegin "Creating pretend list"
                emerge --verbose --pretend --update --deep --newuse world | grep '^\[' &> "$StrWorkDir/pretend.lst"
                eend
                if [ "`cat $StrWorkDir/pretend.lst`" = "" ]
                then
                        einfo "Your system is alredy updated!"
                        exit 0
                fi
        else
                SubAbort
        fi
        ebegin "Checking for blocks packages"
        grep '^\[blocks' "$StrWorkDir/pretend.lst" &> "$StrWorkDir/blocked.lst"
        if [ "`cat $StrWorkDir/blocked.lst`" != "" ]
        then
                eerror "There are the follows blocks packages."
                cat "$StrWorkDir/blocked.lst"
                eerror "Please fix them first and run updantoo late."
                SubAbort
        else
                eend
        fi
        ebegin "Checking for fetch packages"
        grep '^\[ebuild[^]F]*F' "$StrWorkDir/pretend.lst" &> "$StrWorkDir/fetched.lst"
        if [ "`cat $StrWorkDir/fetched.lst`" != "" ]
        then
                eerror "There are the follows fetch packages."
                cat "$StrWorkDir/fetched.lst"
                eerror "Please fix them first and run updantoo late."
                einfo "Trying to emerge these packages in order to get the download URL."
                while read -r StrLine
                do
                        StrPackage=`echo "$StrLine" | sed -e 's/^[^]]*\] //g' -e 's/ .*$//g'`
                        emerge --oneshot --nodeps "=$StrPackage"
                done < "$StrWorkDir/fetched.lst"
                SubAbort
        else
                eend
        fi
        rm -f "$StrWorkDir/emerged.lst" "$StrWorkDir/failed.lst" "$StrWorkDir/emerge.log"
        touch "$StrWorkDir/emerged.lst" "$StrWorkDir/failed.lst" "$StrWorkDir/emerge.log"
        NumPackages=`wc -l "$StrWorkDir/pretend.lst" | cut -d' ' -f1`
        ebegin "Emerging $NumPackages packages from pretend list"
        while read -r StrLine
        do
                StrPackage=`echo "$StrLine" | sed -e 's/^[^]]*\] //g' -e 's/ .*$//g'`
                ebegin "Emerging $StrPackage ($NumPackage of $NumPackages)"
                let NumPackage++
                emerge --oneshot --nodeps "=$StrPackage" >> "$StrWorkDir/emerge.log" 2>&1
                if [ "$?" -eq "0" ]
                then
                        echo "$StrPackage" >> "$StrWorkDir/emerged.lst" 2>&1
                        eend
                else
                        echo "$StrPackage" >> "$StrWorkDir/failed.lst" 2>&1
                        eend "Fail emerging $StrPackage!"
                fi
        done < "$StrWorkDir/pretend.lst"
        if [ "`cat $StrWorkDir/failed.lst`" = "" ]
        then
                einfo "All packages were emerged successfully!"; eend
                if [ "$StrForce" = "no" ]
                then
                        einfo "Would you like clean up the system? (Y/n)"
                        read StrAnswer
                fi
                if [[ "$StrAnswer" =~ ^([yY]([eE][sS])?)?$ ]]
                then
                        ebegin "Cleaning up the system"
                        emerge --depclean &> "$StrWorkDir/cleanup.log"
                        rm -rf /var/tmp/portage/* >> "$StrWorkDir/cleanup.log" 2>&1
                        eclean distfiles >> "$StrWorkDir/cleanup.log" 2>&1
                        eend
                fi
                if [ "$StrForce" = "no" ]
                then
                        einfo "Would you like to run revdep-rebuild? (Y/n)"
                        read StrAnswer
                fi
                if [[ "$StrAnswer" =~ ^([yY]([eE][sS])?)?$ ]]
                then
                        ebegin "Runing revdep-rebuild"
                        revdep-rebuild &> "$StrWorkDir/revdep-rebuild.log"
                        eend
                fi
        else
                mv "$StrWorkDir/pretend.lst" "$StrWorkDir/failed_pretend.lst"
                eerror "These packages couldn't be merged:"
                cat "$StrWorkDir/failed.lst"
                eerror "Please fix them manually and run updatoo again."
                SubAbort
        fi
  else
        eerror "Invalid option."
        SubHelp
        exit 1
  fi
  einfo "Finished!"
  exit 0
  < A NAME="note# End Script " HREF="#textnote# End Script ">< SUP># End Script #


 

 

Veja a relação completa dos artigos de Ricardo Iramar dos Santos

Opinião dos Leitores

Seja o primeiro a comentar este artigo
*Nome:
Email:
Me notifique sobre novos comentários nessa página
Oculte meu email
*Texto:
 
  Para publicar seu comentário, digite o código contido na imagem acima
 


Powered by Scriptsmill Comments Script