Bitte lesen:
Ein persönlicher Aufruf von
Bunnybase-Gründer Kim Il-sung

unmaskmerge (Bash Script)

Dieses kleine bash script unmasked ein Paket sammt dependencies und merged es dann.
Dies ist vor allem dann sehr kompfortabel, wenn ein Paket wieder weitere masked Packages benötigt.

Aufruf:
$ ./unmaskmerge "emerge_command"

also z.b.:
$ ./unmaskmerge "-uD world"


Dependencies:
Es wird lediglich eix benötigt


#!/usr/bin/env bash

# Gentoo unmaskmerge script beta1
# written by Lorenz Werner 2008 
# License: none (if you are an nice person you keep my name in the comment above)

# printf colors
RED="\033[31m"
GREEN="\033[32m"
BLUE="\033[34m"
LIGHT_GRAY="\033[37m"

# define some styles for the exit_status function
ASTERISK="$GREEN *$LIGHT_GRAY"
ACTIVE="\r $LIGHT_GRAY[$BLUE ACTIVE $LIGHT_GRAY]"

# check if user has root rights
if [[ $UID -ne 0 ]]; then
  printf $RED"$0 must be run as root\n"
  exit 1
fi

# check if neccessary directories exists
if [ ! -d "/etc/portage/package.keywords/unmaskmerge" ]; then
  printf $RED"$0 missing directory '/etc/portage/package.keywords/unmaskmerge'\n"
  exit 1
fi

# check if an command is provided
if [ "$1" == "" ]; then
  printf $RED"please provide emerge command\n"
  printf $LIGHT_GRAY"eg: $0 -upD world\n"
  exit
fi

# this function provides the OK and FAILED messages
function exit_status() {
  X=$?
  if [ $1 != "" ]; then
    if [ $1 != "exit" ]; then
      STATUS=$1
    else
      STATUS=$X
    fi
  else
    STATUS=$X
  fi
  
  if [ $STATUS == 0 ]; then
    printf "\r $LIGHT_GRAY[ -$GREEN OK $LIGHT_GRAY- ]\n"
  else
    printf "\r $LIGHT_GRAY[$RED FAILED $LIGHT_GRAY]\n"
    if [ $1 == "exit" ]; then
      exit 1
    fi
  fi
}

# confirm the command to be executed 
printf "$ASTERISK Execute command 'emerge $@' ? (y/n) "
read OK
if [ "$OK" != "y" ]; then
  exit 1
fi

# emerge pretend the choosen action
printf "$ACTIVE running$GREEN 'emerge -pv $@'"
emerge -pv $@ > /dev/null
STATUS=$?
exit_status $STATUS

LAST_DEPENDENCY=""

# if the exit status from the last emerge command is not 0 check if there are packages to unmask
while [ $STATUS != 0 ]; do
  # parse emerge output for keyworded dependencies
  DEPEND=`emerge -pv $@ | grep "All ebuilds that could satisfy" | grep -o '".*"' | sed -e 's/\"//g'`

  # if depend is empty, then we couldn't find any dependency
  if [ "$DEPEND" == "" ]; then
    printf "\n$RED sorry, it seems like there is some problem, please try running 'emerge $@' by hand.\n"
    exit
  fi

  # if depend is equal to last_dependency, then the keyword we have set doesn't work
  if [ "$LAST_DEPENDENCY" == "$DEPEND" ]; then
    printf "\n$RED sorry, it seems like the package has already been keyworded.\n"
    exit
  fi

  # confirm if keyword should be set
  printf "\n"
  printf "$ASTERISK it seems like $GREEN$DEPEND$LIGHT_GRAY is masked by keyword. set keyword? (y/n) "

  read OK
  if [ "$OK" != "y" ]; then
    printf "$RED aborting ...\n"
    exit
  fi

  # set keyword for package / dependency
  printf "\n$ACTIVE setting keyword for $GREEN$DEPEND"
  DIR="/etc/portage/package.keywords/unmaskmerge/`dirname "$DEPEND" | sed "s/[\>\<\=\~]//g"`"
  FILE="`basename "$DEPEND" | sed "s/[\>\<\=\~]//g"`"
  mkdir -p "$DIR"
  echo "$DEPEND" >> "$DIR/$FILE"
  exit_status exit

  # try to merge the package again
  printf "$ACTIVE running$GREEN emerge -pv $@"
  emerge -pv $@ > /dev/null
  STATUS=$?
  exit_status $STATUS
  
done

printf "\n"

# show user what emerge will actually do
emerge -pv $@

printf "\n"

# confirm if the user wants to run the actual merge
printf "$ASTERISK is this ok? (y/n) "
read OK

if [ "$OK" != "y" ]; then
  printf "$RED aborting ...\n"
  exit
else
  printf "\n$ASTERISK running 'emerge $@'\n\n"
  # start the actual merge
  emerge $@
fi