#!/bin/sh
# ~jhs/public_html/bin/.sh/distfiles_mount	by jhs@

# New 2017-02-21. Needs root.
# Nothing yet uses the product of this script.
# Purpose: Creates a stack of overlaying distfiles/.
# Later I will point older
# releases to earlier in the stack, & newer releases to later in the stack.
# Hopefully eventually I will be able to run a distfiles prune on current,
# which will prune stuff fetched by older current into $dir/current
# but will Not prune stuff in $dir/*-RELEASE.

# See also:
#	/site/domain/this/etc/make.conf.fetch
#	~/bin/.sh/distfiles_cmpd
#	~/bin/.sh/distfiles_dups
#	~/bin/.sh/distfiles_fetch
#	~/bin/.sh/distfiles_mount

# Caution:
#	If this is run on host=lapr, & then one runs:
#		cd /.amd_mnt/fire/0s4/ftp/pub/FreeBSD/dists/union
#		touch some-invented-name
#	it takes a Long time, maybe 7 minutes,
#	probably cos its doing a lot of AMD.
#	it may be better later to only run this distfiles_mount on the host=user.

dir=/pub/FreeBSD/dists
union=$dir/union
mkdir $union $dir/top
mnt="mount -t unionfs -o noatime"
$mnt $dir/jhs		$union	# First, at bottom of stack,
				# stuff I am master for.
#	Release Name		Date		Hosts Using	Host Fetching 2017-02
$mnt $dir/4.11-RELEASE	$union	# 2005-01-25 scan,lapl			# LAPL	2
$mnt $dir/6.4-RELEASE	$union	# 2008-11-28 mart,park			# MART	2
$mnt $dir/7.4-RELEASE	$union	# 2011-02-21 sony,lapd,lapn		# 2Strip
$mnt $dir/8.4-RELEASE	$union	# 2013-06-09 lapr:s1,			# BLAK	2
$mnt $dir/9.2-RELEASE	$union	# 2013-09-30 fire,blak			# Soon 2Strip
$mnt $dir/9.3-RELEASE	$union	# 2014-07-17 blak:1s2,lapr:s3		# LAPR + BLAK
$mnt $dir/10.2-RELEASE	$union	# 2015-08-12				# 2Strip
$mnt $dir/10.3-RELEASE	$union	# 2016-04-04 slim,land			# BLAK	2
$mnt $dir/11.0-RELEASE	$union	# 2016-10-10				# BLAK	2
$mnt $dir/current.old	$union	# might be needed by older releases	# 2Strip
$mnt $dir/current	$union	#					# BLAK	2
$mnt $dir/top		$union	# Top of stack. Periodically one should manually move
				# files in here toward bottom of stack.

# If anything is written into $union , it arrives in $dir/top ,
# ( $dir/top also gets lots of empty directories )
# $dir/top protects $dir/current clean from pollution by older distfiles,
# if some host with an older release has a crude symbolic link via AMD,
# eg /usr/ports/distfiles -> $union ;
# Older hosts should best have
#	 /usr/ports/distfiles -> /pub/FreeBSD/dists/X.Y-RELEASE
# A current host should have /usr/ports/distfiles -> /pub/FreeBSD/dists/current
# Occasionaly all of $dir/current is moved to $dir/current.old ,
# then make fetch is run, to see what distfiles are still needed.
# To detect distfiles now obsolete from current, see:
#	/usr/ports/ports-mgmt/pkg_jail clean-distfiles
#	/usr/ports/ports-mgmt/portsreinstall
#	/usr/ports/ports-mgmt/portupgrade
#	/usr/ports/ports-mgmt/poudriere

mount | grep $dir
