/*--------------------------------------------------------------------------*\
     LINUX_LOGO 3.9b1 -- Shows a Logo With some System Info - 6 August 2000
     by Vince Weaver (weave@eng.umd.edu, http://www.glue.umd.edu/~weave )
     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.9b1.tar.gz
	
    enter the directory
        cd linux_logo-3.9b1
	
    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] [-D file] [-e file] [-f] [-F] [-g]
                    [-h] [-l] [-n] [-o num] [-p] [-s] [-t str] [-u] [-v]
                    [-w Num] [-x] [-y] [-F format] [-L num | list | random_xx]
         [-a]     -- Display an ascii-only Logo
         [-b]     -- Display a Banner Logo!
         [-c]     -- Display a "Classic" type logo
         [-d]     -- disable "prettying" of output
         [-D file]-- use custom logo from "file"
         [-e file]-- Use "file" instead of /proc/cpuinfo [for debugging
         [-f]     -- force the screen clear before drawing
         [-F format] Format output.  See README.
      B  [-g]     -- give system info only
         [-h]     -- this help screen
      B  [-l]     -- display logo only
      C  [-o Num] -- offset output Num spaces to the right
         [-p]     -- preserve cursor location
         [-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]
      *  [-y]     -- show load average
         [-L ...] -- multiple Logo options.  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 linux_logo display the first compiled-in "banner" 
           style logo.
	   
[-c]     : This option makes linux_logo display the first compiled-in 
           "classic" style logo.  Many people prefer this version of the
	   logo.  I made it myself using some complex manipulation of TheDraw 
	   and 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.

[-D file]: Use an alternate logo on disk.  Just make sure 'file' points
           to a valid '.logo' file.  Read README.CUSTOM_LOGOS for more
	   info on how to make these.  Some can be found in the 
	   ./logos directory of the linux_logo distribution.

[-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.

[-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.

[-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 has been removed from linux_logo 3.9 and above.
           If you want to create a logo that looks different than the
	   default, read README.CUSTOM_LOGOS.
	   	   
[-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.

[-L num | list | random_xy]:  This option is used to manipulate compiled-in
           custom logos.  As of linux_logo 3.9 you can compile in an
	   arbitrary amount of logos, although the default is to just have
	   the original and banner logos.
	   
	   "-L list" will list all of the logos available
	   "-L num" will display logo number num, where the number is
	       obtained using the "-L list" command
	   "-L random_xy" will pick a logo at random, with criteria xy.
	       When you replace x with the letter:
	          b : pick a random banner mode logo
                  c : pick a random classic mode logo
                  e : pick a logo from either banner or classic
	       When you replace y with the letter:
	          a: pick a random ascii logo
		  n: pick a non-ascii logo
		  e: pick either type of logo
	       So to summarize "-L random_ba" picks a random ascii banner,
	                       "-L random_ce" picks a random classic logo
			       "-L random_ee" picks any logo, etc, etc
			       
	   See README.CUSTOM_LOGOS for more info
	   
[-n]     : This option has been removed from linux_logo 3.9 and above.
           If you want to create a logo that looks different than the
	   default, read README.CUSTOM_LOGOS.

[-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 has been removed from linux_logo 3.9 and above.
           If you want to create a logo that looks different than the
	   default, read README.CUSTOM_LOGOS.

[-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 has been removed from linux_logo 3.9 and above.
           If you want to create a logo that is narrower than the
	   default, read README.CUSTOM_LOGOS.
	   
[-y]     : Display the load average.  [Yes I have just about run out of
           letters to use as command line options ;)]


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

   + 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: 
  
      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.
	 
------------------------------------------------------------------------>
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.


------------------------------------------------------------------------>
CREATING/USING CUSTOM LOGOS
------------------------------------------------------------------------>
  See the file README.CUSTOM_LOGOS for more than you ever wanted to know
  about making and using your own logo files.
     
------------------------------------------------------------------------->
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.9b1.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

