Sfoglia il codice sorgente

split config files

Tobias Simetsreiter 4 anni fa
parent
commit
6217ace6a5
12 ha cambiato i file con 147 aggiunte e 98 eliminazioni
  1. 1 1
      .gitignore
  2. 4 3
      Makefile
  3. 7 4
      sharxz.sh
  4. 14 0
      src/bootstrap_captive.service
  5. 5 84
      src/bootstrap_captive.sh
  6. 7 0
      src/dnsmasq.conf
  7. 15 0
      src/hostapd.conf
  8. 3 0
      src/http/cgi-bin/api.cgi
  9. 9 0
      src/http/index.html
  10. 28 2
      src/install.sh
  11. 50 0
      src/main.py
  12. 4 4
      unsharxz.sh

+ 1 - 1
.gitignore

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

+ 4 - 3
Makefile

@@ -4,14 +4,15 @@
 build: build/bootstrap_captive_bundle.sh
 
 
-build/bootstrap_captive_bundle.sh:
+build/bootstrap_captive_bundle.sh: src src/blob/hostapd.deb
 	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}"
+src/blob/hostapd.deb:
+	mkdir -p src/blob
+	curl -L -o "${@}" "${HOSTAPD_URL}"
 
 clean:
 	rm -rf build

+ 7 - 4
sharxz.sh

@@ -3,8 +3,11 @@
 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
+INDIR=$1
+OUTFILE=$2
+
+dd if=/dev/zero of=$OUTFILE bs=512 count=1
+dd of=$OUTFILE if=./unsharxz.sh conv=notrunc
+tar -cC $INDIR .| xz -c -T 0 >> $OUTFILE
+chmod +x $OUTFILE
 

+ 14 - 0
src/bootstrap_captive.service

@@ -0,0 +1,14 @@
+[Unit]
+Description=A Captive Portal for Raspberry Setup
+After=network.target
+StartLimitIntervalSec=0
+
+[Service]
+Type=simple
+Restart=always
+RestartSec=1
+User=centos
+ExecStart=/usr/local/bin/bootstrap_portal serve
+
+[Install]
+WantedBy=multi-user.target

+ 5 - 84
src/bootstrap_captive.sh

@@ -2,91 +2,12 @@
 
 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>
+TMPDIR=$(mktemp -d)
+cd $TMPDIR
+cat << 'EOF' > index.html
 EOF
-    cat << 'EOF' > cgi-bin/api.cgi
-#!/usr/bin/env python3
-import json
 
+mkdir -p cgi-bin
+cat << 'EOF' > cgi-bin/api.cgi
 EOF
-    python3 -m http.server --cgi 80
-}
-
-if [ "$1" == "serve" ]
-then
-    bootstrap_serve
-else
-    main
-fi
 

+ 7 - 0
src/dnsmasq.conf

@@ -0,0 +1,7 @@
+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

+ 15 - 0
src/hostapd.conf

@@ -0,0 +1,15 @@
+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   

+ 3 - 0
src/http/cgi-bin/api.cgi

@@ -0,0 +1,3 @@
+#!/usr/bin/env python3
+import json
+

+ 9 - 0
src/http/index.html

@@ -0,0 +1,9 @@
+<html>
+ <head>
+ <script>
+ </script>
+ </head>
+ <body>
+   <h1>Hello World<h1>
+ </body>
+</html>

+ 28 - 2
src/install.sh

@@ -1,4 +1,30 @@
 #!/usr/bin/env bash
 
-env
-pwd
+set -e
+ls -alh
+
+INSTALL_DIR="/opt/eu.tsimnet.git/dasimmet/raspi-captive-bootstrap"
+mkdir -p "$INSTALL_DIR/"
+rsync -a ./ "$INSTALL_DIR/"
+
+echo "Ending Install"
+exit 0
+dpkg -i hostapd.deb
+mkdir -p /etc/hostapd/
+cp /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.orig
+cp hostapd.conf /etc/hostapd/hostapd.conf
+cp bootstrap_portal.service /etc/systemd/system/
+
+sed -e "s/DAEMON_CONF=\".*/\/etc\/hostapd\/hostapd.conf/" /etc/default/hostapd
+
+cat << 'EOF' > /etc/dnsmasq.d/bootstrap_portal.conf
+EOF
+
+cat << 'EOF' > /etc/systemd/system/bootstap_portal
+EOF
+
+systemctl daemon-reload
+systemctl disable dhcpcd
+systemctl enable hostapd dnsmasq bootstrap_portal
+cp $0 /usr/local/bin/bootstap_portal.sh
+

+ 50 - 0
src/main.py

@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+
+import os
+realp = os.path.realpath(os.path.dirname(__file__))
+
+def main():
+    p = parser()
+    args = p.parse_args()
+    if "func" in args:
+        return args.func(args)
+    else:
+        p.print_help()
+
+def parser():
+    from argparse import ArgumentParser
+    p = ArgumentParser()
+    sub = p.add_subparsers()
+    p_serve = sub.add_parser("serve")
+    p_serve.set_defaults(func=com_serve)
+    p_install = sub.add_parser("install")
+    p_install.set_defaults(func=com_install)
+    p_install.add_argument("-i", "--install_dir", default="/opt/eu.tsimnet.git/dasimmet/bootstrap_captive")
+    return p
+
+def com_install(args):
+    import os
+    if not "UNSHARXZ_INSTALLER" in os.environ:
+        print("Installer not found in Environment")
+    installer = os.environ["UNSHARXZ_INSTALLER"]
+    print("Installer: ", installer)
+    COM="""
+set -e
+set -x
+pwd
+mkdir -p "{1}"
+printf "#!/usr/bin/env sh\n\ncd {1} && ./main.py \\$@" > "/usr/local/bin/bootstrap_captive"
+cp -aT "." "{1}"
+chmod +x "/usr/local/bin/bootstrap_captive"
+
+""".format(installer,args.install_dir)
+    from subprocess import run
+    run(COM, shell=True, check=True)
+
+def com_serve(args):
+    COM=["python3", "-m", "http.server", "--cgi", "8080"]
+    from subprocess import run
+    run(COM, cwd="http", check=True)
+
+if __name__=="__main__":
+    main()

+ 4 - 4
unsharxz.sh

@@ -5,13 +5,13 @@ set +x
 
 TMPDIR=$(mktemp -d)
 
-dd if=$0 bs=512 skip=1 |xz -d -T 0 |tar -xC $TMPDIR
+dd if=$0 bs=512 skip=1 2>/dev/null |xz -d -T 0 |tar -xC $TMPDIR
 
-export SELF_INSTALLER=$(realpath $0)
+export UNSHARXZ_INSTALLER=$(realpath $0)
 cd $TMPDIR
-./install.sh $@
+./main.py $@
 EXITCODE=$?
 rm -r $TMPDIR
 exit $EXITCODE
 
-cat <<SAFEPAYLOADEOF > /dev/null
+# cat <<SAFEPAYLOADEOF > /dev/null