#!/usr/bin/perl #=============================================================================== # # FILE: epu.pl # # USAGE: ./epu.pl # # DESCRIPTION: This script is able to manage the /etc/portage/package.use file # # OPTIONS: must be a valid portage package e.g. "net-im/gaim", # must be a valid useflag e.g. "-perl" to disable # or "perl" to enable or add # (without qoutes (" ") of course ;). # REQUIREMENTS: Gentoo (emerge) # BUGS: none reportet # NOTES: none # AUTHOR: ViLeDa (Tristan Leo), # COMPANY: Schmerzerzeuger # VERSION: 1.0 # CREATED: 07.09.2006 19:27:33 CEST # REVISION: 2 # #=============================================================================== use strict; use Tie::File; #Check commandline unless ( @ARGV > 1 && $ARGV[0] =~ m/\w+\/\w+/ ) { print "Syntax: For example: to enable a flag: epu net-im/gaim perl or to disable a flag: epu net-im/gaim -perl\n"; die "More help informations soon.\n"; } #some declarations my $package = shift @ARGV; my @useflags = sort @ARGV; my $usefile = './package.use'; my $fuseflags; my $fpackage; my $haspackage; my $i = 0; #read the file into an array tie my @uselines, 'Tie::File', $usefile; #look if package already in there for my $fuseline (@uselines) { #regexp for package match and useflag extraction if ( $fuseline =~ m/^($package)[ ](.*)$/sg ) { #package is already in the file #save useflags $fpackage = $1; $fuseflags = $2; $haspackage = 1; last; } $i++; } $uselines[@uselines] = $package . " " . join( " ", @useflags ) if not $haspackage; #write new line to file for my $flags (@useflags) { next if $fuseflags =~ m/^($flags)/; next if $fuseflags =~ m/[ ]($flags)/; next if $fuseflags =~ s/[-]$flags/$flags/; if ( $flags =~ m/[-](.+)/s ) { if ( undef ne $1 && $fuseflags =~ m/$1/s ) { $fuseflags =~ s/$1/$flags/; } } else { print "Adding useflag: ", $flags, "\n"; $fuseflags .= " " . $flags; } } $uselines[$i] = $package . " " . join( " ", sort split( " ", $fuseflags ) ); print "New line: ", $uselines[$i], "\n"; untie @uselines; # vim:ts=8:sw=4:ft=perl