Saturday, February 28, 2015

Pi's and Install Configuration

UPDATED:

My Raspberry Pi 2's have arrived!  Two of which are now running on the Internet.  I have three locations that I want to install and run them from.

New Raspberry Pi 2's
The initial installations will be running Raspbian (wheezy) serving simple Ham Radio Blog pages and running some HF Beaconing or Receiver code. See: http://dc01.ebcon.com:8040/

As a system administrator for large employers, I have installed and configured many Linux (UNIX) systems, I now have it down to quick trivial process.

For Raspberry Pi, First:

On the Raspberry Pi, I immediately execute the following commands:




$ sudo aptitude install ssh sshuttle
$ sudo aptitude install xosview htop tree wicd apache2 php5
$ sudo aptitude install vnc-server vnc-viewer




Note: if these are already installed, no harm. See the man pages as necessary.

Then I add users as necessary, with:



$ sudo adduser <user_name>




And then, add the appropriate admin "user_name" to the "sudo" group


$ sudo adduser <user_name> sudo




Then:

There are several things I DO NOT like about most default UNIX installations.

The first is the default command "prompt", which is typically a long string of characters that is; the user and system name, and the current working directory. The information is good, but the format is terrible. While in a directory way down in the directory structure, typing space on the displayed command line is very limited, and wraps around and is difficult to use. For example, change to the directory as shown:



$ cd /usr/share/SuperCollider/SCClassLibrary/Common/GUI/PlusGUI/Control/



This will result in a Command Prompt of:



pi@rbpi3 /usr/share/SuperCollider/SCClassLibrary/Common/GUI/PlusGUI/Control $ 




Note: there is little typing space on the line to the right of the "$". There is little wonder why most users get turned OFF with the Linux Command Line environment.

I personally like the same information, only in a different prompt format. For example (see below), the "date" command was entered at the prompt, and then executed, a new prompted followed:




/usr/share/SuperCollider/SCClassLibrary/Common/GUI/PlusGUI/Control
rbpi3$ date
Sat Feb 28 12:32:40 PST 2015

/usr/share/SuperCollider/SCClassLibrary/Common/GUI/PlusGUI/Control
rbpi3$




In this example the prompt starts with a blank line, followed by the current directory, and then on the next line, the name of the system, followed by the "$" prompt. Regardless of the length of the current directory, the user starts typing at the same location on the command line (and with space to spare).

Modifying or Adding this type of Prompt is simple, but I have done it "too" many times, see shell script below.



PS1='\n$PWD\n\h\$ '



Also, I set the default "command line editor" to "vi", this allows the use of "vi" key commands to "edit the command line", and access "command history stack". As in; "h" and "l" (cursor Hop-left and Leap-right), "j" and "k" (history Jump-down and Klimb-up). Also, see shell script below.



set -o vi



I now add a simple script (/etc/bash.bashrc.local) to each system I install. It contains all of my favourite system modifications. The script is as shown below, details are not provided, but maybe you will find bits-of-it you would like also.

Note, depending on the initial OS installation, each user may want to remove the ".bashrc" and ".profile" from their home directory, or adopt parts of this script in their files. I like the system wide approach, an yet, while knowing that it is a little dictatorial.




#
# Usage in /etc/bash.bashrc
# Add the following two lines to the end of /etc/bash.bashrc, uncommenting the "test" line.

   # Start up /etc/bash_localrc for Local Stuff
   # test -f /etc/bash.bashrc.local && . /etc/bash.bashrc.local

# Local Startup files for Bash

   #echo "Start: /etc/bash.bashrc.local"
   #set -xv

   TZ='PST8PDT'; export TZ
   PATH=/usr/local/lbin:$PATH

# Show System Key

   # KEY="$(ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub)"
   # KEY="${KEY#* }"
   # echo
   # echo "System Key: ${KEY% *}"

# Setup the default editor
   export EDITOR='vi'
   set -o "$EDITOR"

# Setup History
   HISTSIZE=10000
   HISTCONTROL=ignoreboth:erasedups
   shopt -s cmdhist histappend lithist execfail

# Add extended globing
   shopt -s extglob

# Set the Terminal Tab value
   # If this is an xterm set the title to user@host:dir
   case "$TERM" in
   xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
     ;;
   esac

# Prompt # for root, $ otherwise
   PS1='\n$PWD\n\h\$ '


# Local Aliases
   alias ll='ls -l '
   alias bdf='df '
   alias is='ps -ef | grep -v grep | grep -- '

   #set +xv
   #echo "End: /etc/bash.bashrc.local"


# Some Interesting Shell Stuff
   alias ralias='. $HOME/.alias'; # reread HOME aliases
   alias ...='cd ../..'
   alias ..='cd ..'

# Local GitHUB Aliases
# Git related
   alias gco='git checkout'
   alias gci='git commit'
   alias gst='git status'
   alias gbr='git branch'
   alias gls='gbr'
   alias gsbr='git show-branch'
   alias gmg='git merge --no-ff -v --progress'

   alias gad='git add'
   alias gdf='git diff'
   alias glg='git log'
   alias ggp='git grep'
   alias gpu='git push'
 
   alias gk='gitk --all &'
   alias gr='git rebase'
   alias gri='git rebase --interactive'
   alias gcp='git cherry-pick'
   #alias grm='git rm'

# End



I use "scp" to grab the script from a previously installed system.


Security Tip

If you going to put a Raspberry Pi on the Internet:
  • Remember to set a new passwd on the pi login
  • Do not open the ssh port 22 directly to the Internet, use a router to NAT and route another port to the Raspberry Pi. Note: if you DO open port 22, your system will be hammered by break-in attempts. Check your logs often.
  • Open only the ports that are necessary for your applications.
  • Also, I recommend doing something similar for port 80.

Be careful, the Internet is full of malicious hackers and "script kiddies" that will take over and eat your Raspberry Pi.

The following is a script that I wrote many years ago, as "taillogs", it "lists" and "follows" the system logs, showing new log events as they occur. I know it is somewhat cryptic, but does a nice job.

I saved this in a file: "/usr/local/lbin/taillogs".

Note: "/usr/local/lbin" is where I save all of my authored scripts.




#! /bin/sh
# Author: Eldon R. Brown, eldonb@ebcon.com

        cd /var/log &&
        find . -type f -print |
        egrep -v "\.[0-9][0-9]*$|OLD|mbox|\.offset$" |
        xargs ls -tr |
        xargs file |
        sed -n '/ text/s/:.*//p' |
        xargs tail -n2 -f

# End



With this script, it is easy to check your system logs.


-- Home Page: https://WA0UWH.blogspot.com

1 comment:

  1. Hi Eldon, long time no see :)

    I've not been blogging much for a few months so I have lately been catching up on your blog. This raspi config post is terrific information! You've put a huge amount of work into this and I will be able to use quite a bit of it in my future raspi projects, thanks.

    I'm studying to get my Foundation Ham licence after several years of putting it off, I've been consistently getting decent scores on some online example test exams, now I just have to find a test centre and bite the bullet!

    On the topic of Ham stuff, I recently did a blog post that may interest you...
    http://wardyprojects.blogspot.co.uk/2015/02/propeller-high-frequency-output-using.html
    It uses the Parallax Propeller's high frequency PLL output features to generate VHF carrier signals using the "CTRx" hardware (in the background), leaving your code free to perform the necessary signal modulation! The Prop's VHF generation tops out at about 180MHz (when using a standard 5MHz external crystal).

    I know you've hacked with the Propeller before so you may know how to do all this already, but I thought I'd mention it anyway.

    This kind of technique lends itself to CW, FM and QRSS signalling. This is the kind of thing I'd be most interested in using my Ham license for.

    Anyway, good to catch up with your adventures in technology, and I hope your recovery to full health is swift.

    73

    Wardy

    ReplyDelete