2 # Copyright (C) 2016 Ian Kelling
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 x
="$(readlink -f "$BASH_SOURCE")"; source "${x%/*}/bash-trace"
21 # background: upgrading all packages is not recommended because it
22 # doesn't go into the firmware. build new firmware if you want
25 if ! (( $
(date -r $f +%s
) + 60*60*24 > $
(date +%s
) )); then
32 if [[ ! $
(opkg list-installed
"$x") ]]; then
44 cat >/usr
/bin
/arch-pxe-mount
<<'EOFOUTER'
46 # symlinks are collapsed for nfs mount points, so use a bind mount.
47 # tried putting this in /etc/config/fstab,
48 # then doig block mount, it didn't work. This doesn't persist across reboots,
49 # todo: figure that out
50 d=/run/archiso/bootmnt
51 cat > /etc/fstab <<EOF
52 /mnt/usb/tftpboot $d none bind 0 0
54 mount | grep $d &>/dev/null || mount $d
55 /etc/init.d/nfsd restart
57 chmod +x
/usr
/bin
/arch-pxe-mount
60 # changing login shell emits spam on ssh single commands & scp
61 # sed -i 's#/bin/ash$#/bin/bash#' /etc/passwd
62 #https://dev.openwrt.org/ticket/13852
68 v pi kmod-usb-storage block-mount kmod-fs-ext4 nfs-kernel-server \
69 tcpdump openvpn-openssl
73 sed -ri "s/option[[:space:]]*encryption[[:space:]]*'?none'?/option encryption psk2\n option key pictionary49/" /etc
/config
/wireless
74 sed -i '/^[[:space:]]*option disabled/d' /etc
/config
/wireless
78 v
/etc
/init.d
/fstab
enable ||
:
80 # rebooting makes mounting work, but comparing lsmod,
81 # i'm guessing this will too. todo, test it.
82 # 255 == module already loaded
83 for mod
in scsi_mod sd_mod
; do v modprobe
$mod ||
[[ $?
== 255 ]]; done
85 # for arch pxe. The default settings in the installer expect to find
86 # the NFS at /run/archiso/bootmnt
87 mkdir
-p /run
/archiso
/bootmnt
89 # todo: at some later time, i found /mnt/usb not mounted, watch to see if
90 # that is the case after running this or rebooting.
91 # wiki says safe to do in case of fstab changes:
92 cedit
/etc
/config
/fstab
<<'EOF' || { v block umount; v block mount; }
93 config global automount
97 config global autoswap
102 option target /mnt/usb
103 option device /dev/sda2
105 option options rw,async,noatime,nodiratime
107 option enabled_fsck 0
110 option device /dev/sda1
117 # exportfs -ra wont cut it when its the same path, but now a bind mount
118 cedit
/etc
/exports
<<'EOF' || v /etc/init.d/nfsd restart ||:
119 /mnt/usb 192.168.1.0/255.255.255.0(rw,no_root_squash,insecure,sync,no_subtree_check)
121 /run/archiso/bootmnt 192.168.1.0/255.255.255.0(rw,no_root_squash,insecure,sync,no_subtree_check)
125 v
/etc
/init.d
/portmap start
126 v
/etc
/init.d
/nfsd start
127 v
/etc
/init.d
/portmap
enable
128 v
/etc
/init.d
/nfsd
enable
135 ######### uci example:#######
136 # # https://wiki.openwrt.org/doc/uci
137 # wan_index=$(uci show firewall | sed -rn 's/firewall\.@zone\[([0-9])+\]\.name=wan/\1/p')
138 # wan="firewall.@zone[$wan_index]"
139 # if [[ $(uci get firewall.@forwarding[0].dest) != $forward_dest ]]; then
141 # v uci set firewall.@forwarding[0].dest=$forward_dest
142 # uci commit firewall
143 # firewall_restart=true
148 ########## openvpn exampl
149 ########## missing firewall settings for routing lan
151 # v /etc/init.d/openvpn start
152 # v /etc/init.d/openvpn enable
154 # # from https://wiki.openwrt.org/doc/uci/firewall
155 # # todo: not sure if /etc/init.d/network needs restarting.
156 # # I did, and I had to restart the vpn afterwards.
157 # # This maps a uci interface to a real interface which is
158 # # managed outside of uci.
159 # v cedit /etc/config/network <<'EOF' ||:
160 # config interface 'tun0'
161 # option ifname 'tun0'
162 # option proto 'none'
164 # v cedit /etc/config/openvpn <<'EOF' || v /etc/init.d/openvpn restart
165 # config openvpn my_client_config
167 # option config /etc/openvpn/client.conf
171 v cedit
/etc
/config
/network
<<'EOF' || v /etc/init.d/network reload
172 config 'route' 'transmission'
173 option 'interface' 'lan'
174 option 'target' '10.173.0.0'
175 option 'netmask' '255.255.0.0'
176 option 'gateway' '192.168.1.2'
179 v cedit
/etc
/config
/firewall
<<'EOF' || firewall_restart=true
184 option dest_ip 192.168.1.2
194 option src_dport 2222
196 option dest_ip 192.168.1.3
201 option dest_port 2222
207 option dest_ip 192.168.1.2
217 option src_dport 1194
219 option dest_ip 192.168.1.2
224 option dest_port 1194
232 option dest_ip 192.168.1.2
241 option name syncthing
243 option src_dport 22001
244 option dest_ip 192.168.1.2
249 option dest_port 22001
258 dnsmasq_restart
=false
259 v cedit
/etc
/hosts
<<EOF || dnsmasq_restart=true
262 192.168.1.2 treetowl b8.nz faiserver
267 #192.168.1.7 faiserver
273 # netns creation looks for next free subnet starting at 10.173, but I only
274 # use one, and I would keep this one as the first created.
275 10.173.0.2 transmission
279 # avoid using the dns servers that my isp tells me about.
280 if [[ $
(uci get dhcp.@dnsmasq
[0].resolvfile
) ]]; then
281 # default is '/tmp/resolv.conf.auto', we switch to the dnsmasq default of
282 # /etc/resolv.conf. not sure why I did this.
283 v uci delete dhcp.@dnsmasq
[0].resolvfile
288 if [[ $
(uci get dhcp.@dnsmasq
[0].domain
) != b8.nz
]]; then
289 v uci
set dhcp.@dnsmasq
[0].domain
=b8.nz
293 if [[ $
(uci get dhcp.@dnsmasq
[0].
local) != b8.nz
]]; then
294 v uci
set dhcp.@dnsmasq
[0].
local=/b8.nz
/
299 if [[ $
(uci get system.@system
[0].hostname
) != wrt
]]; then
300 v uci
set system.@system
[0].hostname
=wrt
305 # useful: http://wiki.openwrt.org/doc/howto/dhcp.dnsmasq
307 # sometimes /mnt/usb fails, cuz it's just a flash drive,
308 # so make sure we have this dir or else dnsmasq will fail
310 mkdir
-p /mnt
/usb
/tftpboot
311 v cedit
/etc
/dnsmasq.conf
<<'EOF' || dnsmasq_restart=true
313 ############ updating dns servers ###################3
316 # this says the ip of default gateway and dns server,
317 # but I think they are unneded and default
318 #dhcp-option=3,192.168.1.1
319 #dhcp-option=6,192.168.1.1
323 # results from googling around dnsmasq optimizations
324 # about 50k in memory. router has 62 megs.
325 # in a browsing session, I probably won't ever do 5000 lookups
326 # before the ttl expiration or whatever does expiration.
329 # ask all servers, use the one which responds first.
330 # http://ma.ttwagner.com/make-dns-fly-with-dnsmasq-all-servers/
333 # namebench benchmarks dns servers. google's dns was only
334 # slightly less fast than some others, and I trust it more
335 # to give accurate results, stay relatively fast, and
336 # not do anythin too malicious, so just use that.
337 # download namebench and run it like this:
338 # for x in all regional isp global preferred nearby; do ./namebench.py -s $x -c US -i firefox -m weighted -J 10 -w; echo $x; hr; done
342 server=2001:4860:4860::8888
343 server=2001:4860:4860::8844
346 # to fixup existin ips, on the client you can do
347 # sudo dhclient -r; sudo dhclient <interface-name>
349 # default dhcp range is 100-150
350 dhcp-host=f4:6d:04:02:ed:66,set:treetowl,192.168.1.2,treetowl
351 dhcp-host=00:26:18:97:bb:16,set:frodo,192.168.1.3,frodo
352 dhcp-host=10:78:d2:da:29:22,set:htpc,192.168.1.4,htpc
353 dhcp-host=00:1f:16:16:39:24,set:x2,192.168.1.5,x2
354 # this is so fai can have an explicit name to use for testing,
355 # or else any random machine which did a pxe boot would get
356 # reformatted. The mac is from doing a virt-install, cancelling it,
357 # and copying the generated mac, so it should be randomish.
358 dhcp-host=52:54:00:9c:ef:ad,set:demohost,192.168.1.6,demohost
359 #dhcp-host=52:54:00:56:09:f9,set:faiserver,192.168.1.7,faiserver
360 dhcp-host=80:fa:5b:1c:6e:cf,set:tp,192.168.1.8,tp
361 dhcp-host=c4:43:8f:f2:79:1f,set:n5,192.168.1.9,n5
362 # this is the ip it picks by default if dhcp fails,
363 # so might as well use it.
364 # hostname is the name it uses according to telnet
365 dhcp-host=b4:75:0e:94:29:ca,set:switch9429ca,192.168.1.251,switch9429ca
369 # dhcp-host=,192.168.1.,
371 # Just leave the tftp server up even if we aren't doing pxe boot.
372 # It has no sensitive info.
374 tftp-root=/mnt/usb/tftpboot
377 if $dnsmasq_restart; then
378 v
/etc
/init.d
/dnsmasq restart
381 if $firewall_restart; then
382 v
/etc
/init.d
/firewall restart