This is how I set up Raspberry Pi computers in my Mac OS X environment. Raspbian is a general purpose operating system for the Raspberry Pi computer.
On the Mac:
# Warning: make SURE this is the right disk number because all data will be destroyed.df -h sudo diskutil unmount /dev/disk1s1 sudo dd bs=1m if=Downloads/2015-09-24-raspbian-jessie.img of=/dev/rdisk1 sudo diskutil eject /dev/rdisk1 sudo raspi-config # expand file system, change user password, locale = NL.UTF8, timezone = Europe/Amsterdam, hostname = [case colour], reboot
Right-click desktop, preferences
Right-click menu bar, preferences, advanced, Minimise
On the Raspberry Pi:
sudo apt-get update && sudo apt-get -y dist-upgrade sudo rpi-update && sudo reboot mkdir bin mkdir public_html mkdir .pubkey mkdir .private chmod 600 [regular files in ~] chmod 700 [directories in ~, except Public / public_html / python_games] sudo chown root:root .private/ ssh-keygen ln -s .ssh/id_rsa.pub key.pub scp -p -P [ssh port] pi@[other pi]:.ssh/config .ssh/ scp -p [other pi]:.bash_aliases . . ./.bash_aliases nano .bashrc # comment out aliases scp key.pub [other pi]:.pubkey/[hostname] scp [other pi]:.pubkey/* .pubkey/ cat .pubkey/* >> .ssh/authorized_keys scp [other pi]:/usr/local/bin/* bin/ sudo mv bin/* /usr/local/bin/ scp [other pi]:bin/* bin/ scp [other pi]:/etc/init.d/shairport . nano shairport # edit AirPlay name sudo mv shairport /etc/init.d/ sudo update-rc.d shairport defaults 90 10 scp [other pi]:/etc/init.d/webcam . sudo mv webcam /etc/init.d/ sudo nano /etc/kbd/config # uncomment LEDS=+num sudo nano /etc/motd # empty sudo nano /etc/modules # add ipv6 sudo nano /etc/network/interfaces # wireless-power off sudo nano /etc/ssh/sshd_config # edit port, pwd auth = no sudo /etc/init.d/ssh restart sudo visudo # www-data [hostname] = (www-data) NOPASSWD: /sbin/shutdown, /usr/local/bin/startcam
Download the latest Raspbian OS image file.
Open a Terminal window. The Terminal application hides in the Utilities sub-folder of the Applications folder. (In Dutch: Programma's 〉 Hulpprogramma's.)
pwd to see in which folder you are,
cd NewFolderName to change to a different folder,
cd .. to go up to the parent folder,
ls to list the files and sub-folders in the current folder.cd Downloads and ls.df -h.df -h again, see which disk is new and note its name. It might be /dev/disk1s1. To double-check, look for the size in Gi (gigabyte) listed behind the disk name, which should correspond to the labeled SD card size (7.x for an 8 GB card).sudo diskutil unmount /dev/disk1s1. Instead of /dev/disk1s1, use the exact name you noted in the previous step.sudo dd bs=1m if=2013-07-26-wheezy-raspbian.img of=/dev/rdisk1. Triple-check for typos. Make sure you use the correct names in your situation for the input file (if=) and especially for the output file (of=). If you already had two or more disks or partitions connected to your system before inserting the SD card, its name will be /dev/rdisk2 or a higher number. In that case, /dev/rdisk1 might be a hard disk with all your important data … All existing data and formatting on the disk will be lost when writing to it using the low-level dd command! "This action cannot be undone."sudo diskutil eject /dev/rdisk1. Again, it might be disk2, 3 etc. for you.Physically remove the SD card from the reader/writer and insert it upside down into the Raspberry Pi. Plug in a keyboard, optionally a mouse, and connect the RPi to a monitor or TV. Attach an ethernet network cable to download updates. Wifi USB dongles might work out-of-the-box, and they might not … Finally, plug in the micro-USB cable and power up the RPi.
Check every setting in raspi-config, a text-mode configuration program which automatically starts on the first boot-up of Raspbian. Use the cursor keys and Tab to navigate, Enter to activate, Space to select. At the very least change the password (standard password for user pi is raspberry), then select reboot. After reboot, log in at the console if you chose not to boot to desktop, or open an LXTerminal window. Enable IPv6:
sudo modprobe ipv6 # To enable momentarily sudo nano /etc/modules # To enable always upon reboot, add line: ipv6 ifconfig # Check wget -6 http://www.google.com/ # Test
Enable NumLock in the console:
sudo nano /etc/kbd/config # Uncomment LEDS=+num
Remove or edit login message (MotD, message of the day):
sudo nano /etc/motd # Empty with Ctrl-k
Enable automatic connect to the WPA2 wireless network of my Apple Airport router, valid for both 2.4 and 5 GHz networks if they have the same name and password. Depending on the driver or system settings for your wifi dongle, you might need to change the router wifi channel on the 5 GHz band from automatic to manual (so that's a change on the router, not on the RPi). I had to do that for the Asus USB-N53 (RT3572 chipset), see my thread on the Raspberry Pi forum.
# This waits for you to type your wireless network password and Enter:
wpa_passphrase MyWirelessNetworkName | sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf
# Edit the network parameters …
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
# … like so:
network={
ssid="MyWirelessNetworkName"
psk=ALongStringOfHexadecimalDigits
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
group=CCMP
auth_alg=OPEN
}
Create Bash aliases:
nano ~/.bash_aliases # Edit like so: if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" alias ls='/bin/ls --color=auto' alias l='/bin/ls -oFh --color=auto' alias ll='/bin/ls -AoF --color=auto' alias la='/bin/ls -alF --color=auto' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' else alias l='/bin/ls -oFh' alias ll='/bin/ls -AoF' alias la='/bin/ls -alF' fi alias lo=logout alias scp='/usr/bin/scp -p'
System update:
sudo apt-get update && sudo apt-get -y dist-upgrade sudo rpi-update sudo reboot
Install extras:
# LAN / Mac-related essentials sudo apt-get install avahi-daemon avahi-utils netatalk hfsplus hfsprogs hfsutils # Basic tools sudo apt-get install locate dnsutils alsa-tools # Video / Graphics sudo apt-get install libav-tools imagemagick aview caca-utils fim # Graphs / Text sudo apt-get install gnuplot gnuplot-x11 texlive wv # Might be handy or fun sudo apt-get install numlockx x11-apps toilet mpd mpc sudo apt-get -y autoremove # Probably redundant sudo updatedb # For locate
Generate SSH keys for the user (as opposed to the host):
ssh-keygen ln -s ~/.ssh/id_rsa.pub ~/key.pub
Exchange public keys with other computers using scp, place in ~/.ssh/authorized_keys.
Optionally disable password-based login: sudo nano /etc/ssh/sshd_config, uncomment and edit: PasswordAuthentication no.
If you purchased MPEG-2 or VC-1 licence keys for this particular RPi:
sudo nano /boot/config.txt # Add line(s): decode_MPG2=0x01234567 decode_WVC1=0x89abcdef sudo reboot vcgencmd codec_enabled MPG2 # Test vcgencmd codec_enabled WVC1 # Test
I had trouble getting the right screen resolution on my TV when connected through an AV receiver.
I fixed it by referring to the
eLinux wiki,
sudo nano /boot/config.txt and uncommenting / editing:
# group 1: CEA (TV), group 2: DMT (monitor) # group 1 mode 2: 720x480@60 # group 1 mode 4: 1280x720@60 # group 1 mode 19: 1280x720@50 hdmi_group=1 hdmi_mode=19 # Mode 4 supported by TV but not by receiver :-( hdmi_force_hotplug=1 # Probably not needed hdmi_drive=2 # Probably not needed
Optionally fix audio output:
amixer cset numid=3 2 # Audio output: 0=auto (default), 1=jack, 2=hdmi
Optionally add a new user:
sudo adduser newname # Asks for password for the new user sudo visudo # Duplicate last line, replace pi with newname groups pi # See of which groups old user pi is a member sudo adduser newname audio # Add new user to one group # Add new user to all groups of pi except pi's own group for i in $(groups pi | sed 's/.*: //' | sed 's/^pi //'); do sudo adduser newname $i; done # Optionally change boot to desktop to new user sudo nano /etc/lightdm/lightdm.conf # Edit: autologin-user=newname
Download and build the application:
sudo apt-get install libssl-dev libavahi-client-dev libasound2-dev git clone -b 1.0-dev git://github.com/abrasive/shairport.git cd shairport ./configure make sudo mv shairport /usr/local/bin/
Save as /etc/init.d/shairport:
#!/bin/sh
### BEGIN INIT INFO
# Provides: shairport
# Required-Start: $remote_fs $syslog $network
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: AirTunes emulator
# Description: Controls shairport which emulates audio-only AirPlay.
### END INIT INFO
DESC="AirTunes emulator"
NAME=shairport
PIDFILE=/var/run/$NAME.pid
DAEMON=/usr/local/bin/$NAME
DAEMON_ARGS="-d -P $PIDFILE -l /var/log/$NAME.log -a PiTunes"
SCRIPTNAME=/etc/init.d/$NAME
[ -x "$DAEMON" ] || exit 0
. /lib/lsb/init-functions
do_start()
{
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
}
do_stop()
{
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
rm -f $PIDFILE
return "$RETVAL"
}
do_reload() {
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
:
Install the service:
sudo chmod 755 /etc/init.d/shairport sudo update-rc.d shairport defaults 90 10 sudo service shairport start # Manual start
Standard web server with Apache, Python, PHP, MySQL and phpMyAdmin:
sudo apt-get install apache2 apache2-doc libapache2-mod-python libapache2-mod-python-doc php5 php5-gd php5-mcrypt mysql mysql-server mysql-client sudo apt-get install phpmyadmin # Only install after finishing MySQL installation and configuration sudo a2enmod userdir sudo nano /etc/apache2/mods-available/php5.conf # Comment out userdir sudo apachectl restart
Lightweight web server with Lighttpd, PHP and SQLite:
sudo apt-get install lighttpd lighttpd-doc php5-cgi php5-cli php5-gd php5-mcrypt php5-sqlite apache2-utils sudo lighty-enable-mod fastcgi fastcgi-php accesslog dir-listing userdir sudo service lighttpd force-reload
Common:
mkdir ~/public_html echo '<?php phpinfo(); ?>' > ~/public_html/phpinfo.php
Go to http://raspberrypi/~pi/phpinfo.php to test. Depending on your RPi hostname and your router configuration, you may need to use another hostname, add a DNS suffix like .local or .lan, or use an IP address.
Cheers, boos and questions via the Raspberry Pi forum.