diff --git a/apst/README.md b/apst/README.md new file mode 100644 index 0000000..8af184b --- /dev/null +++ b/apst/README.md @@ -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. diff --git a/apst/apst.json b/apst/apst.json new file mode 100644 index 0000000..a07d019 --- /dev/null +++ b/apst/apst.json @@ -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." +} diff --git a/apst/etc/default/hostapd b/apst/etc/default/hostapd new file mode 100644 index 0000000..5783c15 --- /dev/null +++ b/apst/etc/default/hostapd @@ -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="" diff --git a/apst/etc/dnsmasq.conf b/apst/etc/dnsmasq.conf new file mode 100644 index 0000000..34d11eb --- /dev/null +++ b/apst/etc/dnsmasq.conf @@ -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 diff --git a/apst/etc/hostapd/hostapd.conf b/apst/etc/hostapd/hostapd.conf new file mode 100644 index 0000000..e14e11d --- /dev/null +++ b/apst/etc/hostapd/hostapd.conf @@ -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 diff --git a/apst/etc/network/interfaces b/apst/etc/network/interfaces new file mode 100644 index 0000000..9691e70 --- /dev/null +++ b/apst/etc/network/interfaces @@ -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 + diff --git a/apst/etc/udev/rules.d/90-wireless.rules b/apst/etc/udev/rules.d/90-wireless.rules new file mode 100644 index 0000000..a5aac57 --- /dev/null +++ b/apst/etc/udev/rules.d/90-wireless.rules @@ -0,0 +1,3 @@ +ACTION=="add", SUBSYSTEM=="ieee80211", KERNEL=="phy0", \ + RUN+="/sbin/iw phy %k interface add uap0 type __ap" + diff --git a/apst/etc/wpa_supplicant/wpa_supplicant-none.conf b/apst/etc/wpa_supplicant/wpa_supplicant-none.conf new file mode 100644 index 0000000..de4d47b --- /dev/null +++ b/apst/etc/wpa_supplicant/wpa_supplicant-none.conf @@ -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 +} diff --git a/apst/etc/wpa_supplicant/wpa_supplicant-wep.conf b/apst/etc/wpa_supplicant/wpa_supplicant-wep.conf new file mode 100644 index 0000000..a17e287 --- /dev/null +++ b/apst/etc/wpa_supplicant/wpa_supplicant-wep.conf @@ -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_" +} diff --git a/apst/etc/wpa_supplicant/wpa_supplicant-wpa.conf b/apst/etc/wpa_supplicant/wpa_supplicant-wpa.conf new file mode 100644 index 0000000..e375044 --- /dev/null +++ b/apst/etc/wpa_supplicant/wpa_supplicant-wpa.conf @@ -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 +} diff --git a/apst/etc/wpa_supplicant/wpa_supplicant.conf b/apst/etc/wpa_supplicant/wpa_supplicant.conf new file mode 100644 index 0000000..e375044 --- /dev/null +++ b/apst/etc/wpa_supplicant/wpa_supplicant.conf @@ -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 +} diff --git a/apst/files/installer b/apst/files/installer new file mode 100755 index 0000000..77158bb --- /dev/null +++ b/apst/files/installer @@ -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 diff --git a/apst/files/self-installer-header.sh b/apst/files/self-installer-header.sh new file mode 100644 index 0000000..9108007 --- /dev/null +++ b/apst/files/self-installer-header.sh @@ -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__ diff --git a/apst/make-self-installer.sh b/apst/make-self-installer.sh new file mode 100755 index 0000000..538b7d0 --- /dev/null +++ b/apst/make-self-installer.sh @@ -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 + diff --git a/apst/self-installer.sh b/apst/self-installer.sh new file mode 100755 index 0000000..c36ab60 Binary files /dev/null and b/apst/self-installer.sh differ diff --git a/dnshostname/dnshostname.json b/dnshostname/dnshostname.json new file mode 100644 index 0000000..ef67e2b --- /dev/null +++ b/dnshostname/dnshostname.json @@ -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." +} diff --git a/dnshostname/sethostname.sh b/dnshostname/sethostname.sh new file mode 100755 index 0000000..51c26ea --- /dev/null +++ b/dnshostname/sethostname.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +raspi-config nonint do_hostname "$1" +hostname -b "$1" +systemctl restart avahi-daemon diff --git a/nodejs/node-install.sh b/nodejs/node-install.sh new file mode 100755 index 0000000..5941b27 --- /dev/null +++ b/nodejs/node-install.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +version="$1" + +curl -sL https://deb.nodesource.com/setup_$version | sudo bash - +apt-get install nodejs -y + diff --git a/nodejs/nodejs.json b/nodejs/nodejs.json new file mode 100644 index 0000000..604ee2f --- /dev/null +++ b/nodejs/nodejs.json @@ -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." +}