summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xsbin/keyword_package44
1 files changed, 35 insertions, 9 deletions
diff --git a/sbin/keyword_package b/sbin/keyword_package
index 93b93d9..4ecb034 100755
--- a/sbin/keyword_package
+++ b/sbin/keyword_package
@@ -1,26 +1,52 @@
#!/bin/sh
-SPECIAL_LINE_COUNT=$(grep -nE "(/\*)|(\*/)" /etc/portage/package.keywords | tail -n 1 | awk -F: '{ print $1 }')
+
+# 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)
-head -n $SPECIAL_LINE_COUNT /etc/portage/package.keywords > $TMP_FILE
+# copy untouched special lines to new file
+head -n $SPECIAL_LINE_COUNT ${PORTCONF_DIR}/package.keywords > $TMP_FILE
(
while [ -n "${1}" ] ; do
- LINE="${1} ~x86"
- if [ -z "$(grep "^${LINE}$" /etc/portage/package.keywords)" ]
+ LINE="${1} ~${ARCH}"
+ if [ -z "$(grep "^${LINE}$" ${PORTCONF_DIR}/package.keywords)" ]
then
+ # adding requested package
echo "${LINE}"
- echo "adding \"${LINE}\" to /etc/portage/package.keywords" | logger -st $(basename $0)
+ 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
- tail -n $(($(cat /etc/portage/package.keywords | wc -l)-$SPECIAL_LINE_COUNT)) /etc/portage/package.keywords
+ # 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
-mv /etc/portage/package.keywords /etc/portage/package.keywords.bak
-mv $TMP_FILE /etc/portage/package.keywords
-chmod +r /etc/portage/package.keywords
+# 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