#!/bin/bash ################################################################## # Copyright (C) 2005 DEMAINE Benoit-Pierre (benoit@demaine.info) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ################################################################## ###BEGIN # This script is written for those stupid people like me # who like launching several emerge at the same time # It tries to determine whether launching a new emerge at once is risky or not. # It can take one or two arguments. # Each argument can be composite; composite arguments are delimited with " # if you give two arguments, it says whether the two emerge can be done in parallel: # $ emerge-diff xmms wireless-tools # usually returns OK, because their dependencies do not overlap. # $ emerge-diff xmms xmms # will always fails since dependencies of xmmms overlap with himself. # $ emerge-diff "xmms wireless-tools" "enlightenment mplayer" # will tell if it is possible to do side by side: # $ emerge xmms wireless-tools # $ emerge enlightenment mplayer # If the script reports any risk, it will print the list of # common dependencies between the first and the second argument. # If you first emerge the list returned, then you can emerge side # by side the first and second argument without breaking any thing. # if you provide only one argument, the script will list # the running emerges, and build the dependency list of all packages being emerged. # this allows to determine whether you can start a 2nd (or 3rd) emerge # without stopping the ones already running to add arguments. # # If you supply only one agument, the script WILL NOT analyse whether # already running emerges may break portage !!! # emerge-diff # without any argument will list packages being emerged. ###END # I am sorry I did not find any way to print out the list of deps # a way that you can emerge it at once :( EMERGE="/usr/bin/emerge -p " E="emerge" GREP="/bin/grep" G="grep" CUT="/bin/cut" COMM="/bin/comm -1 -2" ECHO="/bin/echo" SORT="/bin/sort" PS="/bin/ps" SED="/bin/sed" S="sed" TR="/bin/tr" CAT="/bin/cat" HEAD="/bin/head" TAIL="/usr/bin/tail" # Prefix of temp files ... TMP="/tmp/ziouplop" # is there an argument ? if [ -z "$1" ] then Z=" " else Z="$1" fi if [ "$1" = "-h" -o "$1" = "--help" ] then begin=`$CAT $0 | $GREP -n '###BEGIN' | $TR '\n' ' ' | $CUT -d ":" -f 1 | $CUT -d " " -f1` end=`$CAT $0 | $GREP -n '###END' | $TR '\n' ' ' | $CUT -d ":" -f 1 | $CUT -d " " -f1` # compute length length=$(($end-$begin-1)) $CAT $0 | $HEAD -n $(($end-1)) | $TAIL -n $length exit 0 fi if [ -z "$2" ] then R=`eval "${PS} ax | ${GREP} $E | ${GREP} -v $G | ${GREP} -v $S | ${GREP} -v "$0" | $SED 's/\([^.]*\)emerge\([^.]*\)$/\2/g' | $SED 's/ -[^ ]*\ //g' | $TR '\n' ' '"` if [ -z "$R" ] then $ECHO "No emerge running: please give two arguments." exit 1 fi $ECHO "Actually emerging $R" else R="$2" fi SKIP=" ${GREP} -v \"These are the packages\" | ${GREP} -v \"Calculating dependencies\" | ${GREP} -v \"Total size of downloads\" | ${CUT} -d \"]\" -f2 | ${CUT} -d \" \" -f2 | ${GREP} \"/\" | ${SORT}" eval "${EMERGE} "$Z" | ${SKIP}" >${TMP}1 eval "${EMERGE} "$R" | ${SKIP}" >${TMP}2 R=`eval "${COMM} ${TMP}1 ${TMP}2"` if [ -z "$R" ] then $ECHO "No overlapping detected." exit 0 else $ECHO "OVERLAPING DETECTED - try continue at your own risks." $ECHO "$R" exit 1 fi