Tobias Simetsreiter 4 gadi atpakaļ
vecāks
revīzija
c995cff31f
6 mainītis faili ar 142 papildinājumiem un 0 dzēšanām
  1. 2 0
      .gitignore
  2. 17 0
      Makefile
  3. 10 0
      sharxz.sh
  4. 92 0
      src/bootstrap_captive.sh
  5. 4 0
      src/install.sh
  6. 17 0
      unsharxz.sh

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+src/hostapd.deb
+build

+ 17 - 0
Makefile

@@ -0,0 +1,17 @@
+
+
+.PHONY: build
+build: build/bootstrap_captive_bundle.sh
+
+
+build/bootstrap_captive_bundle.sh:
+	mkdir -p build
+	./sharxz.sh src/ ${@}.tmp
+	mv ${@}.tmp ${@}
+
+HOSTAPD_URL="http://ftp.de.debian.org/debian/pool/main/w/wpa/hostapd_2.7+git20190128+0c1e29f-6+deb10u2_armhf.deb"
+hostapd:
+	curl -L -o src/hostapd.deb "${HOSTAPD_URL}"
+
+clean:
+	rm -rf build

+ 10 - 0
sharxz.sh

@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+
+set -e
+set -x
+
+dd if=/dev/zero of=$2 bs=512 count=1
+dd of=$2 if=./unsharxz.sh conv=notrunc
+tar -cC $1 .| xz -c -T 0 >> $2
+chmod +x $2
+

+ 92 - 0
src/bootstrap_captive.sh

@@ -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
+

+ 4 - 0
src/install.sh

@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+
+env
+pwd

+ 17 - 0
unsharxz.sh

@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+
+set -e
+set +x
+
+TMPDIR=$(mktemp -d)
+
+dd if=$0 bs=512 skip=1 |xz -d -T 0 |tar -xC $TMPDIR
+
+export SELF_INSTALLER=$(realpath $0)
+cd $TMPDIR
+./install.sh $@
+EXITCODE=$?
+rm -r $TMPDIR
+exit $EXITCODE
+
+cat <<SAFEPAYLOADEOF > /dev/null