#!/bin/sh
wget -O- https://dev.ffnw.de/modules/l2tp/gluon-ffnw-20211030/ramips/mt76x8/block-mount_2020-05-12-84269037-1_mipsel_24kc.ipk | ssh root@192.168.1.1 "cat >/tmp/block-mount.ipk"
wget -O- https://downloads.openwrt.org/releases/19.07-SNAPSHOT/packages/mipsel_24kc/base/libuuid1_2.34-1_mipsel_24kc.ipk | ssh root@192.168.1.1 "cat >/tmp/libuuid1.ipk"
wget -O- https://downloads.openwrt.org/releases/19.07-SNAPSHOT/packages/mipsel_24kc/base/libblkid1_2.34-1_mipsel_24kc.ipk | ssh root@192.168.1.1 "cat >/tmp/libblkid1.ipk"
wget -O- https://downloads.openwrt.org/releases/19.07-SNAPSHOT/packages/mipsel_24kc/base/libss2_1.44.5-2_mipsel_24kc.ipk | ssh root@192.168.1.1 "cat >/tmp/libss2.ipk"
wget -O- https://downloads.openwrt.org/releases/19.07-SNAPSHOT/packages/mipsel_24kc/base/libcomerr0_1.44.5-2_mipsel_24kc.ipk | ssh root@192.168.1.1 "cat >/tmp/libcomerr0.ipk"
wget -O- https://downloads.openwrt.org/releases/19.07-SNAPSHOT/packages/mipsel_24kc/base/libext2fs2_1.44.5-2_mipsel_24kc.ipk | ssh root@192.168.1.1 "cat >/tmp/libext2fs2.ipk"
wget -O- https://downloads.openwrt.org/releases/19.07-SNAPSHOT/packages/mipsel_24kc/base/e2fsprogs_1.44.5-2_mipsel_24kc.ipk | ssh root@192.168.1.1 "cat >/tmp/e2fsprogs.ipk"
wget -O- https://dev.ffnw.de/modules/l2tp/gluon-ffnw-20211030/ramips/mt76x8/kmod-fs-ext4_4.14.245-1_mipsel_24kc.ipk | ssh root@192.168.1.1 "cat >/tmp/kmod-fs-ext4.ipk"
wget -O- https://dev.ffnw.de/modules/l2tp/gluon-ffnw-20211030/ramips/mt76x8/kmod-scsi-core_4.14.245-1_mipsel_24kc.ipk | ssh root@192.168.1.1 "cat >/tmp/kmod-scsi-core.ipk"
wget -O- https://dev.ffnw.de/modules/l2tp/gluon-ffnw-20211030/ramips/mt76x8/kmod-usb-storage_4.14.245-1_mipsel_24kc.ipk | ssh root@192.168.1.1 "cat >/tmp/kmod-usb-storage.ipk"
wget -O- https://dev.ffnw.de/modules/l2tp/gluon-ffnw-20211030/ramips/mt76x8/kmod-usb2_4.14.245-1_mipsel_24kc.ipk | ssh root@192.168.1.1 "cat >/tmp/kmod-usb2.ipk"
wget -O- https://dev.ffnw.de/modules/l2tp/gluon-ffnw-20211030/ramips/mt76x8/kmod-usb3_4.14.245-1_mipsel_24kc.ipk | ssh root@192.168.1.1 "cat >/tmp/kmod-usb3.ipk"

ssh root@192.168.1.1 <<EOF
opkg install \
/tmp/block-mount.ipk \
/tmp/libuuid1.ipk \
/tmp/libblkid1.ipk \
/tmp/libss2.ipk \
/tmp/libcomerr0.ipk \
/tmp/libext2fs2.ipk \
/tmp/e2fsprogs.ipk \
/tmp/kmod-fs-ext4.ipk \
/tmp/kmod-scsi-core.ipk \
/tmp/kmod-usb-storage.ipk \
/tmp/kmod-usb2.ipk \
/tmp/kmod-usb3.ipk && \
block detect | uci import fstab && \
uci set fstab.@mount[0].enabled='1' && uci set fstab.@global[0].anon_mount='1' && uci commit fstab && \
/etc/init.d/fstab boot && \
mkdir -p /mnt/sda1/v1/l2tp/stable

gluon-switch-domain landkreis_wittmund_sued

uci set uhttpd.firmware=uhttpd
uci set uhttpd.firmware.max_connections='100'
uci set uhttpd.firmware.network_timeout='30'
uci set uhttpd.firmware.http_keepalive='20'
uci set uhttpd.firmware.tcp_keepalive='1'
uci set uhttpd.firmware.home='/mnt/sda1'
uci set uhttpd.firmware.max_requests='32'
uci add_list uhttpd.firmware.listen_http='0.0.0.0:80'
uci add_list uhttpd.firmware.listen_http='[::]:80'
uci del_list uhttpd.main.listen_http='0.0.0.0:80'
uci del_list uhttpd.main.listen_http='[::]:80'
uci add_list uhttpd.main.listen_http='0.0.0.0:8080'
uci add_list uhttpd.main.listen_http='[::]:8080'
uci commit uhttpd

uci set dhcp.autoupdate=domain
uci set dhcp.autoupdate.name='autoupdate-lede.ffnw'
uci set dhcp.autoupdate.ip="2a06:e881:2000:7::1"
uci set dhcp.ntp=domain
uci set dhcp.ntp.name='ntp.ffnw'
uci set dhcp.ntp.ip="2a06:e881:2000:7::1"
uci delete dhcp.@dnsmasq[0].server
uci commit dhcp
uci set system.ntp.enable_server='1'
uci delete system.ntp.server
uci commit system
echo "date -s \"2021-11-05 19:00:00\"" >/etc/rc.local
echo "ip a add 2a06:e881:2000:7::1/64 dev br-client" >>/etc/rc.local
echo "ip a add 2a06:e881:2000:8::1/64 dev br-client" >>/etc/rc.local
echo "/usr/sbin/uradvd -i br-client -p 2a06:e881:2000:7::/64 -p 2a06:e881:2000:8::/64" >>/etc/rc.local
echo "exit 0" >>/etc/rc.local
/etc/init.d/gluon-ebtables disable
/etc/init.d/gluon-radv-filterd disable
/etc/init.d/firewall disable

uci set wireless.client_radio0.ssid='FreifunkMobileUpdate'
uci set wireless.client_radio0.owe_transition_ssid='FreifunkMobileUpdate OWE'
uci set wireless.client_radio1.ssid='FreifunkMobileUpdate'
uci set wireless.client_radio1.owe_transition_ssid='FreifunkMobileUpdate OWE'
uci commit wireless

uci set gluon-node-info.@location[0]='location'
uci set gluon-node-info.@location[0].share_location='0'
uci set gluon-node-info.@location[0].latitude='53.399809786'
uci set gluon-node-info.@location[0].longitude='7.898311615'
uci commit gluon-node-info

uci set system.@system[0].hostname='FreifunkMobileUpdate'
uci commit system

uci set autoupdater.settings.enabled='0'
uci commit autoupdater
uci set gluon-setup-mode.@setup_mode[0].configured='1'
uci commit gluon-setup-mode
reboot

EOF
