Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Unsupported Software
  • Search

Script to clean /usr/portage/distfiles

This forum covers all Gentoo-related software not officially supported by Gentoo. Ebuilds/software posted here might harm the health and stability of your system(s), and are not supported by Gentoo developers. Bugs/errors caused by ebuilds from overlays.gentoo.org are covered by this forum, too.
Post Reply
Advanced search
7 posts • Page 1 of 1
Author
Message
haylocki
Tux's lil' helper
Tux's lil' helper
Posts: 85
Joined: Wed Apr 10, 2002 6:46 am
Location: London

Script to clean /usr/portage/distfiles

  • Quote

Post by haylocki » Thu Jul 24, 2003 12:57 pm

Hi,

I have been working on a script to clean old source files from the distfiles directory.

Running the following script should leave just the files which are in the world file, in the distfiles directory.

Other files are moved into distfiles_backup. This will include source for files which were emerged with the inject option.

Old versions of files which still exist in the distfiles directory are deleted from the distfiles_backup directory.

The script works by parsing the output of 'emerge -ef world'. So it would be a good idea to run 'emerge -ef world before this script, just to make sure that all the packages needed are still available, and that emerge is working o.k.

The script uses /tmp to store its temporary files, so this directory must already exist (doesn't it exist on all Gentoo systems ?)

Oh, and of course you need to be root to run the script.

Only tested with Portage 2.0.48-r5.

O.K. heres the script, just save it as something like /usr/bin/source_clean.sh

Code: Select all

#!/usr/bin/env bash

read_file="packages.txt"
write_file1="edit1.txt"
write_file2="edit2.txt"
write_dir="/tmp"
source_dir="/usr/portage/distfiles"
backup_dir="/usr/portage/distfiles_backup"

# Create package list
echo Creating package list
emerge -ef world  > ${write_dir}/${read_file}

# Remove un-needed text from list
cat ${write_dir}/${read_file} |
while read filename
    do
	case ${filename} in
	    ">>> md5 src_uri"*)
	        echo ${filename##*' '} >> ${write_dir}/${write_file1};;    
        esac
    done
# Remove duplicate lines
sort -u ${write_dir}/${write_file1} > ${write_dir}/${write_file2}
	
# Move packages to backup file
mkdir -p ${backup_dir}
mv  -f ${source_dir}/* ${backup_dir}

# Remove cvs-src directory if it exists
if [ -d  ${backup_dir}/cvs-src ]
    then
        rm -rf  ${backup_dir}/cvs-src
fi

# Move required packages back to source directory
cat ${write_dir}/${write_file2} |
while read filename
    do
         mv ${backup_dir}/${filename} ${source_dir}/
    done

# Remove old versions from backup directory
sort -u ${write_dir}/${write_file2} > ${write_dir}/${write_file1}
rm ${write_dir}/${write_file1}
cat ${write_dir}/${write_file2} |
while read filename
    do	
	filename=${filename%-*}"*"
	if [ -f ${backup_dir}/${filename} ]
	    then
		rm  ${backup_dir}/${filename}
        fi
    done

# Remove temporary files
rm -f ${write_dir}/${write_file1}
rm -f ${write_dir}/${write_file2}
rm -f ${write_dir}/${read_file}

echo Distfiles directory now cleaned
Hope someone finds it helpful, (and it works :wink: )

Ian
Top
Pythonhead
Developer
Developer
User avatar
Posts: 1801
Joined: Mon Dec 16, 2002 6:30 pm
Location: Redondo Beach, Republic of Calif.
Contact:
Contact Pythonhead
Website

  • Quote

Post by Pythonhead » Thu Jul 24, 2003 3:26 pm

I added your script to this list of portage utilities:

http://forums.gentoo.org/viewtopic.php?t=67849

There is one there called distclean.py that is similar to yours.

People may change their DISTDIR directory though, so you could add this:

Code: Select all

source /etc/make.conf
Then you have ${DISTDIR}
Last edited by Pythonhead on Tue Mar 08, 2005 6:06 pm, edited 2 times in total.
Top
pilla
Bodhisattva
Bodhisattva
User avatar
Posts: 7732
Joined: Wed Aug 07, 2002 8:19 pm
Location: Underworld

  • Quote

Post by pilla » Thu Jul 24, 2003 3:32 pm

Moving to Docs, Tips & Tricks, as it is not a support request.
"I'm just very selective about the reality I choose to accept." -- Calvin
Top
pjp
Administrator
Administrator
User avatar
Posts: 20668
Joined: Tue Apr 16, 2002 10:35 pm

  • Quote

Post by pjp » Thu Jul 24, 2003 3:48 pm

See also, Cleaning out stale distfiles
Top
Calamarain
n00b
n00b
User avatar
Posts: 23
Joined: Tue Jul 27, 2004 9:45 am
Location: Netherlands

  • Quote

Post by Calamarain » Wed Aug 11, 2004 3:08 pm

I get this error in the end:

/usr/bin/source_clean.sh: line 50: [: too many arguments
/usr/bin/source_clean.sh: line 50: [: /usr/portage/distfiles_backup/enigmail-0.83.6.tar.gz: binary operator expected
/usr/bin/source_clean.sh: line 50: [: /usr/portage/distfiles_backup/gentoo-sources-2.4.26-r1.tar.bz2: binary operator expected
/usr/bin/source_clean.sh: line 50: [: /usr/portage/distfiles_backup/ipc-1.0.5.tar.gz: binary operator expected
/usr/bin/source_clean.sh: line 50: [: /usr/portage/distfiles_backup/m4-1.4.tar.gz: binary operator expected
/usr/bin/source_clean.sh: line 50: [: /usr/portage/distfiles_backup/tvtime-0.9.12.tar.gz?download&failedmirror=easynews.dl.sourceforge.net: binary operator expected
Distfiles directory now cleaned


Also, why does the script redownload all the files I already have? Or is that a one time effort?
Top
g4c9z
Apprentice
Apprentice
Posts: 178
Joined: Thu Jun 03, 2004 9:37 pm

  • Quote

Post by g4c9z » Tue Dec 07, 2004 4:09 pm

I got a similar error when I pressed Ctrl+C:
./source_clean.sh: line 50: [: /usr/portage/distfiles_backup/portage-2.0.51-r2.tar.bz2: binary operator expected

And I'm also wondering why it needs to download all 290 of my installed packages.

This script is a great idea though. In fact, I believe something like this should be put in portage and run by default after doing package management. The reason is that a program should never be allowed to gradually fill up a disk more and more as time goes on. The amount of space being used should always be fixed by some user decided constant, in this case by the set of packages they choose to install.
Top
pjp
Administrator
Administrator
User avatar
Posts: 20668
Joined: Tue Apr 16, 2002 10:35 pm

  • Quote

Post by pjp » Tue Dec 07, 2004 4:16 pm

Moved from Documentation, Tips & Tricks as this no longer seems maintained.
Quis separabit? Quo animo?
Top
Post Reply

7 posts • Page 1 of 1

Return to “Unsupported Software”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic