#!/bin/sh # run like this: ocaml-rebuild.sh [-h|--help|-f|--force] [emerge_options] emerge="$(type -P emerge) --ignore-default-opts" portageq="$(type -P portageq)" egrep="$(type -P egrep)" if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then echo "usage: ocaml-rebuild.sh [-h | --help | -f | --force)] [emerge_options]" echo "With -f|--force, the packages will first be unmerged and then emerged" echo "with the given options to ensuree correct dependancy analysis." echo "Otherwise emerge is run with the --pretend flag and the given" echo "options." echo "It is recommended to keep the list of rebuilt packages printed" echo "in pretend mode in case something go wrong" exit 1 fi if [ "$1" = "-f" ] || [ "$1" = "--force" ] ; then pretend=0 shift else pretend=1 echo "Running in pretend mode, will only show which actions would be taken ..." fi installed="$($portageq match / '')" echo "Searching installed packages for ocaml dependencies." echo "Please be patient; this will take a while ..." depends= for i in $installed ; do LC_ALL=C # grep performance completely sucks with UTF-8 depstring="$($portageq metadata / installed $i DEPEND)" if echo $depstring | $egrep -l 'dev-lang/ocaml|dev-ml/findlib' > /dev/null ; then depends="$depends $i" fi done echo "Building a list of packages to reinstall ..." toclean= tobuild= for dep in $depends ; do slot="$($portageq metadata / installed $dep SLOT)" tobuild=">=$dep:$slot $tobuild" toclean="=$dep:$slot $toclean" done if [ "$toclean" != "" ] ; then if [ $pretend -eq 1 ] ; then $emerge --pretend $@ $tobuild else echo "Cleaning $toclean ..." $emerge --unmerge $toclean echo "Building $tobuild ..." $emerge $@ $tobuild fi else echo "Nothing to update" fi echo "All done!"