Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeJS, a better "sethostname" and RPI3 Access Point+Station mode #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apst/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# RPI 3 WIFI AP + Station

The install script, `self-installer.sh` is a little special in that it
contains an embedded tar.gz "file" with the contents of `./etc` and `./files/installer`.
If you make any changes to `./etc` or to `./files/installer`, then run

```bash
./make-self-installer.sh
```

which will create a new `self-installer.sh`. Then re-import this block into PiBakery
to get the changes.
45 changes: 45 additions & 0 deletions apst/apst.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "apst",
"text": "Setup Access Point+Station\\nAP SSID: %1\\nAP Pass: %2\\nBridge AP to ST?: %3\\nST SSID: %4\\nST Pass: %5\\nST Type: %6",
"script": "self-installer.sh",
"args": [
{
"type": "text",
"default": "ap-ssid",
"maxLength":0
},
{
"type": "text",
"default": "ap-password",
"maxLength":0
},
{
"type": "menu",
"options": [ "yes", "no" ]
},
{
"type": "text",
"default": "st-ssid",
"maxLength":0
},
{
"type": "text",
"default": "st-password",
"maxLength":0
},
{
"type": "menu",
"options": ["WPA/WPA2", "WEP", "Open (no password)"]
}
],
"network": false,
"continue": true,
"type": "network",
"category":"network",
"supportedOperatingSystems": [
"raspbian-pibakery.img",
"raspbian-lite-pibakery.img"
],
"shortDescription":"Set up Access Point + Station mode",
"longDescription":"This block allows you to enter a WiFi network name and password, and then your Raspberry Pi will automatically connect to that network when it is first switched on. It also creates a WiFi hotspot (access point) that (optionally) bridges traffic to the client interface."
}
20 changes: 20 additions & 0 deletions apst/etc/default/hostapd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Defaults for hostapd initscript
#
# See /usr/share/doc/hostapd/README.Debian for information about alternative
# methods of managing hostapd.
#
# Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration
# file and hostapd will be started during system boot. An example configuration
# file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz
#
DAEMON_CONF="/etc/hostapd/hostapd.conf"

# Additional daemon options to be appended to hostapd command:-
# -d show more debug messages (-dd for even more)
# -K include key data in debug messages
# -t include timestamps in some debug messages
#
# Note that -B (daemon mode) and -P (pidfile) options are automatically
# configured by the init.d script and must not be added to DAEMON_OPTS.
#
#DAEMON_OPTS=""
5 changes: 5 additions & 0 deletions apst/etc/dnsmasq.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface=lo,uap0
no-dhcp-interface=lo,wlan0
bind-interfaces
server=8.8.8.8
dhcp-range=10.3.141.50,10.3.141.255,12h
12 changes: 12 additions & 0 deletions apst/etc/hostapd/hostapd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
interface=uap0
ssid=_AP_SSID_
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=_AP_PASSWORD_
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
23 changes: 23 additions & 0 deletions apst/etc/network/interfaces
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug uap0
auto uap0
iface uap0 inet static
address 10.3.141.1
netmask 255.255.255.0

3 changes: 3 additions & 0 deletions apst/etc/udev/rules.d/90-wireless.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ACTION=="add", SUBSYSTEM=="ieee80211", KERNEL=="phy0", \
RUN+="/sbin/iw phy %k interface add uap0 type __ap"

8 changes: 8 additions & 0 deletions apst/etc/wpa_supplicant/wpa_supplicant-none.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
country=GB

network={
ssid="_ST_SSID_"
scan_ssid=1
key_mgmt=NONE
}
9 changes: 9 additions & 0 deletions apst/etc/wpa_supplicant/wpa_supplicant-wep.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
country=GB

network={
ssid="_ST_SSID_"
scan_ssid=1
key_mgmt=NONE
wep_key0="_ST_PASSWORD_"
}
9 changes: 9 additions & 0 deletions apst/etc/wpa_supplicant/wpa_supplicant-wpa.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
country=GB

network={
ssid="_ST_SSID_"
scan_ssid=1
psk="_ST_PASSWORD_"
key_mgmt=WPA-PSK
}
9 changes: 9 additions & 0 deletions apst/etc/wpa_supplicant/wpa_supplicant.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
country=GB

network={
ssid="_ST_SSID_"
scan_ssid=1
psk="_ST_PASSWORD_"
key_mgmt=WPA-PSK
}
83 changes: 83 additions & 0 deletions apst/files/installer
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash
#
# Called by the self extracting installer. Everything we need
# is in ./etc. Parse arguments, do the substitutions and install
# the files.
#
ap_ssid="$1"
ap_password="$2"
ap_bridge="$3"
st_ssid="$4"
st_password="$5"
st_type="$6"

function wait_for_network {
for ((i=0;i<50;i++)); do
ping -w 1 8.8.8.8 >/dev/null 2>&1
if [ $? -eq 0 ]
then
sleep 1
break
fi
sleep 4
done
}

function enable_station {
if [ "$st_type" = "Open (no password)" ]; then
cat etc/wpa_supplicant/wpa_supplicant-none.conf | \
sed "s/_ST_SSID_/$st_ssid/g" > /etc/wpa_supplicant/wpa_supplicant.conf
elif [ "$st_type" = "WEP" ]; then
cat etc/wpa_supplicant/wpa_supplicant-wep.conf | \
sed "s/_ST_SSID_/$st_ssid/g" | \
sed "s/_ST_PASSWORD_/$st_password/g" > /etc/wpa_supplicant/wpa_supplicant.conf
else
cat etc/wpa_supplicant/wpa_supplicant-wpa.conf | \
sed "s/_ST_SSID_/$st_ssid/g" | \
sed "s/_ST_PASSWORD_/$st_password/g" > /etc/wpa_supplicant/wpa_supplicant.conf
fi
wpa_cli reconfigure
wait_for_network
}

function packages {
export DEBIAN_FRONTEND=noninteractive
apt-get update && apt-get install -q -y hostapd dnsmasq iptables-persistent
}

function install_device {
cp etc/network/interfaces /etc/network/interfaces
cp etc/udev/rules.d/90-wireless.rules /etc/udev/rules.d/90-wireless.rules
/sbin/iw phy phy0 interface add uap0 type __ap
}

function copy_ap_files {
cp etc/default/hostapd /etc/default/hostapd
cp etc/dnsmasq.conf /etc/dnsmasq.conf
cat etc/hostapd/hostapd.conf | \
sed "s/_AP_SSID_/$ap_ssid/g" | \
sed "s/_AP_PASSWORD_/$ap_password/g" > /etc/hostapd/hostapd.conf
}

function bridge {
if [ "$ap_bridge" = "yes" ]; then
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -i wlan0 -o uap0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i uap0 -o wlan0 -j ACCEPT
iptables-save > /etc/iptables/rules.v4
fi
}

function restart_services {
systemctl restart dnsmasq
systemctl restart hostapd
}

install_device && \
enable_station && \
packages && \
copy_ap_files && \
bridge && \
restart_services
21 changes: 21 additions & 0 deletions apst/files/self-installer-header.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
echo ""
echo "Self Extracting Installer"
echo ""

export TMPDIR=`mktemp -d /tmp/selfextract.XXXXXX`

ARCHIVE=`awk '/^__ARCHIVE_BELOW__/ {print NR + 1; exit 0; }' $0`

tail -n+$ARCHIVE $0 | tar xzv -C $TMPDIR

CDIR=`pwd`
cd $TMPDIR
./installer "$@"

cd $CDIR
rm -rf $TMPDIR

exit 0

__ARCHIVE_BELOW__
13 changes: 13 additions & 0 deletions apst/make-self-installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
#
# Remake self-installer.sh after making any changes to etc/* or files/*
#
mkdir /tmp/se
cp -r etc /tmp/se/etc
cp files/installer /tmp/se
(cd /tmp/se; tar zcf /tmp/files.tar.gz .)
rm -rf /tmp/se
cat files/self-installer-header.sh /tmp/files.tar.gz > self-installer.sh
chmod +x self-installer.sh
rm -f /tmp/files.tar.gz

Binary file added apst/self-installer.sh
Binary file not shown.
22 changes: 22 additions & 0 deletions dnshostname/dnshostname.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "dnshostname",
"text": "Set hostname to %1",
"script": "sethostname.sh",
"args": [
{
"type": "text",
"default": "raspberrypi",
"maxLength":0
}
],
"network": false,
"continue": true,
"type": "setting",
"category":"setting",
"supportedOperatingSystems": [
"raspbian-pibakery.img",
"raspbian-lite-pibakery.img"
],
"shortDescription":"Change the full hostname of the Raspberry Pi",
"longDescription":"By default, the hostname of the Raspberry Pi is \"raspberry\". If you've got multiple Raspberry Pis, you'll want to set each of them to a unique name to avoid confusion, and you may want to change your hostname anyway. THIS BLOCK ALSO CHANGES THE DNS NAME THAT IS BROADCASTED."
}
5 changes: 5 additions & 0 deletions dnshostname/sethostname.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

raspi-config nonint do_hostname "$1"
hostname -b "$1"
systemctl restart avahi-daemon
7 changes: 7 additions & 0 deletions nodejs/node-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

version="$1"

curl -sL https://deb.nodesource.com/setup_$version | sudo bash -
apt-get install nodejs -y

21 changes: 21 additions & 0 deletions nodejs/nodejs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "nodejs",
"text": "Install NodeJS\\nversion: %1\\nRequires internet connection",
"script": "node-install.sh",
"args": [
{
"type": "menu",
"options": ["4.x", "5.x", "6.x", "7.x", "8.x", "9.x"]
}
],
"network": true,
"continue": true,
"type": "software",
"category":"software",
"supportedOperatingSystems": [
"raspbian-pibakery.img",
"raspbian-lite-pibakery.img"
],
"shortDescription":"Install NodeJS",
"longDescription":"Install ytour favorite version of node."
}