|
|
@@ -0,0 +1,92 @@
|
|
|
+#!/usr/bin/env bash
|
|
|
+
|
|
|
+set -e
|
|
|
+
|
|
|
+main(){
|
|
|
+ apt-get update
|
|
|
+
|
|
|
+ echo $SOURCE_HOSTAPD | base64 -d > /opt/hostapd.deb
|
|
|
+ dpkg -i /opt/hostapd.deb
|
|
|
+ mkdir -p /etc/hostapd/
|
|
|
+ cp /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.orig
|
|
|
+ cat << 'EOF' > /etc/hostapd/hostapd.conf
|
|
|
+interface=wlan0
|
|
|
+driver=nl80211
|
|
|
+ssid=raspberry
|
|
|
+hw_mode=g
|
|
|
+channel=6
|
|
|
+ieee80211n=1
|
|
|
+wmm_enabled=1
|
|
|
+ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
|
|
|
+macaddr_acl=0
|
|
|
+auth_algs=1
|
|
|
+ignore_broadcast_ssid=0
|
|
|
+wpa=2
|
|
|
+wpa_key_mgmt=WPA-PSK
|
|
|
+wpa_passphrase=raspberry
|
|
|
+rsn_pairwise=CCMP
|
|
|
+EOF
|
|
|
+
|
|
|
+ sed -e "s/DAEMON_CONF=\".*/\/etc\/hostapd\/hostapd.conf/" /etc/default/hostapd
|
|
|
+
|
|
|
+ cat << 'EOF' > /etc/dnsmasq.d/bootstrap_portal.conf
|
|
|
+interface=wlan0
|
|
|
+listen-address=192.168.5.1
|
|
|
+bind-interfaces
|
|
|
+server=8.8.8.8
|
|
|
+domain-needed
|
|
|
+bogus-priv
|
|
|
+dhcp-range=192.168.5.100,192.168.5.200,24h
|
|
|
+EOF
|
|
|
+
|
|
|
+ cat << 'EOF' > /etc/systemd/system/bootstap_portal
|
|
|
+[Unit]
|
|
|
+Description=
|
|
|
+After=network.target
|
|
|
+StartLimitIntervalSec=0[Service]
|
|
|
+Type=simple
|
|
|
+Restart=always
|
|
|
+RestartSec=1
|
|
|
+User=centos
|
|
|
+ExecStart=/usr/local/bin/bootstrap_portal.sh serve
|
|
|
+
|
|
|
+[Install]
|
|
|
+WantedBy=multi-user.target
|
|
|
+EOF
|
|
|
+
|
|
|
+ systemctl daemon-reload
|
|
|
+ systemctl disable dhcpcd
|
|
|
+ systemctl enable hostapd dnsmasq bootstrap_portal
|
|
|
+ cp $0 /usr/local/bin/bootstap_portal.sh
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+bootstrap_serve(){
|
|
|
+ mkdir -p /tmp/bootstrap_portal/cgi-bin
|
|
|
+ cd /tmp/bootstrap_portal/
|
|
|
+ cat << 'EOF' > index.html
|
|
|
+<html>
|
|
|
+ <head>
|
|
|
+ <script>
|
|
|
+ </script>
|
|
|
+ </head>
|
|
|
+ <body>
|
|
|
+ <h1>Hello World<h1>
|
|
|
+ </body>
|
|
|
+</html>
|
|
|
+EOF
|
|
|
+ cat << 'EOF' > cgi-bin/api.cgi
|
|
|
+#!/usr/bin/env python3
|
|
|
+import json
|
|
|
+
|
|
|
+EOF
|
|
|
+ python3 -m http.server --cgi 80
|
|
|
+}
|
|
|
+
|
|
|
+if [ "$1" == "serve" ]
|
|
|
+then
|
|
|
+ bootstrap_serve
|
|
|
+else
|
|
|
+ main
|
|
|
+fi
|
|
|
+
|