#!/bin/sh # collecting required information ARCH="$(portageq envvar ARCH)" PORTCONF_DIR="/etc/portage" # check if keywords file exists if [ ! -f ${PORTCONF_DIR}/package.keywords ] then echo "Creating ${PORTCONF_DIR}/package.keywords..." touch ${PORTCONF_DIR}/package.keywords fi # check if special lines in keyword file exists SPECIAL_LINE_COUNT="$(grep -nE "(/\*)|(\*/)|(^[ \t]*#)" ${PORTCONF_DIR}/package.keywords | tail -n 1 | awk -F: '{ print $1 }')" if [ -z "${SPECIAL_LINE_COUNT}" ] then SPECIAL_LINE_COUNT=0 fi # create tmpfile TMP_FILE=$(mktemp) # copy untouched special lines to new file head -n $SPECIAL_LINE_COUNT ${PORTCONF_DIR}/package.keywords > $TMP_FILE ( while [ -n "${1}" ] ; do LINE="${1} ~${ARCH}" if [ -z "$(grep "^${LINE}$" ${PORTCONF_DIR}/package.keywords)" ] then # adding requested package echo "${LINE}" echo "adding \"${LINE}\" to ${PORTCONF_DIR}/package.keywords" | logger -st $(basename $0) else # requested package already there echo "Don't adding \"${1}\". Already there." > /dev/stderr fi shift 1 done # listing all remaining packages in file tail -n $(($(cat ${PORTCONF_DIR}/package.keywords | wc -l)-$SPECIAL_LINE_COUNT)) ${PORTCONF_DIR}/package.keywords # sort packages and seperate categories by new line ) | grep -v "^$" | sort | awk -F/ '{ if (OLD_PREFIX!=$1) print ""; OLD_PREFIX=$1 ; print }' >> $TMP_FILE # creatbackup and move temporary file to destination mv ${PORTCONF_DIR}/package.keywords ${PORTCONF_DIR}/package.keywords.bak mv $TMP_FILE ${PORTCONF_DIR}/package.keywords chmod +r ${PORTCONF_DIR}/package.keywords