1
2# Those <censored> mIRC'ers have all those irritating system info "remotes" to
3# brag about their system.
4# Now, it's up to Irssi users to brag about their pentium 75's and 2 Gio harddisks.
5# :)
6
7# Differences to Juerd-only-version:
8# -YASFU units (Mio, Gio) - http://snull.cjb.net/?yasfu
9# -Free memory and free swap are displayed (previously only total swap/mem)
10# -Reorganized and tuned output
11# -Displays length of your virtual penis (this is quite tricky, so you might want to disable it by commenting)
12# -Doesn't display info on nfs/smbfs/none-type mounts (edit script if you want those)
13
14# Vpenis is not 100% compatible with Cras' vpenis.sh - I have fixed some bugs:
15# -More network filesystems excluded (originally only NFS was excluded)
16# -Total amount of memory counts (not the used amount, as before)
17
18# Changelog 2.10 -> 2.20: memory/swap info is displayed now (it was broken previously) and code is properly indented
19use strict;
20use vars qw/$VERSION %IRSSI/;
21
22$VERSION = "2.21";
23%IRSSI = (
24	  authors     => "Juerd, Tronic",
25	  contact     => "trn\@iki.fi",
26	  name        => "SysinfoPlus",
27	  description => "Linux system information (with vPenis and other stuff)",
28	  license     => "Public Domain",
29	  url         => "http://juerd.nl/irssi/",
30	  changed     => "2017-04-02"
31	  );
32
33BEGIN{
34    use vars '$console';
35    eval q{
36	use Irssi;
37	Irssi::version();
38    };
39    $console = !!$@;
40}
41
42
43# Tronic has no time for maintaining this and Juerd hates braces, so it might be better
44# not to expect any new versions ...
45
46sub sysinfo{
47    # This should really need indenting, but I'm kinda lazy.
48
49    my (@uname, $ret, @pci, $usr, $avg, $up, $vpenis);
50
51    @uname = (split ' ', `uname -a`)[0..2];
52
53    $ret = "Host '@uname[1]', running @uname[0] @uname[2] - ";
54
55    open FOO,'<', '/proc/cpuinfo';
56    while (<FOO>){
57	/^processor\s*:\s*(\d+)/         ? $ret .= "Cpu$1: "
58	  : /^model name\s*:\s*(\w+[ A-Za-z]*)/ ? do { my $t = $1; $t =~ s/\s+$//; $ret .= "$t " }
59	: /^cpu MHz\s*:\s*([\.\d]+)/       ? $ret .= int(.5+$1) . ' MHz '
60	  : undef;
61    }
62    close FOO;
63    $ret =~ s/( ?)$/;$1/;
64    open FOO,'<', '/proc/pci';
65    while (<FOO>){
66	/^\s*(?:multimedia )?(.*?)( storage| compatible)? controller/i and push @pci, $1;
67    }
68    close FOO;
69    $ret .= 'PCI: ' . join(',', map ucfirst, @pci) . '; ' if @pci;
70    if (`uptime` =~ /^.*?up\s*(.*?),\s*(\d+) users?,.*: ([\d\.]+)/){
71	($usr, $avg) = ($2, $3);
72	($up = $1) =~ s/\s*days?,\s*|\+/d+/;
73	$ret .= "Up: $up; Users: $usr; Load: $avg; ";
74    }
75
76    # Free space
77    $ret .= "Free:";
78    if (`free` =~ /Mem:\s*(\d*)\s*\d*\s*(\d*)/) { $ret .= " [Mem: " . int(.5 + $2/2**10) . "/" . int(.5 + $1/2**10) . " Mio]"; } # For compatibility: replace $1 with $2
79    if (`free` =~ /Swap:\s*(\d*)\s*\d*\s*(\d*)/) { $ret .= " [Swap: " . int(.5 + $2/2**10) . "/" . int(.5 + $1/2**10) . " Mio]"; } # For compatibility: replace $1 with $2
80
81    for (`df -m -x nfs -x smbfs -x none`) {
82	/^\/\S*\s*(\S*)\s*\S*\s*(\S*)\s*\S*\s*(\S*)/ and $ret .= " [$3: $2/$1 Mio]";
83    }
84    $ret .= ";";
85
86    # Vpenis (derived from vpenis.sh)
87    $vpenis = 70;
88    if (`cat /proc/uptime` =~ /(\d*)/) { $vpenis += int($1/3600/24)/10; }
89    if (`cat /proc/cpuinfo` =~ /MHz\s*:\s*(\S*)/) { $vpenis += $1/30; }
90    if (`free` =~ /Mem:\s*(\d*)\s*(\d*)/) { $vpenis += $1/1024/3; } # For compatibility: replace $1 with $2
91    for (`df -P -k -x nfs -x smbfs -x none|grep -v blocks`) { # For compatibility: remove -x smbfs -x none
92	if (/^\S*\s*(\S*)/) { $usr = $1; $vpenis += ((/^\/dev\/(scsi|sd)/) ? 2*$usr : $usr)/1024/50/15; }
93    }
94    $ret .= " Vpenis: " . int($vpenis)/10 . " cm;";
95
96    if ($console){
97	print "$ret\n";
98    }else{
99	Irssi::active_win->command("/say $ret");
100    }
101} #end of sub
102
103if ($console){
104    sysinfo();
105}else{
106    Irssi::command_bind('sysinfo', 'sysinfo')
107}
108