#ident	"@(#)proto:desktop/menus/size_chk	1.12"

# Disk slice 1 = root, 3 = usr, 4 = var

function size_chk
{
# These size arrays are generated with the help of
# sysinst/desktop/buildscripts/sizer.sh.  See the comments in that file.
# The pseudo-package "dtext_icon" needs to be added manually.

ASdocs[1]=0	ASdocs[3]=57	ASdocs[4]=0
PEdocs[1]=0	PEdocs[3]=51	PEdocs[4]=0
acl[1]=1	acl[3]=1	acl[4]=0
acp[1]=1	acp[3]=2	acp[4]=0
atm[1]=0	atm[3]=2	atm[4]=0
audit[1]=1	audit[3]=1	audit[4]=0
base[1]=11	base[3]=19	base[4]=0
bkrs[1]=2	bkrs[3]=2	bkrs[4]=0
bsdcompat[1]=1	bsdcompat[3]=3	bsdcompat[4]=0
ccs[1]=0	ccs[3]=14	ccs[4]=0
cmds[1]=1	cmds[3]=5	cmds[4]=0
deASdocs[1]=0	deASdocs[3]=22	deASdocs[4]=0
dePEdocs[1]=0	dePEdocs[3]=22	dePEdocs[4]=0
dele[1]=1	dele[3]=5	dele[4]=0
demerge[1]=1	demerge[3]=7	demerge[4]=0
desktop[1]=1	desktop[3]=9	desktop[4]=0
dfs[1]=0	dfs[3]=1	dfs[4]=0
display[1]=0	display[3]=3	display[4]=0
dtclients[1]=0	dtclients[3]=1	dtclients[4]=0
dtext_icon[1]=0	dtext_icon[3]=1	dtext_icon[4]=0
dtxt[1]=0	dtxt[3]=6	dtxt[4]=0
dtxtfonts[1]=0	dtxtfonts[3]=4	dtxtfonts[4]=0
dynatext[1]=0	dynatext[3]=5	dynatext[4]=0
esASdocs[1]=0	esASdocs[3]=21	esASdocs[4]=0
esPEdocs[1]=0	esPEdocs[3]=21	esPEdocs[4]=0
esle[1]=1	esle[3]=5	esle[4]=0
esmerge[1]=1	esmerge[3]=7	esmerge[4]=0
frASdocs[1]=0	frASdocs[3]=21	frASdocs[4]=0
frPEdocs[1]=0	frPEdocs[3]=21	frPEdocs[4]=0
frle[1]=1	frle[3]=5	frle[4]=0
frmerge[1]=1	frmerge[3]=7	frmerge[4]=0
inet[1]=1	inet[3]=3	inet[4]=0
itASdocs[1]=0	itASdocs[3]=20	itASdocs[4]=0
itPEdocs[1]=0	itPEdocs[3]=20	itPEdocs[4]=0
itle[1]=1	itle[3]=6	itle[4]=0
itmerge[1]=1	itmerge[3]=7	itmerge[4]=0
jaASdocs[1]=0	jaASdocs[3]=71	jaASdocs[4]=0
jaPEdocs[1]=0	jaPEdocs[3]=43	jaPEdocs[4]=0
jale[1]=1	jale[3]=12	jale[4]=0
jamerge[1]=1	jamerge[3]=7	jamerge[4]=0
jadicopft[1]=0	jadicopft[3]=22	jadicopft[4]=0
lp[1]=0		lp[3]=1		lp[4]=0
ls[1]=1		ls[3]=3		ls[4]=1
manpages[1]=0	manpages[3]=12	manpages[4]=0
merge[1]=1	merge[3]=7	merge[4]=0
netmgt[1]=1	netmgt[3]=1	netmgt[4]=0
nfs[1]=1	nfs[3]=1	nfs[4]=0
nics[1]=2	nics[3]=1	nics[4]=0
nis[1]=0	nis[3]=1	nis[4]=1
nsu[1]=1	nsu[3]=2	nsu[4]=0
nuc[1]=1	nuc[3]=2	nuc[4]=0
nwnet[1]=1	nwnet[3]=1	nwnet[4]=0
nwsup[1]=0	nwsup[3]=0	nwsup[4]=4
oam[1]=0	oam[3]=3	oam[4]=0
osmp[1]=3	osmp[3]=1	osmp[4]=0
platform[1]=1	platform[3]=1	platform[4]=0
rpc[1]=1	rpc[3]=1	rpc[4]=0
server[1]=0	server[3]=1	server[4]=0
terminf[1]=1	terminf[3]=0	terminf[4]=0

# The variable "size" (declared below) is intentionally declared to be a
# "regular" variable as opposed to an integer.  If "size" were declared to be
# an integer, then [ -z "$size" ] (used below) would not return anything
# useful.

typeset size avail pkg
integer i

#- overhead compensation - varies by FS, UFS is 15% which seems the worst, but
#- then again UFS and vxfs are better at fragments than s5, so ...
for i in 1 3 4
do
	[ "${SLTYPE[i]}" != "$off" ] && (( avail[i] = SLSIZE[i]*85/100 ))
done
# If dynatext is not selected (and desktop is selected), then dtext_icon flag is
# turned on to indicate that only icon stubs will be installed from the dynatext
# package.  We must add space for these stubs.
for pkg in $ALLPKGS dtext_icon
do
# If a user chose to install a package, subtract its space needs
# from the available space.
	if (( pkg ))
	then
		for i in 1 3 4
		do
# Assign "size" the value of the appropriate array variable as defined
# above, using pkg and i.
			eval size=\${$pkg[i]}
			[ -z "$size" ] && {
				# If this condition is true, it means that someone forgot to add
				# the size array definition (above) for this package.
				faultvt "$0: Internal Error: $pkg has no size information."
				halt
			}
# If the filesystem slice is defined, subtract the package space for
# that slice from it.  Otherwise subtract the space from the root slice.
			if [ "${SLTYPE[i]}" != "$off" ]
			then
				(( avail[i] -= size ))
			else
				(( avail[1] -= size ))
			fi
		done
	fi
done
# If any filesystem has negative space available, warn the user
# how much extra space they need to allocate to it.
for i in 1 3 4
do
	[ "${SLTYPE[i]}" != "$off" ] && (( avail[i] < 0 )) && {
		FS_BIG=${SLNAME[i]}
# Need to increase the amount of space we tell the user they
# need to add to compensate for the amount for filesystem overhead.
# It's not just 15% extra because that comes up 1-2 MB short.
		(( FS_LACKS = -avail[i]*115/100+2 ))
		eval display -w "\"$SPACE_ERR\"" -bg $ERROR_BG -fg $ERROR_FG
		return 1
	}
done
return 0
}
