Welcome to encomiabile.it
“Gather ye rosebuds while ye may, old time is still a-flying. And this same flower that smiles today tomorrow will be dying” (Dream Theater - A Change of Season)

* The one that syncs your portage tree

What it does? This script is ideated for the ones that already have a gentoo computer/server at their home.
Usually /usr/portage directory is mounted through NFS to execute only one 'emerge --sync' and, by the effects of NFS mounting, this sync is automatically mirrored on other computers too. This solution is quite good but I've had some problem in the past, furthermore when the 'other computer' is a laptop.
I prefer to sync that tree on my laptop in order to avoid problems that may happen if something goes wrong and you're not at your home. Maybe a crash happens and you have your very old portage tree stored so you've to sync it.
Another thing I've experienced is when you forget to rebuild the kernel modules (provided by ebuilds). In these cases the system could hang on boot asking for drivers, or simply Xorg may not start at all. What if the driver is the wireless one? You'll probably have to attach your laptop to the router, download through normal eth cable and so on..

So I've written a small script that:

  • Sync portage tree remotely
  • Sync the remote portage tree locally
  • Auto fetch module-rebuild packages (works only with portage v >=2.2)
  • Update layman repositories
  • Update eix cache and show diff

Every task could be performed either using eix or emerge.
These parameters can be easily configured by editing variables at the beginning of the script.

Little note
Using '-s' switch you can force the script to run an eix/emerge sync even if it's has been disabled by the settings.

External tools: portage rsync [eix] [layman]

Script code

  1. #!/bin/sh
  2.  
  3. # A small script to sync remote portage tree with local one
  4. # Written by Fabiano 'elbryan' Francesconi
  5. # Please report any feedback/error/suggestion to fabiano 'dot' francesconi 'at' gmail 'dot' com
  6.  
  7. # Changelog
  8.  
  9. # v0.2-r3 17/09/09
  10. # - Now using trap to trap SIGINT and terminate the script
  11.  
  12. # v0.2-r2 16/09/09
  13. # - Code improvement (thanks to drizztbsd & exg)
  14.  
  15. # v0.2-r1 25/08/09
  16. # - Fixed code for using new eix commands
  17.  
  18. # v0.2 - 06/07/09
  19. # - Refactored everything
  20. # - Now uses fucntions.sh and ewarn/einfo/eerror functions
  21. # - Improved output beautyness
  22. # - Minor bugs fix
  23.  
  24. # v0.1 - 03/07/09
  25. # - added auto fetching options
  26. # - improved layman update command
  27.  
  28. # you want to run a remote 'eix-sync' on remote_server?
  29. # yes = eix-sync
  30. # no = nothing
  31. # emerge = use emerge --sync
  32. run_remote_eix_sync="no"
  33.  
  34. # remote server. DNS or IP here.
  35. remote_server=""
  36. # remote directory. remember rsync syntax as trailing '/' at the end of the directory
  37. remote_dir="/usr/portage/"
  38. # remote username, probably you want root here
  39. remote_username="root"
  40.  
  41. # local directory where portage is placed
  42. local_dir="/usr/portage"
  43.  
  44. # auto fetch module-rebuild packages
  45. # since rsync would delete/alterate your current /usr/portage/distfiles directory, you may want
  46. # this script to simply fetch your module-rebuild packages (useful when you have in there some important drivers - like wireless/ethernet ones -)
  47. # that will be unable to download if missing.
  48. # WARNING: You *MUST* have portage version 2.2 or major to make this to work
  49. auto_fetch_module_rebuild="no"
  50.  
  51. # if you have layman just choose yes here
  52. update_layman="no"
  53.  
  54. # if you want the script to update your portage cache
  55. update_eix_cache="yes"
  56. # ... and show the differences from the previous sync
  57. show_eix_diff="yes"
  58.  
  59. # look for functions.sh
  60. # baselayout 2
  61. [ -r /lib/rc/sh/functions.sh ] && . /lib/rc/sh/functions.sh
  62. # baselayout 1
  63. [ -r /sbin/functions.sh ] && . /sbin/functions.sh
  64.  
  65. # set trap for interrupting the script if SIGINT is received
  66. message="SIGINT received. Script halted."
  67. trap " trap sees INT; echo -e ${message}; exit 1" INT
  68.  
  69. if [ "${1}" = "-s" ]; then
  70.     if [ "${2}" = "emerge" ]; then
  71.         run_remote_eix_sync="emerge"
  72.     else
  73.         run_remote_eix_sync="yes"
  74.     fi
  75. fi
  76.  
  77. ebegin "Checking tools"
  78.  
  79. rsync_path=$(qfile -Ceq rsync)
  80. if [ -z "${rsync_path}" ]; then
  81.     eerror "Unable to find rsync in your system. Aborting"
  82.     exit -1
  83. fi
  84.  
  85. eix_path=$(qfile -Ceq eix)
  86. if [ -z "${eix_path}" ]; then
  87.     eerror "Unable to find eix in your system."
  88.     ewarn "Disabling eix-driven options.."
  89.     update_eix_cache="no"
  90.     show_eix_diff="no"
  91.     if [ ${run_remote_eix_sync} = "yes" ]; then
  92.         ewarn "..and falling back to emerge --sync....."
  93.         run_remote_eix_sync="emerge"
  94.     fi
  95. fi
  96.  
  97. eend $?
  98.  
  99. if [ ${run_remote_eix_sync} = "yes" ]; then
  100.     ebegin "Running remote eix-sync.."
  101.     ssh ${remote_username}@${remote_server} 'eix-sync -q'
  102.     eend $?
  103. elif [ ${run_remote_eix_sync} = "emerge" ]; then
  104.     ebegin "Running remote emerge --sync.."
  105.     ssh ${remote_username}@${remote_server} 'emerge --sync -q'
  106.     eend $?
  107. fi
  108.  
  109. ebegin "Syncing remote ${remote_dir} dir with local one (${local_dir}).."
  110. rsync -raz -e "ssh -l ${remote_username}" --delete "${remote_server}:${remote_dir}" "${local_dir}"
  111. eend $?
  112.  
  113. if [ ${auto_fetch_module_rebuild} = "yes" ]; then
  114.     ebegin "Auto fetching module-rebuild packages.."
  115.     emerge -Fq @module-rebuild > /dev/null
  116.     eend $?
  117. fi
  118.  
  119. if [ ${update_layman} = "yes" ]; then
  120.     ebegin "Updating layman repositories.."
  121.     layman -Sq > /dev/null
  122.     eend $?
  123. fi
  124.  
  125. if [ ${update_eix_cache} = "yes" ]; then
  126.     ebegin "Copying old eix cache to eix.previous.."
  127.     cp /var/cache/eix /var/cache/eix.previous
  128.     eend $?
  129.  
  130.     ebegin "Updating local eix cache.."
  131.     eix-update -q
  132.     eend $?
  133. fi
  134.  
  135. if [ ${show_eix_diff} = "yes" ]; then
  136.     einfo "Showing eix differences.."
  137.     eix-diff /var/cache/eix.previous
  138. fi
  139.  
  140. einfo "Script Completed"
  141.  

Or you can download the script file HERE

Issue that you may encounter
An ssh connection needs to be enstablished through the systems involved with the operations.
Is very suggested (by me) to use private/public RSA authentication in order to avoid explicit login (this is mandatory if you're going to run this script through cron).


Last update: Apr 27 @ 12:31