summaryrefslogtreecommitdiff
path: root/conf/intel/portage/bashrc
blob: a6f4f2521067b055f7e0a1f318f852332c2b48d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
cleancache() {
	# By default, binary mode portage downloads binary packages from repository and saves 
	# them in /usr/portage/packages. This saves bandwidth in case of reinstalls/downgrades, 
	# but will eat up lots of HDD space, possibly preventing further installs/upgrades.

	# To address this issue, we check if /usr/portage/packages directory is on its own partition
	# case in which we do nothing assuming that user gave it plenty space anyway. But if its
	# not the case, and /usr/portage/packages is just a directory in the system / root hierarchy,
	# then we make sure we remove downloaded binary packages after every installation.

	# This function hooks into the pkg_postinst() phase, after the package files are written 
	# into the filesystem and registered into the database, and just removes the content of
	# /usr/portage/packages directory (which is the binary package cache).

	# In orther for this to work PORTDIR (/usr/portage) and PKGDIR(/usr/portage/packages)
	# must be on the same filesystem, which is 99% the case. If they are on different
	# filesystems, package cache is always saved, as mentioned above.

	export local PORTDIRDEV=$(find /usr/ports/gentoo -maxdepth 0 -printf "%D")
	export local PKGDIRDEV=$(find /usr/ports/gentoo/packages -maxdepth 0 -printf "%D")
	if [ $PORTDIRDEV = $PKGDIRDEV ]; then
		rm -rf /usr/ports/gentoo/packages/"${CATEGORY}"/"${P}"*.tbz2
	fi
}

main() {
	if [ "${EBUILD_PHASE}" == "postinst" ]; then
		cleancache
	fi
}

main