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.
19 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
23 # background: upgrading all packages is not recommended because it
24 # doesn't go into the firmware. build new firmware if you want
27 if ! (( $
(date -r $f +%s
) + 60*60*24 > $
(date +%s
) )); then
34 if [[ ! $
(opkg list-installed
"$x") ]]; then
46 cat >/usr
/bin
/arch-pxe-mount
<<'EOFOUTER'
48 # symlinks are collapsed for nfs mount points, so use a bind mount.
49 # tried putting this in /etc/config/fstab,
50 # then doig block mount, it didn't work. This doesn't persist across reboots,
51 # todo: figure that out
52 d=/run/archiso/bootmnt
53 cat > /etc/fstab <<EOF
54 /mnt/usb/tftpboot $d none bind 0 0
56 mount | grep $d &>/dev/null || mount $d
57 /etc/init.d/nfsd restart
59 chmod +x
/usr
/bin
/arch-pxe-mount
62 # changing login shell emits spam on ssh single commands & scp
63 # sed -i 's#/bin/ash$#/bin/bash#' /etc/passwd
64 #https://dev.openwrt.org/ticket/13852
70 v pi kmod-usb-storage block-mount kmod-fs-ext4 nfs-kernel-server \
71 tcpdump openvpn-openssl
75 sed -ri "s/option[[:space:]]*encryption[[:space:]]*'?none'?/option encryption psk2\n option key pictionary49/" /etc
/config
/wireless
76 sed -i '/^[[:space:]]*option disabled/d' /etc
/config
/wireless
80 v
/etc
/init.d
/fstab
enable ||
:
82 # rebooting makes mounting work, but comparing lsmod,
83 # i'm guessing this will too. todo, test it.
84 # 255 == module already loaded
85 for mod
in scsi_mod sd_mod
; do v modprobe
$mod ||
[[ $?
== 255 ]]; done
87 # for arch pxe. The default settings in the installer expect to find
88 # the NFS at /run/archiso/bootmnt
89 mkdir
-p /run
/archiso
/bootmnt
91 # todo: at some later time, i found /mnt/usb not mounted, watch to see if
92 # that is the case after running this or rebooting.
93 # wiki says safe to do in case of fstab changes:
94 cedit
/etc
/config
/fstab
<<'EOF' || { v block umount; v block mount; }
95 config global automount
99 config global autoswap
104 option target /mnt/usb
105 option device /dev/sda2
107 option options rw,async,noatime,nodiratime
109 option enabled_fsck 0
112 option device /dev/sda1
119 # exportfs -ra wont cut it when its the same path, but now a bind mount
120 cedit
/etc
/exports
<<'EOF' || v /etc/init.d/nfsd restart ||:
121 /mnt/usb 192.168.1.0/255.255.255.0(rw,no_root_squash,insecure,sync,no_subtree_check)
123 /run/archiso/bootmnt 192.168.1.0/255.255.255.0(rw,no_root_squash,insecure,sync,no_subtree_check)
127 v
/etc
/init.d
/portmap start
128 v
/etc
/init.d
/nfsd start
129 v
/etc
/init.d
/portmap
enable
130 v
/etc
/init.d
/nfsd
enable
137 ######### uci example:#######
138 # # https://wiki.openwrt.org/doc/uci
139 # wan_index=$(uci show firewall | sed -rn 's/firewall\.@zone\[([0-9])+\]\.name=wan/\1/p')
140 # wan="firewall.@zone[$wan_index]"
141 # if [[ $(uci get firewall.@forwarding[0].dest) != $forward_dest ]]; then
143 # v uci set firewall.@forwarding[0].dest=$forward_dest
144 # uci commit firewall
145 # firewall_restart=true
150 ########## openvpn exampl
151 ########## missing firewall settings for routing lan
153 # v /etc/init.d/openvpn start
154 # v /etc/init.d/openvpn enable
156 # # from https://wiki.openwrt.org/doc/uci/firewall
157 # # todo: not sure if /etc/init.d/network needs restarting.
158 # # I did, and I had to restart the vpn afterwards.
159 # # This maps a uci interface to a real interface which is
160 # # managed outside of uci.
161 # v cedit /etc/config/network <<'EOF' ||:
162 # config interface 'tun0'
163 # option ifname 'tun0'
164 # option proto 'none'
166 # v cedit /etc/config/openvpn <<'EOF' || v /etc/init.d/openvpn restart
167 # config openvpn my_client_config
169 # option config /etc/openvpn/client.conf
173 v cedit
/etc
/config
/network
<<'EOF' || v /etc/init.d/network reload
174 config 'route' 'transmission'
175 option 'interface' 'lan'
176 option 'target' '10.173.0.0'
177 option 'netmask' '255.255.0.0'
178 option 'gateway' '192.168.1.3'
181 v cedit
/etc
/config
/firewall
<<'EOF' || firewall_restart=true
186 option dest_ip 192.168.1.2
196 option src_dport 2222
198 option dest_ip 192.168.1.3
203 option dest_port 2222
209 option dest_ip 192.168.1.2
219 option src_dport 1196
221 option dest_ip 192.168.1.2
226 option dest_port 1196
234 option dest_ip 192.168.1.2
243 option name syncthing
245 option src_dport 22001
246 option dest_ip 192.168.1.2
251 option dest_port 22001
260 dnsmasq_restart
=false
261 v cedit
/etc
/hosts
<<EOF || dnsmasq_restart=true
264 192.168.1.2 treetowl b8.nz faiserver
269 #192.168.1.7 faiserver
275 # netns creation looks for next free subnet starting at 10.173, but I only
276 # use one, and I would keep this one as the first created.
277 10.173.0.2 transmission
281 # avoid using the dns servers that my isp tells me about.
282 if [[ $
(uci get dhcp.@dnsmasq
[0].resolvfile
) ]]; then
283 # default is '/tmp/resolv.conf.auto', we switch to the dnsmasq default of
284 # /etc/resolv.conf. not sure why I did this.
285 v uci delete dhcp.@dnsmasq
[0].resolvfile
290 if [[ $
(uci get dhcp.@dnsmasq
[0].domain
) != b8.nz
]]; then
291 v uci
set dhcp.@dnsmasq
[0].domain
=b8.nz
295 if [[ $
(uci get dhcp.@dnsmasq
[0].
local) != b8.nz
]]; then
296 v uci
set dhcp.@dnsmasq
[0].
local=/b8.nz
/
301 if [[ $
(uci get system.@system
[0].hostname
) != wrt
]]; then
302 v uci
set system.@system
[0].hostname
=wrt
307 # useful: http://wiki.openwrt.org/doc/howto/dhcp.dnsmasq
309 # sometimes /mnt/usb fails, cuz it's just a flash drive,
310 # so make sure we have this dir or else dnsmasq will fail
312 mkdir
-p /mnt
/usb
/tftpboot
313 v cedit
/etc
/dnsmasq.conf
<<'EOF' || dnsmasq_restart=true
315 ############ updating dns servers ###################3
318 # this says the ip of default gateway and dns server,
319 # but I think they are unneded and default
320 #dhcp-option=3,192.168.1.1
321 #dhcp-option=6,192.168.1.1
325 # results from googling around dnsmasq optimizations
326 # about 50k in memory. router has 62 megs.
327 # in a browsing session, I probably won't ever do 5000 lookups
328 # before the ttl expiration or whatever does expiration.
331 # ask all servers, use the one which responds first.
332 # http://ma.ttwagner.com/make-dns-fly-with-dnsmasq-all-servers/
335 # namebench benchmarks dns servers. google's dns was only
336 # slightly less fast than some others, and I trust it more
337 # to give accurate results, stay relatively fast, and
338 # not do anythin too malicious, so just use that.
339 # download namebench and run it like this:
340 # 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
344 server=2001:4860:4860::8888
345 server=2001:4860:4860::8844
348 # to fixup existin ips, on the client you can do
349 # sudo dhclient -r; sudo dhclient <interface-name>
351 # default dhcp range is 100-150
352 dhcp-host=f4:6d:04:02:ed:66,set:treetowl,192.168.1.2,treetowl
353 dhcp-host=00:26:18:97:bb:16,set:frodo,192.168.1.3,frodo
354 dhcp-host=10:78:d2:da:29:22,set:htpc,192.168.1.4,htpc
355 dhcp-host=00:1f:16:16:39:24,set:x2,192.168.1.5,x2
356 # this is so fai can have an explicit name to use for testing,
357 # or else any random machine which did a pxe boot would get
358 # reformatted. The mac is from doing a virt-install, cancelling it,
359 # and copying the generated mac, so it should be randomish.
360 dhcp-host=52:54:00:9c:ef:ad,set:demohost,192.168.1.6,demohost
361 #dhcp-host=52:54:00:56:09:f9,set:faiserver,192.168.1.7,faiserver
362 dhcp-host=80:fa:5b:1c:6e:cf,set:tp,192.168.1.8,tp
363 dhcp-host=c4:43:8f:f2:79:1f,set:n5,192.168.1.9,n5
364 # this is the ip it picks by default if dhcp fails,
365 # so might as well use it.
366 # hostname is the name it uses according to telnet
367 dhcp-host=b4:75:0e:94:29:ca,set:switch9429ca,192.168.1.251,switch9429ca
371 # dhcp-host=,192.168.1.,
373 # Just leave the tftp server up even if we aren't doing pxe boot.
374 # It has no sensitive info.
376 tftp-root=/mnt/usb/tftpboot
379 if $dnsmasq_restart; then
380 v
/etc
/init.d
/dnsmasq restart
383 if $firewall_restart; then
384 v
/etc
/init.d
/firewall restart