I have also been playing with 2 Raspberry PI's lately and occasionally have to reformat them and start again due to my mistakes or a pivot in the project I'm running. As we all know a bare install is like a pair of new shoes, it takes a while to get them how you like them and i generally forget about some infrequently used but vital tool until I need it and then have to break my flow to go grab it and install it, well no more!
Below is a short bash script that I can copy from here when I need it, past into a file & run to get the basics setup quickly, It will even grab my beloved .bashrc file and copy it to my home directory so i have access to all my aliases and have my command prompt just so.
#!/bin/bash
title="Linux Personalisation Script"
prompt="Pick an option:"
options=("Update Installation" "Upgrade Distribution" "Add user jamie & set password" "Edit group file" "Install Fortune, Git, Terminator(A Great Console), TTYtter(cli twitter client), VLC player" "Install Nvidia drivers" "Install LAMP Server (Apache2, PHP5, MySql)" "Get Fruitbats Custom .bashrc File" "Get xorg.conf " )
echo -e "${LIGHTCYAN}$title"
PS3="$prompt "
select opt in "${options[@]}" "Quit"; do
case "$REPLY" in
1 ) sudo apt-get update;;
2 ) sudo apt-get dist-upgrade;;
3 ) sudo sudo useradd -m jamie && sudo passwd jamie;;
4 ) sudo nano /etc/group;;
5 ) sudo apt-get install fortune-mod git-core terminator ttytter vlc vlc-plugin-pulse mozilla-plugin-vlc proftpd-basic dropbox && dropbox start -i ;;
6 ) sudo add-apt-repository ppa:ubuntu-x-swat/x-updates && sudo apt-get update && sudo apt-get install nvidia-current nvidia-settings;;
7 ) sudo apt-get install apache2 php5 libapache2-mod-php5 mysql-server libapache2-mod-auth-mysql php5-mysql phpmyadmin;;
8 ) cd /home/*/ && rm -f .bashrc && wget https://dl.dropbox.com/u/XXXXXXX/.bashrc;; ##save below script to your own dropbox
9 ) cd /etc/X11 wget https://dl.dropbox.com/u/17907226/xorg.conf;;
$(( ${#options[@]}+1 )) ) echo "Goodbye!"; break;;
*) echo "Invalid option. Try another one.";continue;;
esac
done
echo -e "${LIGHTCYAN} Well Done. Have the Bluemars.org stream as a reward. CTRL C to Exit Player."
echo "To hear more from bluemars.org just type bluemars at the prompt "
cvlc "http://207.200.96.225:8020/listen.pls"
endColor='\e[0m'
That's the basic script as you can see its nothing too fancy at the moment just a menu and some apt-get install's with an audio stream that plays on exit to test the VLC Player setup worked.
Below is the .bashrc script im so fond of. I included it here as most people will be wary of grabbing an unknown file and I wouldn't blame you if you commented out that line and menu entry. I cant take credit for a large chunk of the script below as I grabbed it from pastebin and tailored it to my own liking as i do with most code, I find it a good way to learn new code.
# .bashrc
# Imported by Fruitbats Linux-setup-script-v2
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
##################################
# _ _ _ #
# /_\ | (_) __ _ ___ ___ ___ #
# //_\\| | |/ _` / __|/ _ | __| #
# / _ \ | | (_| \__ \ __|__ \ #
# \_/ \_/_|_|\__,_|___/\___|___/ #
##################################
alias ut='tar -zxvf' # untar
alias t='tar -cvf' # to compress files with dates: t file-$(date +%F).tar
alias tsee='tar -tvf'
alias off="su -c 'shutdown -h now'"
alias restart="su -c 'reboot'"
alias x='exit'
alias cls='clear'
alias ..='cd ..'
alias ...='cd ../..'
alias pdir='cd $OLDPWD'
alias setup='sudo apt-get install'
alias install='sudo apt-get install'
alias docs='cd ~jc/Documents;ls -l'
alias downs='cd ~jc/Downloads;ls -l'
alias tailmsg='tail -f /var/log/messages'
alias t='todo.sh -d /home/jamie/Documents/todo/todo.cfg'
alias ..='cd ..'
alias sshpi='ssh jamie@192.168.1.42'
alias sshpi2='ssh jamie@192.168.1.40'
alias bluemars='cvlc "http://207.200.96.225:8020/listen.pls"'
# chmod and permissions commands
alias mx='chmod a+x'
alias mynet="su -c 'nmap -O -sS 192.168.1.0/24'"
alias pg='ps aux | grep' #requires an argument
#Use human-readable filesizes
alias du="du -h"
alias df="df -h"
#-------------------------------------------------------------
# The 'ls' family (this assumes you use a recent GNU ls)
#-------------------------------------------------------------
alias l='ls'
alias ll="ls -l --group-directories-first"
alias ls='ls -hF --color' # add colors for filetype recognition
alias la='ls -Al' # show hidden files
alias lx='ls -lXB' # sort by extension
alias lk='ls -lSr' # sort by size, biggest last
alias lc='ls -ltcr' # sort by and show change time, most recent last
alias lu='ls -ltur' # sort by and show access time, most recent last
alias lt='ls -ltr' # sort by date, most recent last
alias lm='ls -al |more' # pipe through 'more'
alias lr='ls -lR' # recursive ls
alias tree='tree -Csu' # nice alternative to 'recursive ls'
#-------------------------------------------------------------
# spelling typos - highly personnal and keyboard-dependent :-)
#-------------------------------------------------------------
alias xs='cd'
alias vf='cd'
alias moer='more'
alias moew='more'
alias kk='ll'
############################################################
# _____ _ ___ _ #
# /__ \ |__ ___ / _ \_ __ ___ _ __ ___ _ __ | |_ #
# / /\/ '_ \ / _ \ / /_)/ '__/ _ \| '_ ` _ \| '_ \| __| #
# / / | | | | __/ / ___/| | | (_) | | | | | | |_) | |_ #
# \/ |_| |_|\___| \/ |_| \___/|_| |_| |_| .__/ \__| #
# |_| #
############################################################
# Greeting, motd etc...
#-------------------------------------------------------------
# Define some colors first:
LIGHTGRAY='\e[0;37m'
LIGHTBLUE='\e[1;34m'
LIGHTGREEN='\e[1;32m'
LIGHTCYAN='\e[1;36m'
red='\e[0;31m'
RED='\e[1;31m'
blue='\e[0;34m'
BLUE='\e[1;34m'
cyan='\e[0;36m'
CYAN='\e[1;36m'
NORMAL='\[\033[00m\]'
NC='\e[0m' # No Color
PS1="$cyan[\u@\h] -> $LIGHTBLUE\w $NC \n \$ "
##################################################
# ___ _ _ #
# / __\_ _ _ __ ___| |_(_) ___ _ __ ___ #
# / _\ | | | | '_ \ / __| __| |/ _ \| '_ \/ __| #
# / / | |_| | | | | (__| |_| | (_) | | | \__ \ #
# \/ \__,_|_| |_|\___|\__|_|\___/|_| |_|___/ #
##################################################
# edit bashrc
ebash ()
{
cd;vim .bashrc
}
#source bashrc
sbash ()
{
source .bashrc
}
# grep for active process
function psgrep()
{
ps aux | grep -e $1
}
# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# Makes extraction easier
function extract() {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# Get Host Information
#-------------------------------------------------------------
function hostinfo() # Get current host related info.
{
echo -e "\nYou are logged on ${RED}$HOST"
echo -e "\nAdditionnal information:$NC " ; uname -a
echo -e "\n${RED}Users logged on:$NC " ; w -h
echo -e "\n${RED}Current date :$NC " ; date
echo -e "\n${RED}Machine stats :$NC " ; uptime
echo -e "\n${RED}Memory stats :$NC " ; free
my_ip 2>&- ;
echo -e "\n${RED}Local IP Address :$NC" ; echo ${MY_IP:-"Not connected"}
echo -e "\n${RED}ISP Address :$NC" ; echo ${MY_ISP:-"Not connected"}
echo -e "\n${RED}Open connections :$NC "; netstat -pan --inet;
echo
}
#-------------------------------------------------------------
# DNS and DHCP information
netinfo ()
{
echo "#############Network Information###############"
echo ""
egrep -i "interface|fixed-address|subnet-mask|domain-name-servers|dhcp-server-identifier|domain-name" /var/lib/dhclient/dhclient.leases
echo ""
echo "###############################################"
echo ""
echo "####Current Public IP Address########"
echo ""
myip=`lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g' `
echo "${myip}"
echo ""
echo "#####################################"
echo ""
}
#-------------------------------------------------------------
# Creates an archive from given directory
#-------------------------------------------------------------
mktar() { tar cvf "${1%%/}.tar" "${1%%/}/"; }
mktgz() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; }
mktbz() { tar cvjf "${1%%/}.tar.bz2" "${1%%/}/"; }
#-------------------------------------------------------------
export EDITOR=nano
export VISUAL=nano
#-----------------------------#
# WELCOME SCREEN #
#-----------------------------#
clear
echo -ne "${cyan}""Hello, $USER. today is, "; date
echo -e "${LIGHTGREEN}"; cal -3;
echo -e "${red}"; fortune;
echo -e "${cyan}"; uname -snmro ;
echo ""
#------------------------------
In closing the raspberry PI that I got, then ignored for months as I couldn't find a project for it, has turned out to be a great spur to learning a variety of other skills, so far I've made a dent in :-
- Learning python.
- Learning Bash scripting
- Started Codeacademy
- Learnt to solder
- Started to cross stitch this AdaFruit resistor chart/cushion cover