Skip to content

Commit 12ab919

Browse files
committed
Install scripts for deploying Coder to a fresh Raspbian build.
1 parent 8f4d49c commit 12ab919

File tree

20 files changed

+800
-137
lines changed

20 files changed

+800
-137
lines changed

coder-apps/common/auth/app/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
var mustache = require('mustache');
2222
var util = require('util');
2323
var fs = require('fs');
24-
var bcrypt = require('bcrypt');
24+
var bcrypt = require('bcrypt-nodejs');
2525

2626
//stores cache of password hash and device name
2727
var device_settings = {
@@ -534,6 +534,7 @@ exports.api_logout_handler = function( req, res ) {
534534

535535
var saveDeviceSettings = function() {
536536
err = fs.writeFileSync( process.cwd() + "/device.json", JSON.stringify(device_settings, null, 4), 'utf8' );
537+
fs.chmodSync(process.cwd() + '/device.json', '600');
537538
return err;
538539
};
539540

coder-apps/pi/auth/app/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ exports.api_logout_handler = function( req, res ) {
530530

531531
var saveDeviceSettings = function() {
532532
err = fs.writeFileSync( process.cwd() + "/device.json", JSON.stringify(device_settings, null, 4), 'utf8' );
533+
fs.chmodSync(process.cwd() + '/device.json', '600');
533534
return err;
534535
};
535536

coder-base/package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "coder-base",
3-
"description": "kid-friendly web programming environment for pi",
4-
"version": "0.0.1",
5-
"private": true,
6-
"dependencies": {
7-
"express": "3.1.0",
8-
"redis": "0.8.2",
9-
"mustache": "0.7.2",
10-
"consolidate": "0.8.0",
11-
"socket.io": "0.9.13",
12-
"express-params": "0.0.3",
13-
"bcrypt": "0.7.4",
14-
"connect": "*",
15-
"cookie": "*"
16-
}
3+
"description": "A simple way to make cool web things",
4+
"version": "0.0.7",
5+
"private": true,
6+
"dependencies": {
7+
"express": "3.1.0",
8+
"redis": "0.8.2",
9+
"mustache": "0.7.2",
10+
"consolidate": "0.8.0",
11+
"socket.io": "0.9.13",
12+
"express-params": "0.0.3",
13+
"bcrypt-nodejs": "*",
14+
"connect": "*",
15+
"cookie": "*"
16+
}
1717
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
echo "### Set up coder account."
3+
adduser --system --group coder
4+
echo ""
5+
6+
7+
echo "### Fetch the latest coder tree and install in /home/coder/coder-dist"
8+
su -s/bin/bash coder <<'EOF'
9+
cd /home/coder
10+
git clone https://github.com/googlecreativelab/coder.git coder-dist
11+
EOF
12+
echo ""
13+
14+
echo "### Changing directory to raspian install scripts."
15+
echo "### /home/coder/coder-dist/installer/stock_raspbian/scripts"
16+
cd /home/coder/coder-dist/installer/stock_raspbian/scripts
17+
echo ""
18+
19+
cat <<EOF
20+
21+
------------------------------------------------------------------
22+
Ready to install Coder on your Raspberry Pi!
23+
24+
The following command will:
25+
- Update your system packages and kernel to the latest version.
26+
- Configure your Pi for headless operation.
27+
- Install all Coder dependencies and 3rd party node modules.
28+
- Set up Coder to boot when your Pi is restarted.
29+
30+
To continue, run the following:
31+
32+
sudo ./install_all_coder.sh
33+
34+
35+
36+
EOF
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
echo "### Fetch all the latest Pi updates."
2+
apt-get -y update
3+
apt-get -y dist-upgrade
4+
echo ""
5+
6+
7+
echo "### Update the kernel and firmware to latest versions."
8+
rpi-update
9+
echo ""
10+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
echo "### Add ssh to start up."
3+
insserv ssh
4+
update-rc.d ssh enable
5+
echo ""
6+
7+
echo "### Install avahi daemon (enables mDNS/DNS-SD so you can connect to coder.local)."
8+
apt-get -y install avahi-daemon
9+
echo ""
10+
11+
echo "### Install dhcpd daemon (will be used to give addresses when in ad-hoc hotspot mode)."
12+
apt-get -y install isc-dhcp-server
13+
echo ""
14+
15+
echo "### Update dhcpd init.d script so it doesn't run by default."
16+
cp ../../../raspbian-addons/etc/init.d/isc-dhcp-server /etc/init.d/isc-dhcp-server
17+
insserv -r isc-dhcp-server
18+
echo ""
19+
20+
echo "### Set up wpaconfig group."
21+
addgroup --system wpaconfig
22+
adduser coder wpaconfig
23+
echo ""
24+
25+
echo "### Updating headless boot scripts."
26+
cp -rv ../../../raspbian-addons/boot/coder_settings/ /boot/
27+
28+
cp -v ../../../raspbian-addons/etc/iptables.up.rules /etc/
29+
cp -v ../../../raspbian-addons/etc/network/if-pre-up.d/* /etc/network/if-pre-up.d/
30+
cp -v ../../../raspbian-addons/etc/network/interfaces* /etc/network/
31+
32+
cp -v ../../../raspbian-addons/etc/default/* /etc/default/
33+
cp -v ../../../raspbian-addons/etc/dhcp/dhcpd.conf /etc/dhcp/
34+
cp -v ../../../raspbian-addons/etc/modprobe.d/* /etc/modprobe.d/
35+
36+
cp -v ../../../raspbian-addons/etc/wpa_supplicant/wpa_supplicant* /etc/wpa_supplicant/
37+
chown -v root:wpaconfig /etc/wpa_supplicant/wpa_supplicant*
38+
chmod -v 660 /etc/wpa_supplicant/wpa_supplicant*
39+
40+
cp -v ../../../raspbian-addons/etc/init.d/coder-daemon /etc/init.d/
41+
cp -v ../../../raspbian-addons/etc/init.d/generate-ssh-hostkeys /etc/init.d/
42+
cp -v ../../../raspbian-addons/etc/init.d/pull-coder-reset /etc/init.d/
43+
cp -v ../../../raspbian-addons/etc/init.d/pull-hostname /etc/init.d/
44+
cp -v ../../../raspbian-addons/etc/init.d/pull-net-interfaces /etc/init.d/
45+
cp -v ../../../raspbian-addons/etc/init.d/pull-wpa-supplicant /etc/init.d/
46+
47+
echo "### Add init scripts to start up routine."
48+
echo "Coder"
49+
insserv coder-daemon
50+
update-rc.d coder-daemon enable
51+
52+
echo "Auto ssh key regen"
53+
insserv generate-ssh-hostkeys
54+
update-rc.d generate-ssh-hostkeys enable
55+
56+
echo "Coder quick reset capability"
57+
insserv pull-coder-reset
58+
update-rc.d pull-coder-reset enable
59+
60+
echo "SD host configuration capability"
61+
insserv pull-hostname
62+
update-rc.d pull-hostname enable
63+
64+
echo "SD network interface configuration capability"
65+
insserv pull-net-interfaces
66+
update-rc.d pull-net-interfaces enable
67+
68+
echo "SD wireless configuration capability"
69+
insserv pull-wpa-supplicant
70+
update-rc.d pull-wpa-supplicant enable
71+
echo ""
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
echo "### Add coder user to [spi, gpio, audio] groups (device access that coder needs)."
3+
adduser coder spi
4+
adduser coder gpio
5+
adduser coder audio
6+
echo ""
7+
8+
echo "### Install redis."
9+
apt-get -y install redis-server
10+
cp -v ../../../raspbian-addons/etc/redis/redis.conf /etc/redis/redis.conf
11+
echo ""
12+
13+
echo "### Install nodejs and npm."
14+
#These are really old...
15+
#apt-get -y install nodejs npm
16+
mkdir tmp
17+
wget http://nodejs.org/dist/v0.10.8/node-v0.10.8-linux-arm-pi.tar.gz -P tmp/
18+
tar -zxv -C tmp/ -f tmp/node-v0.10.8-linux-arm-pi.tar.gz
19+
cp -rv tmp/node-v0.10.8-linux-arm-pi /opt/node
20+
ln -s /opt/node/bin/node /usr/bin/node
21+
ln -s /opt/node/bin/npm /usr/bin/npm
22+
rm -rf tmp
23+
echo ""
24+
25+
echo "### Installing Coder base apps (you can ignore any stat warnings)."
26+
su -s/bin/bash coder <<'EOF'
27+
cd /home/coder/coder-dist/coder-apps
28+
./install_pi.sh ../coder-base
29+
EOF
30+
echo ""
31+
32+
echo "### Adding Raspberry Pi Coder features."
33+
cp -rv ../../../raspbian-addons/home/coder/coder-dist/coder-base/sudo_scripts ../../../coder-base/
34+
chown root:root -Rv ../../../coder-base/sudo_scripts
35+
chmod -v 744 ../../../coder-base/sudo_scripts/*
36+
echo ""
37+
38+
echo "### Installing node.js modules."
39+
su -s/bin/bash coder <<'EOF'
40+
cd /home/coder/coder-dist/coder-base
41+
cp ../raspbian-addons/home/coder/coder-dist/coder-base/package.json .
42+
npm install
43+
EOF
44+
echo ""
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
These scripts are intended to assist with deploying the latest
2+
version of Coder on a clean, stock Raspbian system.
3+
4+
BEFORE PROCEEDING:
5+
You should have a coder user, group, and the coder environment
6+
installed in /home/coder/coder-dist
7+
8+
If you have not done this already, run the following commands
9+
first. Otherwise, proceed to the next step.
10+
11+
sudo ./coder_system_setup.sh
12+
13+
14+
15+
INSTALLING CODER:
16+
To update Raspbian with all the necessary changes for Coder
17+
to run, execute the following:
18+
19+
cd /home/coder/coder-dist/installer/stock_raspbian/scripts
20+
sudo ./install_all_coder.sh
21+
22+
This will update to the latest version of Raspbain, install
23+
the necessary dependencies, and make updates to the system
24+
to support headless booting and mDNS discovery.
25+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
# set up coder account
3+
adduser --system --group coder
4+
5+
6+
# fetch the latest coder tree
7+
su -s/bin/bash coder <<'EOF'
8+
cd /home/coder
9+
git clone https://github.com/googlecreativelab/coder.git coder-dist
10+
EOF
11+
12+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Allows the coder user to run a limited number of scripts as the root user.
2+
# This is used for changing the pi password and wireless settings, and for
3+
# rebooting the device from the Coder UI.
4+
5+
bash -c "echo 'coder ALL= NOPASSWD: /home/coder/coder-dist/coder-base/sudo_scripts/*' >>/etc/sudoers"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
bash ./00_latest_updates.sh
2+
bash ./01_headless_basics.sh
3+
bash ./02_coder_dependencies.sh
4+
5+
6+
cat <<EOF
7+
8+
9+
10+
11+
12+
==================================================================
13+
Coder installation is almost complete.
14+
15+
FINAL STEP:
16+
17+
In order for Coder to be able to update your password and wireless
18+
settings, it needs to have limited sudo access.
19+
If you haven't done this already, you can run the following command
20+
to grant this access to the coder user.
21+
22+
sudo ./grant_coder_sudo.sh
23+
24+
Do not run this command if you've already given sudo access to
25+
coder during a previous install.
26+
27+
EOF
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
127.0.0.1 localhost
2+
::1 localhost ip6-localhost ip6-loopback
3+
fe00::0 ip6-localnet
4+
ff00::0 ip6-mcastprefix
5+
ff02::1 ip6-allnodes
6+
ff02::2 ip6-allrouters
7+
8+
127.0.1.1 coder

raspbian-addons/etc/hostname

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coder

raspbian-addons/etc/hosts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
127.0.0.1 localhost
2+
::1 localhost ip6-localhost ip6-loopback
3+
fe00::0 ip6-localnet
4+
ff00::0 ip6-mcastprefix
5+
ff02::1 ip6-allnodes
6+
ff02::2 ip6-allrouters
7+
8+
127.0.1.1 coder

raspbian-addons/etc/init.d/generate-ssh-hostkeys

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,24 @@ logger="logger -t $prog"
1616

1717
rsa_key="/etc/ssh/ssh_host_rsa_key"
1818
dsa_key="/etc/ssh/ssh_host_dsa_key"
19+
ecdsa_key="/etc/ssh/ssh_host_ecdsa_key"
1920

2021
# Exit if the hostkeys already exist
21-
if [ -f $rsa_key -a -f $dsa_key ]; then
22+
if [ -f $rsa_key -a -f $dsa_key -a -f $ecdsa_key ]; then
2223
exit
2324
fi
2425

2526
# Generate the ssh host keys
2627
[ -f $rsa_key ] || ssh-keygen -f $rsa_key -t rsa -C 'host' -N ''
2728
[ -f $dsa_key ] || ssh-keygen -f $dsa_key -t dsa -C 'host' -N ''
29+
[ -f $ecdsa_key ] || ssh-keygen -f $ecdsa_key -t ecdsa -C 'host' -N ''
2830

2931
# Output the public keys to the console
3032
# This allows user to get host keys securely through console log
3133
echo "-----BEGIN SSH HOST KEY FINGERPRINTS-----" | $logger
3234
ssh-keygen -l -f $rsa_key.pub | $logger
3335
ssh-keygen -l -f $dsa_key.pub | $logger
36+
ssh-keygen -l -f $ecdsa_key.pub | $logger
3437
echo "------END SSH HOST KEY FINGERPRINTS------" | $logger
3538

3639

raspbian-addons/etc/init.d/isc-dhcp-server

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
# Required-Stop: $remote_fs $network $syslog
99
# Should-Start: $local_fs slapd $named
1010
# Should-Stop: $local_fs slapd
11-
# Default-Start:
12-
# Default-Stop:
11+
# Default-Start:
12+
# Default-Stop:
1313
# Short-Description: DHCP server
1414
# Description: Dynamic Host Configuration Protocol Server
1515
### END INIT INFO
1616

1717
##commented out only launching from wpa-supplicant
18-
# Default-Start: 2 3 4 5
19-
# Default-Stop: 0 1 6
18+
# ORIG-Start: 2 3 4 5
19+
# ORIG-Stop: 0 1 6
2020

2121
PATH=/sbin:/bin:/usr/sbin:/usr/bin
2222

0 commit comments

Comments
 (0)