shithub: rc

ref: f3afdf563f784c0a5703496f48c1a72dff4617f4
dir: /gfetch/

View raw version
#!/bin/rc
# Warning, parts of this script have been STOLEN!

# TODO:
# fs usage - done
# kernel

fn storage {
	disks = `{ls -d /dev/sd* | uniq}
	anydisk = 'false'
	for(i in $disks){
		if(test -f $i/data){
			full = `{ls -l $i/data}
			disk = `{echo $full | awk -F '/' '{print $3}'}
			size = `{echo $full | awk '{print $6}'}
			echo $disk^': '^`{echo $size^' / 1024 / 1024 /1024' | bc}^GB
			anydisk = 'true'
			echo statw >> /srv/cwfs.cmd
			dd -if /srv/cwfs.cmd -bs 1024 -count 21 -quiet 1 | grep wmax | sed 's/.*\+//'
		}
	}
	if(~ $anydisk -c 'false')
		echo Running in the diskless
}

fn fs {
	if(ls /srv | grep -s '*.cmd')
		ls /srv/*.cmd | sed 's/.cmd//g' | sed 's/\/srv\///g'
	if(test -f /srv/fscons)
		echo fossil
	# Logic from storage to scrape for venti arenas
	v='false'
	disks = `{ls -d /dev/sd* | uniq}
	for(i in $disks){
		if(ls $i | grep -s arena)
			v='true'
	}
	if(~ $v -c 'true')
		echo venti
}

fn cpuid {
	if(test -f /bin/aux/cpuid)
		aux/cpuid >[2]/dev/null | grep procname | sed 's/.*procname//'
}

os=`{
	if(grep -s 'zrv' /dev/drivers)
		echo 9ants
	if not if(grep -s 'vmx' /dev/drivers)
		echo 9front
	if not
		echo Bell Labs
}

# fs and storage require #S bound on /dev 
bind -b '#S' /dev

arch=`{echo $cputype}
shell=/bin/rc
wm=/bin/rio
uptime=`{uptime| sed 's/.*up//; s/..........$//'}
scr=`{dd -count 1 < /dev/screen|[2];}
scr=($scr(4) x $scr(5))
ram=(`{tr / ' '</dev/swap})
free=`{echo $ram(1)'/1024^2'|bc}
used=`{echo '('$ram(3)'*('$ram(7)^+$ram(5)^'))/1024^2'|bc}
cpu=`{cpuid}
files=`{fs}
strg=`{storage}

cat <<EOF
      __
     (  \
 __   \  '\
(  "-_ \ .-'--____
 '-_  "v"         "-.		$user @$sysname
    "γ'              \		---------------
     |                |		os:		Plan 9 from $os/$arch
     |         O    O |		shell:	$shell
     |          ɾᑕᑐɿ  |		wm:		$wm
      \         "L˩ʺ  |		uptime:	$uptime
       |             .|		ram:	$used/$free MiB
       |             |		cpu:	$cpu
       (             /		res:	$scr
     ⡎⠉'\         . \		fs:		$files
     ⠣⠤⋯^__.__/\_)-'		$strg
EOF