#!/bin/bash # portageoverlay.sh # A script to automatically create a local portage overlay # It will take only one argument at a time ### $$$$$$$$$$$$$$$$ ppurka $$$$$$$$$$$$$$$$$$$$ ### ### Set the colors that will be used ### yellow="\E[1;33m" red="\E[1;31m" green="\E[1;32m" underline="\E[4m" bold="\E[1m" normal="\E[0m" # Print out information. # Usage: info "Whatever you want to print" info(){ echo -e " $yellow *$normal ${@}"; } # Print out information without ending with a newline. This adds a space at end # Usage: infon "Whatever you want to print" infon(){ echo -ne " $yellow *$normal ${@} "; } # Print out error information. # Usage: Err "Whatever you want to print" Err(){ echo -e " $red *$normal [$red ERROR!!$normal ] ${@}"; } help() { echo "" echo -e " $yellow portageoverlay.sh:$normal" info "Usage: portageoverlay.sh " info "-h | --help This help text"; echo; info "This program is used to automatically create a local portage overlay" info "This program takes only one argument at a time" info "If the package name is not present in portage, then a new overlay will be created" info "To give a particular package version, provide an \"=\" before it" info "For example: ./portageoverlay.sh =mrxvt-0.4.0" echo "" exit 0; } get_ebuild_path() { EBUILD_PATH=`equery which "$@" 2>&1` if [[ -z "$(echo $EBUILD_PATH | grep "\!\!\!")" ]]; then # No Errors in equery,- so this has actual ebuild path if [[ -z "$(echo $EBUILD_PATH | grep "/usr/local/portage")" ]]; then info "Path to ebuild: $EBUILD_PATH" else EBUILD_PATH="$(echo $EBUILD_PATH | sed -e 's/usr\/local/usr/')"; info "There is already a file in your local portage overlay. Assumed path to ebuild: $EBUILD_PATH" fi # Set the local ebuild path LOCAL_EBUILD_PATH="$( echo $EBUILD_PATH | sed -e 's/usr/usr\/local/')"; DIRNAME="$( dirname $LOCAL_EBUILD_PATH )" # Make the local portage directory mkdir -p "$DIRNAME" [[ -f "$EBUILD_PATH" ]] && cp -i -v $EBUILD_PATH $LOCAL_EBUILD_PATH; else # Erros in equery,- get user input info "$EBUILD_PATH" infon "Enter the name of the package [Eg. rox-2.3.0]: " read answer; EBUILD_PATH="$answer"; infon "Enter the directory structure [Eg. rox-base/rox]: " read answer; EBUILD_PATH="/usr/portage/${answer}/${EBUILD_PATH}.ebuild"; if [[ ! -z "$(echo $EBUILD_PATH | grep " ")" ]]; then Err "There should be no spaces in the above answers"; exit 1; fi echo; info "Assumed path to ebuild: $EBUILD_PATH" # Set the local ebuild path LOCAL_EBUILD_PATH="$( echo $EBUILD_PATH | sed -e 's/usr/usr\/local/')"; DIRNAME="$( dirname $LOCAL_EBUILD_PATH )" infon "Enter the path to the ebuild file that will be used: " read answer; if [[ -f ${answer} ]]; then # Make the local portage directory mkdir -p "$DIRNAME" cp -i -v ${answer} $LOCAL_EBUILD_PATH; else Err "${answer}: No such file exists"; exit 1; fi fi } if [[ $# -gt 1 ]]; then Err "Provide only one argument!" help; exit 1; elif [[ -z "$@" || "$@" = "-h" || "$@" = "--help" ]]; then help; fi LEN=`echo "/usr/local/portage/" | wc -c` get_ebuild_path "$@"; #CUT_FROM=`echo $DIRNAME | wc -c` #EBUILD_NAME="$( echo $LOCAL_EBUILD_PATH | cut --bytes=`echo $DIRNAME/ | wc -c`- )" #EBUILD_NAME=`basename $EBUILD_NAME .ebuild` EBUILD_NAME=`basename $LOCAL_EBUILD_PATH .ebuild` # Number of stages to compilation #NUMBER=4 # Overwrite existing patches in $DIRNAME/files if required ## [[ -d "$(dirname $EBUILD_PATH )/files" ]] && cp -f -r "$(dirname $EBUILD_PATH)/files" "$DIRNAME" ## Start of overlay, compilation, installation from here: >>>>>>>>>> if [[ "$( grep "KEYWORDS=" $LOCAL_EBUILD_PATH | grep "~x86")" == "" ]]; then info "Good! Package is not masked :)" else infon "Package is masked. Add it to /etc/portage/package.keywords? [enter/y or n]: " read -n 1 answer; echo case $answer in "" | [yY]*) echo "$(dirname $LOCAL_EBUILD_PATH | cut --bytes=$LEN-)" >> /etc/portage/package.keywords info "Tail of /etc/portage/package.keywords: $underline$(tail -n 1 /etc/portage/package.keywords)$normal" ;; [nN]*) info "Skipping masking of ebuild ;-)" ;; [dD]*) info "You don't care => I don't care :P Exiting!" exit 0 ;; *) info "I have seen penguins read and type better X(" exit 1 ;; esac fi # ;; # -1) infon "Do you want to edit the ebuild? [enter/y (yes) or n or d (don't bug me)]: " read -n 1 answer; echo case $answer in "" | [yY]*) vim $LOCAL_EBUILD_PATH ;; [nN]*) info "Skipping editing of ebuild ;-)" ;; [dD]*) info "You don't care => I don't care :P Exiting!" exit 0 ;; *) info "I have seen penguins read and type better X(" exit 1 ;; esac # ;; # 0) infon "Do you want to digest the package? [enter/y or n or d (don't bug me)]: " read -n 1 answer; echo case $answer in "" | [yY]*) ebuild $LOCAL_EBUILD_PATH digest ;; [nN]*) info "Digest skipped ;-)" ;; [dD]*) info "You don't care => I don't care :P Exiting!" exit 0 ;; *) info "I have seen penguins read and type better X(" exit 1 ;; esac # ;; # 1) infon "Do you want to emerge the package by \"emerge -av $@\"? [enter/y (yes) or n (compile manually) or d (don't bug me)]: " read -n 1 answer; echo case $answer in "" | [yY]*) emerge -av $@ exit 0 ;; [nN]*) info "We will compile manually stage by stage ;-)" ;; [dD]*) info "You don't care => I don't care :P Exiting!" exit 0 ;; *) info "I have seen penguins read and type better X(" exit 1 ;; esac # ;; # 2) infon "Do you want to unpack the package? [enter/y or n or d (don't bug me)]: " read -n 1 answer; echo case $answer in "" | [yY]*) ebuild $LOCAL_EBUILD_PATH unpack info "Unpacked! Now go into /var/tmp/portage/$EBUILD_NAME/work/$EBUILD_NAME in order to compile this package or in order to modify some source file" info "And use a different terminal from this one :P" ;; [nN]*) info "Unpack skipped ;-)" ;; [dD]*) info "You don't care => I don't care :P Exiting!" exit 0 ;; *) info "I have seen penguins read and type better X(" exit 1 ;; esac # ;; # 3) infon "Do you want to compile the package? [enter/y or n(manually compile) or d (don't bug me)]: " read -n 1 answer; echo case $answer in "" | [yY]*) ebuild $LOCAL_EBUILD_PATH compile; ;; [nN]*) touch "/var/tmp/portage/$EBUILD_NAME/.compiled" info "Placing a.compiled file in work directory ;-)" ;; [dD]*) info "You don't care => I don't care :P Exiting!" exit 0 ;; *) info "I have seen penguins read and type better X(" exit 1 ;; esac # ;; # 4) infon "Do you want to merge the package? [enter/y or n or d (don't bug me)]: " read -n 1 answer; echo case $answer in "" | [yY]*) ebuild $LOCAL_EBUILD_PATH install ebuild $LOCAL_EBUILD_PATH qmerge ebuild $LOCAL_EBUILD_PATH clean info "Installed, Merged and Cleaned the working dir" ;; [nN]*) info "Install & merge skipped ;-)" info "If you want to do it manually, then you need to install, qmerge and clean" ;; [dD]*) info "You don't care => I don't care :P Exiting!" exit 0 ;; *) info "I have seen penguins read and type better X(" exit 1 ;; esac # ;; # *) exit 0 ### Old code ### #for i in $( seq -2 $NUMBER ) #do # case $i in # -2) # ;; # esac #done