X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;ds=sidebyside;f=wrt-setup-local;h=55ac7d7281df6663d10feca0f76caf58d9ff4259;hb=45a2a286083772abc0688e663a6ecc68af0a8d0e;hp=f465da5a75ceef8e8da54932133943a5c4c1dbb1;hpb=917fa30617ccafa3a7ed5218a418cf058948b729;p=automated-distro-installer diff --git a/wrt-setup-local b/wrt-setup-local index f465da5..55ac7d7 100755 --- a/wrt-setup-local +++ b/wrt-setup-local @@ -18,28 +18,116 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR + +usage() { + cat <&2; usage 1 ;; + esac + ;; + m) mac=$OPTARG ;; + *) echo "$0: Internal error! unexpected args: $*" >&2 ; usage 1 ;; + esac +done +shift "$((OPTIND-1))" # Discard the options and sentinel -- + +if [[ ! $mac ]] && ! $test; then + # if we wanted to increment it + #WIRELESSMAC=${WIRELESSMAC:0: -1}$((${WIRELESSMAC: -1} + 2)) + mac=$WIRELESSMAC +fi + +if (( $# != 0 )); then + usage 1 fi + +macpre=${mac:0: -1} +macsuf=${mac: -1} + + +p_updated=false pmirror() { + if $p_updated; then + return + fi # background: upgrading all packages is not recommended because it # doesn't go into the firmware. build new firmware if you want # lots of upgrades. I think /tmp/opkg-lists is a pre openwrt 14 location. f=(/var/opkg-lists/*) if ! (( $(date -r $f +%s) + 60*60*24 > $(date +%s) )); then - opkg update + if ! opkg update; then + echo "$0: warning: opkg update failed" >&2 + fi + p_updated=true fi } pi() { - for x in "$@"; do - if [[ ! $(opkg list-installed "$x") ]]; then + to_install=() + for p in "$@"; do + pname=${p##*/} + pname=${pname%%_*} + if [[ ! $(opkg list-installed "$pname") ]]; then + to_install+=($p) pmirror - opkg install "$@" fi done + if [[ $to_install ]]; then + opkg install ${to_install[@]} + fi } v() { @@ -60,6 +148,7 @@ v() { ####### end uci example ##### uset() { + printf "+ uset %s\n" "$*" local key="$1" local val="$2" local service="${key%%.*}" @@ -74,16 +163,43 @@ uset() { fi } +udel() { + printf "+ udel %s\n" "$*" + local key="$1" + local val="$2" + local service="${key%%.*}" + restart_var=${service}_restart + if [[ ! ${!restart_var} ]]; then + eval $restart_var=false + fi + if uci get "$key" &>/dev/null; then + v uci set "$key"="$val" + uci commit $service + eval $restart_var=true + fi +} + + ### network config ### ssid="check out gnu.org" lan=10.0.0.0 -if $dev2; then +if $test; then ssid="gnuv3" lan=10.1.0.0 +elif [[ $hostname == cmc ]]; then + ssid=Svenska + lan=10.2.0.0 fi + +if [[ $rkey ]]; then + key=${rkey[$rmac]} +fi +: ${key:=pictionary49} + mask=255.255.0.0 +cidr=16 l=${lan%.0} passwd -l root ||: #already locked fails @@ -114,10 +230,15 @@ EOFOUTER chmod +x /usr/bin/archlike-pxe-mount sed -i '/^root:/s,/bin/ash$,/bin/bash,' /etc/passwd +# usb, screen, relay are for libremanage v pi kmod-usb-storage block-mount kmod-fs-ext4 nfs-kernel-server \ - tcpdump openvpn-openssl adblock libusb-compat /root/relay_1.0-1_mips_24kc.ipk - + tcpdump openvpn-openssl adblock libusb-compat /root/relay_1.0-1_mips_24kc.ipk \ + screen kmod-usb-serial-cp210x kmod-usb-serial-ftdi +cat >/etc/libremanage.conf </dev/null) ]]; then - v uci delete wireless.radio$x.disabled - wireless_restart=true + if [[ $mac ]]; then + uset wireless.default_radio$x.macaddr $macpre$((macsuf + 2*x)) fi + # secondary device has wireless disabled + uset wireless.radio$x.disabled $dev2 done if $wireless_restart; then @@ -247,84 +373,179 @@ EOF firewall_restart=false v cedit /etc/config/firewall </dev/null) ]]; then - # default is '/tmp/resolv.conf.auto', we switch to the dnsmasq default of - # /etc/resolv.conf. not sure why I did this. - v uci delete dhcp.@dnsmasq[0].resolvfile - uci commit dhcp - dnsmasq_restart=true -fi - uset dhcp.@dnsmasq[0].domain b8.nz uset dhcp.@dnsmasq[0].local /b8.nz/ -uset system.@system[0].hostname wrt +uset system.@system[0].hostname $hostname if [[ $(uci get adblock.global.adb_enabled) != 1 ]]; then v uci set adblock.global.adb_enabled=1 @@ -388,6 +604,14 @@ EOF # to start. mkdir -p /mnt/usb/tftpboot v cedit /etc/dnsmasq.conf <