Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # p-beautifier — /etc/portage/package.* files beautifier
- #
- # With this script you can make a hook while adding new item to package.* file.
- # The lines will be alphanumeric sorted and the keys will be indented from the
- # packages.
- #
- # You may prefer use this script through aliases in your ~/.bashrc like
- # alias p-use="/path/to/p-beautifier use "
- # And use it from the shell like `p-use app-emulation/wine X alsa -pulseaudio`
- # It will be equivalent to
- # `echo "app-emulation/wine X alsa -pulseaudio" >> /etc/portage/package.use`
- # But more pretty — indented to 2 columns and sorted.
- #
- # @autor fargred
- # @last_edit 20101025
- # @licence GPL v.2
- #
- FILE=$1
- PACKAGE=$2
- KEYS=${@}
- KEYS=${KEYS#${1}\ ${2}}
- # right column start from INDENT symbols
- INDENT=32
- ASK_ME='yes'
- MERGE='yes'
- add_line() {
- if [[ ${#PACKAGE[0]} -lt $INDENT ]]; then {
- num_of_spaces=$(($INDENT-${#PACKAGE[0]}))
- for ((i=0; i < $num_of_spaces; i++)); do
- PACKAGE="${PACKAGE} "
- done
- }; fi
- echo "${PACKAGE}${KEYS}" >> /tmp/package.$FILE.tmp
- }
- check_line() {
- # PACKAGE variable can contain perfixes and postfixes like ">=" or
- # version numbers, so purifying to section/package
- PKG_SECTION=${PACKAGE%/*}
- PKG_SECTION=${PKG_SECTION//[><=]/}
- PKG_NAME=${PACKAGE#*/}
- PKG_NAME=${PKG_NAME//-[0-9]*/}
- echo ${PKG_SECTION}
- echo ${PKG_NAME}
- search=`grep ${PKG_SECTION}/${PKG_NAME} /etc/portage/package.$FILE`
- if [[ ${search} != '' ]]; then {
- echo -en "Requested package is already in file /etc/portage/package.$FILE\nThe string is: \"${search}\"\nNow, type the exactly package, you prefer. Ctrl+C any time exit. Hit <Enter> to left\ndefault: \"${PACKAGE}\"\nPackage > "
- read input
- if [[ ${input} != '' ]]; then
- PACKAGE=${input}; fi
- echo -en "Now, type the exactly keys, you prefer for that package. Ctrl+C any time exit. Hit <Enter> to left\ndefault: \"${KEYS}\"\nKeys > "
- read input
- if [[ ${input} != '' ]]; then
- KEYS=${input}; fi
- grep -v ${PKG_SECTION}/${PKG_NAME} /etc/portage/package.$FILE > /tmp/package.$FILE.tmp
- }
- else {
- cp /etc/portage/package.${FILE} /tmp/package.$FILE.tmp
- }; fi
- }
- check_line
- add_line
- if [[ $ASK_ME == 'yes' ]]; then {
- echo -e "\nThis is a new /etc/portage/package.$FILE:\n"
- cat /tmp/package.$FILE.tmp
- echo -en "\nDo you want to merge this file with the already exist? [Y/n] "
- read input
- if [[ ${input} == 'n' || ${input} == 'N' ]]; then
- MERGE='no'; fi
- }; fi
- if [[ $MERGE == 'yes' ]]; then
- cat /tmp/package.$FILE.tmp | sort -bdf > /etc/portage/package.$FILE; fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement