View previous topic :: View next topic |
Author |
Message |
TheBunman n00b
Joined: 05 May 2004 Posts: 28
|
Posted: Tue Dec 23, 2008 7:33 pm Post subject: [SCRIPT] unmaskmerge (helps merging masked packages) |
|
|
Hi Folks,
I've written an small bash script that helps me merging (keyworded) packages with (multiple) keyworded dependencies.
Since I used it for some time now, I decided to share it with the community.
For example:
$ unmaskmerge games-sports/ultimatestunts
Quote: | * Execute command 'emerge games-sports/ultimatestunts' ? (y/n) y
[ FAILED ] running 'emerge -pv games-sports/ultimatestunts'
* it seems like games-sports/ultimatestunts is masked by keyword. set keyword? (y/n) y
[ - OK - ] setting keyword for games-sports/ultimatestunts
[ - OK - ] running emerge -pv games-sports/ultimatestunts
These are the packages that would be merged, in order:
Calculating dependencies... done!
[ebuild N ] games-sports/ultimatestunts-0.7.5 USE="nls" 16,399 kB
Total: 1 package (1 new), Size of downloads: 16,399 kB
* is this ok? (y/n) |
If you type y the actual merge process will be started.
When there are more keyworded dependencies you will be asked for each depending package if you want to set the keyword for it.
To install this script, copy the following script into /usr/bin/unmaskmerge
Code: | #!/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 |
Then chmod 755 /usr/bin/unmaskmerge to make it executable.
This script needs also the directory /etc/portage/package.keywords/unmaskmerge/ where it creates the files to set the keyword for the packages.
All parameters are passed directly to emerge.
So you can also for example run: unmaskmerge --deep world
If you {like this script, find an bug, have any suggestions} post an comment or patch, and I will update this post.
Greetings
DerBunman _________________ how would you feel if you no longer feared your government |
|
Back to top |
|
|
Naib Watchman
Joined: 21 May 2004 Posts: 6051 Location: Removed by Neddy
|
Posted: Tue Dec 23, 2008 10:19 pm Post subject: |
|
|
or... emerge autounmask _________________
Quote: | Removed by Chiitoo |
|
|
Back to top |
|
|
TheBunman n00b
Joined: 05 May 2004 Posts: 28
|
Posted: Tue Dec 23, 2008 11:18 pm Post subject: |
|
|
oh nice
i didn't know this tool exists _________________ how would you feel if you no longer feared your government |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|