/*--------------------------------------------------------------------------*\
     LINUX_LOGO 3.02 -- Shows a Logo With some System Info - 1 September 1999
     by Vince Weaver (weave@eng.umd.edu, http://www.glue.umd.edu/~weave )
                                         http://www.vince.weaver.org/
     SUPPORTS Linux (most architectures) and some non-Linux OS's
\*--------------------------------------------------------------------------*/

HISTORY: 
  
   Back in the summer of '97 there was a recurring topic on the linux-kernel
   list about having a "boot-up" penguin in the kernel.  There were many 
   arguments back and forth, but eventually the primary consensus was that
   this would be better done in user-space.  [though with the advent
   of GGI, etc, a graphical approach may become standard.  Patches did
   float around of a Vga-font hack to get a penguin...]
   
   So using a ppm to ansi converter from Rasterman [www.rasterman.com],
   a trial version of THEDRAW under DosEmu, and just some talents left
   over from my Ansi-art BBS days I hacked together a rough likeness
   of Ewing's Linux Penguin.  I added some system info from /proc, and
   linux_logo was born.
   
   The program itself has grown more "feature-full" as people around the
   world sent in their patches.  The newer versions are primarily minor
   cosmetic fixes.  But I get a lot of positive feedback from this tiny
   little program I created one summer day........
   
----------------------------------------------------------------------->
POTENTIAL USES FOR linux_logo
----------------------------------------------------------------------->

Note: also see the file "USAGE.FAQ" for some commonly asked questions
      on how to use linux_logo.

* BOOT UP PENGUIN: just stick "/usr/local/bin/linux_logo" in an rc file.
     [/etc/rc.d/rc.M is a good place if you are running Slackware.  Place
      it right above where sendmail causes a pause.]
  
* MOTD/LOGIN: You can have the penguin appear at the login prompt.
  
    FOR SLACKWARE/OPENLINUX
        Add the following lines to /etc/rc.d/rc.M [in slackware] 
        or to /etc/rc.d/rc.local [OpenLinux]
	
       /usr/local/bin/linux_logo > /etc/issue
       /usr/local/bin/linux_logo > /etc/issue.net
  
      and the penguin appears at all the login prompts, even remote ones.
        
    FOR REDHAT: Here is how to do the above with a Redhat distribution.
                [these were tested for Redhat 6.0]
		
	 In the file /etc/rc.d/rc.local Look for the lines saying 
	 
    # This will overwrite /etc/issue at every boot.  So, make any changes you
    # want to make to /etc/issue here or you will lose them when you reboot.
    
         towards the middle of the file.  Comment out [by putting a # at the
	     start of each line] the following 6 lines, up to, but not
	     including,  the line that says 'fi'.
	 
	 Before the 'fi' put in the following lines:
	 
             if [ -f /usr/local/bin/linux_logo ]; then
                echo "" > /etc/issue
                /usr/local/bin/linux_logo -t "$R" >> /etc/issue
	        /usr/local/bin/linux_logo -a -t "$R" > /etc/issue.net
	        echo >> /etc/issue
	     fi
	
	This will give you a color linux_logo at the consoles, and an 
	    ascii linux_logo when telnetting in.
	    
    FOR DEBIAN: 
        [thanks to <rlovison@simons-rock.edu> ]
        Nice program!  Just wanted to let you know how I used it within a 
	Debian system.  I have the logo appear above any text in the message 
	of the day and as long as the day's message remains under a few lines, 
	it works out wonderfully.  First I renamed the Debian default 
	/etc/motd, created a new one with touch motd', used the following 
	command:
	
            /usr/local/bin/linux_logo > /etc/motd 
	    
       and then added a line of text at the end of the file.  Next I edited 
       /etc/init.d/boot.  In the following lines which appear near the end 
       of the file:
     
           if [ "$EDITMOTD" != no ]
           then
               uname -a > /tmp/motd
	       sed 1d /etc/motd >> /tmp/motd
	       mv /tmp/motd /etc/motd
           fi
			     
      change the third line to:
      
	  /usr/local/bin/linux_logo > /tmp/motd
			     
      and the fourth line to:
			     
	 sed 1,18d /etc/motd >> /tmp/motd
			     
     and as long as EDITMOTD is set to yes at the beginning of the file, it
     should work.
     
    FOR SUSE:
      [thanks to Rodolfo Pilas <rodolfo@linux.org.uy>]
      
      Edit /sbin/init.d/boot.local file and add the
      following lines before "exit 0" line:
      
          /usr/local/bin/linux_logo > /etc/issue
	  /usr/local/bin/linux_logo -a > /etc/issue.net			     
	      
      
* NETWORK LOGIN:
        Note: for platforms that do not have color ansi telnet connections
	you might want to use the new "linux_logo -a" option.  This gives
	a plain ascii [though less exciting and uglier] output.  However
	boring telnet clients like win95's can then see the Penguin.  To
	add this functionality, follow the above instructions, but instead
	of:
	      /usr/local/bin/linux_logo > /etc/issue.net
	use the following in the appropriate place
	      /usr/local/bin/linux_logo -a > /etc/issue.net
	 
* PENGUIN PORT: You can set up a port on your Linux box to answer connections
         with the Penguin! 
	 
         Add the following line to /etc/services
	     penguin         54321/tcp        penguin
	     
	 Add the following line to /etc/inetd.conf
	    penguin stream  tcp     nowait  root   /usr/local/bin/linux_logo
	    
         Restart inetd (killall -HUP inetd) and you have it!!
	 
	 Locally "telnet your.host penguin" will do it.  From other machines
	 you will need the port number ("telnet your.host 1234").. it is easy
	 to customize.. just pick a port number and away you go!
 
 ----------------------------------------------------------------------->
 INSTALLING linux_logo
 ----------------------------------------------------------------------->
 
    untar and uncompress the file
        tar -xzvf linux_logo-3.01.tar.gz
	
    enter the directory
        cd linux_logo-3.01
	
    edit the Makefile and be sure everything is set up the way you want.
    [on stock Linux systems it should work without any changes]
    
    compile the program
        make
	
    you can install it by hand
        cp linux_logo /usr/local/bin
	
    "make install" will do this for you.  You can place it anywhere you want,
    but /usr/local/bin is as good a place as any.
  
--------------------------------------------------------------------------->
USAGE
--------------------------------------------------------------------------->

Usage:   linux_logo [-a] [-b] [-c] [-d] [-e file] [-f] [-g] [-h] [-kX] [-l] 
                    [-n] [-o num] [-p] [-rX] [-s] [-t str] [-u] [-v] [-w Num]
                    [-x] [-y] [-F format]
         [-a]     -- Display logo as ascii only monochrome
         [-b]     -- New default Banner Logo!
         [-c]     -- The Old [classic] linux_logo look
	 [-d]     -- disable "prettying" of output
         [-e file]-- Use "file" instead of /proc/cpuinfo [for debugging
         [-f]     -- force the screen clear before drawing
      B  [-g]     -- give system info only
         [-h]     -- this help screen
      B  [-kX]    -- X is a character to replace the background one.
      B  [-l]     -- display logo only
      C  [-n]     -- toggle periods off [may make cleaner output]
      C  [-o Num] -- offset output Num spaces to the right
         [-p]     -- preserve cursor location
      B  [-rX]    -- X is a character to replace '#' with in banner mode
         [-s]     -- skip Bogomips [speeds up on non-Linux platforms]
         [-t str] -- display user-supplied string
      *  [-u]     -- show uptime
         [-v]     -- version information
         [-w Num] -- set width of screen to Num [default 80]
      B  [-x]     -- narrow logo [useful if issue displays wrong]
      *  [-y]     -- show load average
         [-F format] Format output.  See README.

 B=Banner mode only, C=Classic Mode Only  *=Works Only in Linux


More detailed explanations:

[-a]     : This option makes linux_logo output no fancy colors.  This is
           useful if you are viewing linux_logo over a black and white 
	   terminal, or a terminal that can't handle fancy escape sequences
	   well [like default win95 telnet].
	   
[-b]     : This option makes sure you are viewing the new 'banner' style
           output, which the author prefers.  I actually didn't draw this
	   logo; Albert Lai did and let me use it.
	   
[-c]     : This option makes linux_logo display the 'classic' [i.e. pre 2.0]
           style logo.  Apparently many people prefer this version.  I made
	   it myself using some complex manipulation of TheDraw and of
	   the 'official' logo.xpm that comes with the linux_sources.
	   
[-d]     : This option turns off Megahertz rounding and cpuinfo "prettying".
           That is, it prints your /proc/cpuinfo's "model name" verbatim,
	   instead of being clever and making it look nice.
	   
[-e file]: Specify an alternate cpuinfo file.  This is only really useful
           if you are debugging a /proc/cpuinfo file that is not from
	   your own computer.  Theoretically you could also use this to
	   make your old 386 appear to be a Pentium to users ;)

[-f]     : This option simply clears the screen before drawing the logo.

[-g]     : This option makes linux_logo display the system_info only.
           [Note.. this option only works in banner mode].  This is
	   useful if you have your own, better, ansi logo and you don't
	   want to mess with include files.  Just
	   "cat My_Logo >> out; linux_logo -g >> out" to get your logo with
	   my sysinfo.

[-h]     : This simply displays the help screen, which is much less verbose
           than this write-up.

[-kX]    : This option lets you change which character is used when drawing 
           the background of the logo.  Just put the character you want
	   instead of X.  See the next section to learn how to use non-ascii
	   values [like the IBM line-drawing values] instead.
	   
[-l]     : This option displays the logo only [Only works in banner mode].
           This is useful if for whatever reason you don't want to see the
	   system info.
	   
[-n]     : This option toggles periods off.  It makes the classic logo look
           somewhat nicer.  It has no effect on the banner logo.

[-o Num] : This option will offset the logo towards the right of the screen
           Num spaces.

[-p]     : This option preserves the position of the cursor on the screen
           while drawing the logo under it.
	   
[-rX]    : This option is similar to the -kX option described above, only
           it replaces the foreground character not the background one.

[-s]     : This option skips the bogomips test on non-linux ports.  On 
           platforms that don't have the bogomips value in a /proc file,
	   linux_logo calculates the value itself using a GPL'd routine.
	   This can take a while, especially on slower machines, so it can
	   be disabled.
	   
[-t str] : This option displays user-supplied string (for example,
           Red Hat release or welcome...')  in first line of system info.
           See the "Things to do" section for ways to use this.
	   
[-u]     : This option displays the uptime along with the other system
           information.  While useless when putting logos in issue or motd
	   files, this option comes in handy if you are using linux_logo
	   to impress your friends.  Also, when used in conjunction with
	   the -g option, you can use linux_logo in Server-Side includes
	   in web pages.
	   
[-v]     : This option displays the version of linux_logo you are using.

[-w Num] : Use this option to set the width of the screen.  It helps in trying
           to center the banner mode. Default is 80 columns.
	   
[-x]     : This option makes the banner mode output only 79 characters wide,
           possibly counteracting probelms some Xterm/telnet clients have
	   when connection to a computer with linux_logo in issue.net
	   
[-y]     : Display the load average.  [Yes I have just about run out of
           letters to use as command line options ;)]

[-F format]: Use this to super-customize the output of the cpuinfo.  You 
           pass a string, for example "#V\n#U\n#L\n".  See the section
	   below entitled "THE NEAT NEW FORMAT COMMAND" for further info.

--------------------------------------------------------------------------->
NEAT THINGS YOU CAN DO
--------------------------------------------------------------------------->

Changing the output character of the banner
   + You do this with the -rX option where X is the character to output
     instead of the default #
   + Some interesting chars to use instead are $ % X * and ~
   + If you have an IBM-VGA font loaded with ibm's extended graphics
     characters [ascii codes 128-256] you can output these commands when
     using the bas shell via
        linux_logo -R$'\nnn'
     Where you replace nnn with the octal [base eight] code for the ascii
     value.  Some neat values of nnn to try are 333 316 260 and 263
     [Note.. this only seems to work properly with bash 2.0 and greater]
   + You can have it report Redhat version using the -t option
     (thanks to Aleksey Makarov <makarov@iitam.omsk.net.ru>
     for this tip).
     
     If you have redhat installed already, change /etc/rc.d/rc.local so
     where it says
     
        echo "" > /etc/issue
        echo "Red Hat Linux $R" >> /etc/issue
        echo "Kernel $(uname -r) on $a $(uname -m)" >> /etc/issue
     
     comment it out [or delete it] and add instead put 
     
       /usr/local/bin/linux_logo -f -t "$R" > /etc/issue

     For older versions of redhad [older than 5.2] you might try

       /usr/local/bin/linux_logo -f -t "Red Hat $R" > /etc/issue

--------------------------------------------------------------------------->
TROUBLESHOOTING
--------------------------------------------------------------------------->

Know bugs: 
  
      Will not support >9 CPU SMP machines currently.
      
      Different architectures have odd /proc files.  If you send me
      a copy of relevant files (/proc/cpuinfo and /proc/version usually)
      I can see about adding support.
      
      On non-Linux platforms the BogoMips check can be quite slow.  To skip
         it use "linux_logo -s"
      
      To make easy updated to ansi files with difficult editors, 
         the combination ^[ is read as the ESC code (#27 decimal)
	 so this combination cannot be used in a picture.
	 
      If you use linux_logo to make your issue.net file, and it comes across
         all garbled and corrupt when telnetting in, try using linux_logo
	 with the -x option.
	 
------------------------------------------------------------------------>
CUSTOMIZING "TWEAKING" THE SYSTEM INFO OUTPUT
------------------------------------------------------------------------>
     To customize some options of linux_logo, try editing the defaults
         in the "defaults.h" file.
	 
     For ultimate customization, see the section below on the "Format"
         option.
	 
     The cpuinfo supplied in /proc/cpuinfo is not always the most 
         desirable text to be displayed as the cpuinfo.  In the relevant
	 sysinfo_x.c file there is a place where I add custom outputs to
	 "beautify" the output.  For instance I parse the ugly
	 "K6 (166 - 266)" given by /proc/cpuinfo and have it instead just
	 print "K6".
	      
     If your particular chip gives ugly output, send me a sample /proc/cpuinfo
        and what you'd rather it say.  I have already added fixes for the K6
	and certain Cyrix chips.
	
     Unfortunately the 2.0.x kernels don't know about newer chips.  So to get
        linux_logo to recognize your Pentium II and newer chips, unless you
	can find some sort of distinguishing feature that distinguishes them
	in /proc/cpuinfo from a pentium pro, my only suggestion is to run
	Linux 2.2.x [or soon, a 2.3.x kernel].
	
------------------------------------------------------------------------>
THE NEAT NEW FORMAT COMMAND
------------------------------------------------------------------------>
These are instructions on how to use the new Format command in Linux Logo 3.0

The command line argument is -F.  

Special sequences start with "#" use "##" to make the "#" sign.  All other
characters [except "\n", the carriage return] are printed as is.

Special      Stands For                          Example
________________________________________________________________
  #B     Bogomips                            "374.37"
  #C     Compiled Date                       "#47 Fri Jan 8 10:37:09 EST 1999"
  #E     User Text [given with the -t]       "Given with -t option"
  #H     Hostname                            "deranged"
  #L     Load average                        "Load average 0.04, 0.01, 0.01"
  #M     Megahertz [where supported]         "188Mhz "
  #N     Number of CPU's                     "Two"
  #O     Operating System Name               "Linux"
  #R     Ram [in Megabytes]                  "64M"
  #S     Plural                              "s"
  #T     Type of CPU                         "K6"
  #U     Uptime                              "Uptime 10 hours 59 minutes"
  #V     Version of OS                       "2.2.0-pre5"
  #X     CPU Vendor                          "AMD "
  \n     carriage return


Notes:
  + The letter after the # must be capitalized.
  + Options not available are silently ignored.
  + Megahertz only available on some platforms and newer kernels.
  + See "defaults.h" on how to have #N report in non-english numbers.
  + Plural [#S] gives nothing if there is 1 cpu, gives 's' otherwise.
  + Megahertz [#M] and Type of CPU [#T] return a trailing space.  This makes
    the output consistent across all chips.
  + The "-y" and "-u" [display uptime and load average] command line options
    don't affect the output if a custom format is used.
      
      
For example the default banner format is
"#O Version #V, Compiled #C\n#N #M#X#T Processor#S, #R RAM, #B Bogomips Total\n#H\n"

which on my computer gives an output of:
       
      Linux Version 2.2.0-pre5, Compiled #47 Fri Jan 8 10:37:09 EST 1999
         One 188MHz AMD K6 Processor, 64M RAM, 374.37 Bogomips Total
		                    deranged
					
Another example would be
  linux_logo -F "Redhat Linux 5.2\nKernel Version #V\n#U\n#L\n"

which would give
                                Redhat Linux 5.2
			    Kernel Version 2.2.0-pre5
                            Uptime 11 hours 4 minutes
                          Load average 0.00, 0.00, 0.00
			
As you can see, the possibilities are endless.


------------------------------------------------------------------------>
TOOLS TO CREATE OTHER LOGOS
------------------------------------------------------------------------>
     The image was created using the logo.xpm from the Linux distribution,
     ppm2ansi by Carsten Haitzler -- http://www.cse.unsw.edu.au/~s2154962/
     and was hand edited using THEDRAW under dosemu 0.66.7
     
     Another good ansi editor [under development] from Adam Lackorzynski
     can be obtained at http://www.inf.tu-dresden.de/~al10/aae/
     
------------------------------------------------------------------------->
WHERE TO GET LINUX_LOGO:
------------------------------------------------------------------------->
  http://www.glue.umd.edu/~weave/vmwprod/linux_logo
  http://www.vince.weaver.org/vmwprod/linux_logo
  http://sunsite.unc.edu/pub/Linux/logos/penguin/linux_logo-3.01.tar.gz
  
Check out other programs by me at http://www.glue.umd.edu/~weave/vmwprod

-------------------------------------------------------------------------->
THANKS
-------------------------------------------------------------------------->

   Many thanks to the people sending in patches and /proc/cpuinfo entries.
   Without you linux_logo wouldn't work on so many machines.
   
   Also many Thanks to Marie Prosser who is always there for me.
   
-----------------
Vince
weave@eng.umd.edu
vince@weaver.org
