View previous topic :: View next topic |
Author |
Message |
fabius Guru
Joined: 29 Nov 2004 Posts: 525
|
Posted: Sun Jan 02, 2005 2:57 pm Post subject: [Tool] Pulizia del portage overlay: cleanoverlay |
|
|
Non avendo trovato niente di analogo in giro, ho scritto lo scrippettino cleanoverlay per pulire il tree del portage overlay. L'ho pensato per due funzioni:
- cancellare un ebuild non ufficiale quando questo viene inserito nel portage;
- mantenere aggiornata la propria versione modificata di un ebuild ufficiale.
Gli ebuild confrontati devono ovviamente avere la stessa versione. Ecco il codice:
Code: | #!/bin/bash
###########################################################################
#
# Copyright 2004 Fabio Rossi
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
###########################################################################
VERSION="0.2.1"
NORMAL="$(color off)"
RED="$(color ltred)"
GREEN="$(color ltgreen)"
YELLOW="$(color ltyellow)"
BLUE="$(color ltblue)"
UL="$(color ul)"
DIFF_COMMAND="diff"
function usage {
echo "Usage: $(basename $0) [-p]"
echo
echo "Options:"
echo " -h, --help"
echo " Print this help"
echo
echo " -l, --list"
echo " List only the ebuilds in overlay"
echo
echo " -p, --pretend"
echo " Don't delete anything in the portage overlay tree"
echo
echo " -v, --version"
}
function listoverlay {
for PORTDIR_OVERLAY in $PORTDIR_OVERLAY_ALL
do
echo -e "\nContents of ${UL}$PORTDIR_OVERLAY${NORMAL} overlay:"
local ebuild_list=`find "$PORTDIR_OVERLAY" -iname \*.ebuild | sort`
if [ "$ebuild_list" == "" ] ; then
echo " No ebuild found in portage overlay $PORTDIR_OVERLAY"
continue
fi
echo
oldcategory=""
for j in `seq $(echo "$ebuild_list" | wc -l)`
do
ebuild=`echo "$ebuild_list" | head -n $j | tail -n 1`
ebuild_rel=${ebuild#"${PORTDIR_OVERLAY}/"}
category="$(dirname $ebuild_rel)"
if [ "$category" == "$oldcategory" ] ; then
echo " ${BLUE}$(basename $ebuild_rel)${NORMAL}"
else
echo "* $category"
echo " ${BLUE}$(basename $ebuild_rel)${NORMAL}"
oldcategory="$category"
fi
done
done
echo
}
# get the portage directories
source /etc/make.conf
PORTDIR=${PORTDIR-"/usr/portage"}
PORTDIR_OVERLAY_ALL=${PORTDIR_OVERLAY-""}
if [ "$PORTDIR_OVERLAY" == "" ] ; then
echo "I can't find a valid overlay directory, nothing to do"
exit
fi
[ ! `/usr/bin/whoami` = 'root' ] && echo "Program require root access!" && exit 1
which &>/dev/null color
if [ $? -ne 0 ] ; then
echo "Emerge app-misc/color to use this script"
exit 1
fi
args=`getopt -q -o lphv -l list,pretend,help,version -- "$@"`
if [ $? -ne 0 ]
then
echo -e "*** Error in using $(basename $0)\n"
usage
exit 1
fi
endoptions=false # is true when it finishes to parse the switches (and their options)
pretend=false
eval set -- "$args" # reset the positional parameters after the changes made by getopt
for i
do
case "$i" in
-p|--pretend)
pretend=true
;;
-h|--help)
usage; exit 1;;
-l|--list)
listoverlay
exit;;
-v|--version)
echo "$(basename $0) $VERSION"; exit;;
--)
endoptions=true;;
*)
if $endoptions ; then true; fi;;
esac
done
echo -e "Portage: $PORTDIR"
echo "Portage overlay: $PORTDIR_OVERLAY_ALL"
for PORTDIR_OVERLAY in $PORTDIR_OVERLAY_ALL
do
echo -e "\nChecking in ${UL}$PORTDIR_OVERLAY${NORMAL} overlay for ebuilds which overwrite those ones in main portage..."
ebuild_list=`find $PORTDIR_OVERLAY -iname \*.ebuild | sort`
if [ "$ebuild_list" == "" ] ; then
echo " No ebuild found in portage overlay $PORTDIR_OVERLAY"
continue
fi
for j in `seq $(echo "$ebuild_list" | wc -l)`
do
ebuild=`echo "$ebuild_list" | head -n $j | tail -n 1`
ebuild_rel=${ebuild#"${PORTDIR_OVERLAY}/"}
if [ -s "$PORTDIR/$ebuild_rel" ] ; then
echo -en "\n${BLUE}$(dirname "$ebuild_rel")/$(basename "$ebuild_rel")${NORMAL} (duplicated ebuilds "
differences=`$DIFF_COMMAND "$PORTDIR/$ebuild_rel" "$PORTDIR_OVERLAY/$ebuild_rel"`
deletecopy=false
if [ "$differences" != "" ] ; then
echo -e "are ${YELLOW}different${NORMAL})"
if [ "$PORTDIR/$ebuild_rel" -nt "$PORTDIR_OVERLAY/$ebuild_rel" ] ; then
echo " The overlay copy is older than that one in main portage [${YELLOW}WARNING${NORMAL}]"
elif [ "$PORTDIR/$ebuild_rel" -ot "$PORTDIR_OVERLAY/$ebuild_rel" ] ; then
echo " The overlay copy is newer than that one in main portage [${GREEN}NORMAL${NORMAL}]"
else
echo " It appears they have the same modification date"
fi
echo
goon=false
ans=""
while ! $goon
do
echo " 1) Delete ebuild in overlay"
echo " 2) Show differences"
echo " 3) Skip"
echo -n " Select: "
read ans
case $ans in
"1")
goon=true
deletecopy=true
echo
;;
"2")
echo
echo " $PORTDIR/$ebuild_rel vs $PORTDIR_OVERLAY/$ebuild_rel"
echo "$differences" | while read -r line ; do echo " $line"; done
echo
;;
"3")
goon=true
echo
;;
*)
echo -e " Unknown answer\n" ;;
esac
done
else
echo -e "are ${GREEN}identical${NORMAL})"
deletecopy=true
fi
if [ $deletecopy == true -a $pretend == false ] ; then
rm "${PORTDIR_OVERLAY}/$ebuild_rel"
echo " ${PORTDIR_OVERLAY}/$ebuild_rel ${RED}deleted${NORMAL}"
if [ $(find "${PORTDIR_OVERLAY}/$(dirname $ebuild_rel)" -iname \*.ebuild | wc -l) -eq 0 ] ; then
rm -rf "${PORTDIR_OVERLAY}/$(dirname $ebuild_rel)"
echo " ${PORTDIR_OVERLAY}/$(dirname $ebuild_rel)/ ${RED}deleted${NORMAL}"
fi
elif [ $deletecopy == true -a $pretend == true ] ; then
echo " ${PORTDIR_OVERLAY}/$ebuild_rel ${RED}would be deleted${NORMAL}"
if [ $(find "${PORTDIR_OVERLAY}/$(dirname $ebuild_rel)" -iname \*.ebuild | wc -l) -eq 1 ] ; then
echo " ${PORTDIR_OVERLAY}/$(dirname $ebuild_rel)/ ${RED}would be deleted${NORMAL}"
fi
elif [ $deletecopy == false -a $pretend == true ] ; then
echo " ${PORTDIR_OVERLAY}/$ebuild_rel ${GREEN}would be preserved${NORMAL}"
else
echo " ${PORTDIR_OVERLAY}/$ebuild_rel ${GREEN}preserved${NORMAL}"
fi
fi
done
done |
Per usarlo la prima volta consiglio
Qualsiasi feedback è ben accetto
Last edited by fabius on Thu Apr 28, 2005 2:16 pm; edited 2 times in total |
|
Back to top |
|
|
SteelRage Apprentice
Joined: 17 Nov 2003 Posts: 192
|
Posted: Mon Jan 03, 2005 12:00 am Post subject: |
|
|
non avevo pacchetti "vecchi" da aggiornare in overlay, quindi non l'ho provato al massimo delle sue funzionalità...
solo 2 cosette:
- la dipendenza dall'utility "color" è proprio necessaria?
- non so se l'opzione sia già presente in emerge... ma magari potresti integrare nello script un'opzioncina che lista tutti i pacchetti presenti in overlay (non solo quelli che si "sovrappongono" ad altri)... a volte capita che ne dimentichi alcuni in giro, per riscoprirli dopo mesi
grazie cmq! _________________ In the end we only see to change light to dark dark to light light to dark dark to light. |
|
Back to top |
|
|
fabius Guru
Joined: 29 Nov 2004 Posts: 525
|
Posted: Mon Jan 03, 2005 11:53 am Post subject: |
|
|
Ho utilizzato l'utility color per non dover inserire a mano i codici escape dei colori (è comunque possibile eliminarla) dato che è piccola e si compila subito. Per quanto riguarda l'opzione di listare i pacchetti posso inserirla senza problemi! Appena ho un pò di tempo aggiorno lo script.
// EDIT: aggiornato lo script con l'opzione -l
Grazie per aver provato lo script, pensavo di aver creato qualcosa di inutile |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|