xref: /original-bsd/usr.bin/compress/usermem.sh (revision bc058a8b)
12b1d7320Smckusick#!/bin/sh -
22b1d7320Smckusick#
369df8f59Sbostic# Copyright (c) 1985 The Regents of the University of California.
469df8f59Sbostic# All rights reserved.
569df8f59Sbostic#
669df8f59Sbostic# This code is derived from software contributed to Berkeley by
769df8f59Sbostic# James A. Woods, derived from original work by Spencer Thomas
869df8f59Sbostic# and Joseph Orost.
969df8f59Sbostic#
1069df8f59Sbostic# Redistribution and use in source and binary forms are permitted
1169df8f59Sbostic# provided that the above copyright notice and this paragraph are
1269df8f59Sbostic# duplicated in all such forms and that any documentation,
1369df8f59Sbostic# advertising materials, and other materials related to such
1469df8f59Sbostic# distribution and use acknowledge that the software was developed
1569df8f59Sbostic# by the University of California, Berkeley.  The name of the
1669df8f59Sbostic# University may not be used to endorse or promote products derived
1769df8f59Sbostic# from this software without specific prior written permission.
1869df8f59Sbostic# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1969df8f59Sbostic# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
2069df8f59Sbostic# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2169df8f59Sbostic#
22*bc058a8bSbostic#	@(#)usermem.sh	5.6 (Berkeley) 05/11/89
232b1d7320Smckusick#
242b1d7320Smckusick: This shell script snoops around to find the maximum amount of available
252b1d7320Smckusick: user memory.  These variables need to be set only if there is no
262b1d7320Smckusick: /usr/adm/messages.  KMEM, UNIX, and CLICKSIZE can be set on the command
272b1d7320Smckusick: line, if desired, e.g. UNIX=/unix
282b1d7320SmckusickKMEM=/dev/kmem		# User needs read access to KMEM
292b1d7320SmckusickUNIX=
302b1d7320Smckusick# VAX			CLICKSIZE=512,	UNIX=/vmunix
312b1d7320Smckusick# PDP-11		CLICKSIZE=64,	UNIX=/unix
322b1d7320Smckusick# CADLINC 68000		CLICKSIZE=4096,	UNIX=/unix
332b1d7320Smckusick# Perkin-Elmer 3205	CLICKSIZE=4096,	UNIX=/edition7
342b1d7320Smckusick# Perkin-Elmer all others, CLICKSIZE=2048, UNIX=/edition7
352b1d7320SmckusickCLICKSIZE=512
362b1d7320Smckusickeval $*
372b1d7320Smckusick
382b1d7320Smckusickif test -n "$UNIX"
392b1d7320Smckusickthen
402b1d7320Smckusick    : User must have specified it already.
412b1d7320Smckusickelif test -r /vmunix
422b1d7320Smckusickthen
432b1d7320Smckusick    UNIX=/vmunix
442b1d7320Smckusick    CLICKSIZE=512	# Probably VAX
452b1d7320Smckusickelif test -r /edition7
462b1d7320Smckusickthen
472b1d7320Smckusick    UNIX=/edition7
482b1d7320Smckusick    CLICKSIZE=2048	# Perkin-Elmer: change to 4096 on a 3205
492b1d7320Smckusickelif test -r /unix
502b1d7320Smckusickthen
512b1d7320Smckusick    UNIX=/unix		# Could be anything
522b1d7320Smckusickfi
53ebc97e2aSlepreau
54ebc97e2aSlepreauSIZE=0
5502571357Slepreau# messages: probably the most transportable
56*bc058a8bSbosticif test -r /var/log/messages -a -s /var/log/messages
57ebc97e2aSlepreauthen
58*bc058a8bSbostic    SIZE=`grep avail /var/log/messages | sed -n '$s/.*[ 	]//p'`
59ebc97e2aSlepreaufi
60ebc97e2aSlepreau
61ebc97e2aSlepreauif test 0$SIZE -le 0		# no SIZE in /usr/adm/messages
62ebc97e2aSlepreauthen
63ebc97e2aSlepreau    if test -r $KMEM		# Readable KMEM
64ebc97e2aSlepreau    then
652b1d7320Smckusick	if test -n "$UNIX"
662b1d7320Smckusick	then
672b1d7320Smckusick	    SIZE=`echo maxmem/D | adb $UNIX $KMEM | sed -n '$s/.*[ 	]//p'`
682b1d7320Smckusick	    if test 0$SIZE -le 0
692b1d7320Smckusick	    then
706c8aaa2bSlepreau		SIZE=`echo physmem/D | adb $UNIX $KMEM | sed -n '$s/.*[ 	]//p'`
712b1d7320Smckusick	    fi
722b1d7320Smckusick	    SIZE=`expr 0$SIZE '*' $CLICKSIZE`
732b1d7320Smckusick	fi
742b1d7320Smckusick    fi
752b1d7320Smckusickfi
762b1d7320Smckusick
776c8aaa2bSlepreaucase $UNIX in
786c8aaa2bSlepreau    /vmunix)		# Assume 4.2bsd: check for resource limits
796c8aaa2bSlepreau	MAXSIZE=`csh -c limit | awk 'BEGIN	{ MAXSIZE = 1000000 }
806c8aaa2bSlepreau/datasize|memoryuse/ && NF == 3	{ if ($2 < MAXSIZE) MAXSIZE = $2 }
816c8aaa2bSlepreauEND	{ print MAXSIZE * 1000 }'`
826c8aaa2bSlepreau	if test $MAXSIZE -lt $SIZE
836c8aaa2bSlepreau	then
846c8aaa2bSlepreau	    SIZE=$MAXSIZE
856c8aaa2bSlepreau	fi
866c8aaa2bSlepreau	;;
876c8aaa2bSlepreauesac
886c8aaa2bSlepreau
892b1d7320Smckusickif test 0$SIZE -le 0
902b1d7320Smckusickthen
916c8aaa2bSlepreau    echo 0;exit 1
922b1d7320Smckusickelse
932b1d7320Smckusick    echo $SIZE
942b1d7320Smckusickfi
95