From 6419447db9cf1b3590ea38cc4f27a014175b56cc Mon Sep 17 00:00:00 2001 From: sose Date: Sat, 9 Feb 2019 06:27:04 -0800 Subject: [PATCH] first commit --- setflags.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 setflags.sh diff --git a/setflags.sh b/setflags.sh new file mode 100644 index 0000000..64e2615 --- /dev/null +++ b/setflags.sh @@ -0,0 +1,39 @@ +#!/bin/bash +usefile="/etc/portage/package.use/$1" +touch /tmp/usefile + +function addflag +{ + if ! cat $usefile| tr ' ' '\n' |grep -e "^$1" ; then + if [[ $(echo $1 | cut -c 1) == '-' ]]; then + cat $usefile | sed -e 's/ '$(echo $1 | cut -c 2-)'//g' > /tmp/usefile + printf " $1" >> /tmp/usefile + else + cat $usefile | sed -e 's/ -'$1'//g' > /tmp/usefile + printf " $1" >> /tmp/usefile + fi + fi +} + +if [[ -z $1 ]]; then + echo "specify a package atom." + exit +elif [[ -z $2 ]]; then + echo "specify some flags." + exit +elif [[ ! -f $usefile ]]; then + if [[ ! -d $(dirname $usefile) ]]; then + mkdir $(dirname $usefile) + fi + touch $usefile +fi + +printf "$1" > $usefile +for i in $(echo ${BASH_ARGV[*]} | cut -f -$(( $BASH_ARGC -1 )) -d ' ') +do + addflag $i + cat /tmp/usefile > $usefile +done + +rm /tmp/usefile +exit