openwrt: add file to turn router into wifi client
This commit is contained in:
parent
db567a9fbd
commit
8fd5745ce6
1 changed files with 80 additions and 0 deletions
80
openwrt/openwrt-viwib-camera.sh
Executable file
80
openwrt/openwrt-viwib-camera.sh
Executable file
|
@ -0,0 +1,80 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Nico Schottelius, 2024-07-22
|
||||||
|
# This script assumes a clean/newly setup openwrt device
|
||||||
|
#
|
||||||
|
# Assumption:
|
||||||
|
# VIWIB being used to...
|
||||||
|
# - monitor camera
|
||||||
|
|
||||||
|
if [ $# -lt 8 ] ; then
|
||||||
|
echo $0 "address hostname passwd wifi-ssid wifi-psk"
|
||||||
|
fi
|
||||||
|
|
||||||
|
address=$1; shift
|
||||||
|
hostname=$1; shift
|
||||||
|
root_password=$1; shift
|
||||||
|
wifi_ssid=$1; shift
|
||||||
|
wifi_psk=$1; shift
|
||||||
|
|
||||||
|
# Allow passwordless to avoid nightmare
|
||||||
|
cat ~/.ssh/id_rsa.pub | ssh root@${address} "cat > /etc/dropbear/authorized_keys"
|
||||||
|
|
||||||
|
cat <<EOF | ssh -t "root@${address}"
|
||||||
|
set -x
|
||||||
|
# Do not announce ULA - we have GUA
|
||||||
|
uci delete network.globals.ula_prefix
|
||||||
|
|
||||||
|
# Remove IPv6 assign, we are using static IPv6
|
||||||
|
uci delete network.lan.ip6assign
|
||||||
|
|
||||||
|
# Set hostname
|
||||||
|
uci set system.@system[0].hostname="${hostname}"
|
||||||
|
|
||||||
|
# Disable DHCP/RA on LAN
|
||||||
|
uci delete dhcp.lan.dhcpv4
|
||||||
|
uci delete dhcp.lan.dhcpv6
|
||||||
|
uci delete dhcp.lan.ra
|
||||||
|
uci set dhcp.lan.ignore=1
|
||||||
|
|
||||||
|
# Base wifi settings
|
||||||
|
uci set wireless.radio0.channel='auto'
|
||||||
|
|
||||||
|
# Remove old AP entry
|
||||||
|
uci delete wireless.default_radio0
|
||||||
|
|
||||||
|
# Create device for wifi
|
||||||
|
uci set network.wwan=interface
|
||||||
|
uci set network.wwan.proto=dhcpv6
|
||||||
|
uci set network.wwan.device=phy0-sta0
|
||||||
|
|
||||||
|
# Add wwan to lan zone, if it is not in there already
|
||||||
|
is_in=""
|
||||||
|
for net in \$(uci get firewall.@zone[0].network); do
|
||||||
|
echo \$net | grep ^wwan\$ && is_in=yes && break
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "\$is_in" ]; then
|
||||||
|
uci add_list firewall.@zone[0].network="wwan"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create wireless entry for wifi
|
||||||
|
uci set wireless.wifinet1=wifi-iface
|
||||||
|
uci set wireless.wifinet1.device='radio0'
|
||||||
|
uci set wireless.wifinet1.mode='sta'
|
||||||
|
uci set wireless.wifinet1.network='wwan'
|
||||||
|
uci set wireless.wifinet1.ssid='${wifi_ssid}'
|
||||||
|
uci set wireless.wifinet1.encryption='psk2'
|
||||||
|
uci set wireless.wifinet1.key='${wifi_psk}'
|
||||||
|
|
||||||
|
uci delete wireless.radio0.disabled
|
||||||
|
|
||||||
|
uci commit
|
||||||
|
|
||||||
|
printf "${root_password}\n${root_password}\n" | passwd
|
||||||
|
|
||||||
|
# Apply all changes
|
||||||
|
reboot
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo "Restart router to restart firewall, network, dhcp"
|
Loading…
Reference in a new issue