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:
95 ## ian: commented and replaced with just an echo
96 ## since usb port seems to be busted.
97 echo | cedit
/etc
/config
/fstab ||
:
98 # cedit /etc/config/fstab <<'EOF' || { v block umount; v block mount; }
99 # config global automount
100 # option from_fstab 1
101 # option anon_mount 1
103 # config global autoswap
104 # option from_fstab 1
108 # option target /mnt/usb
109 # option device /dev/sda2
111 # option options rw,async,noatime,nodiratime
113 # option enabled_fsck 0
116 # option device /dev/sda1
123 # exportfs -ra wont cut it when its the same path, but now a bind mount
124 cedit
/etc
/exports
<<'EOF' || v /etc/init.d/nfsd restart ||:
125 /mnt/usb 192.168.1.0/255.255.255.0(rw,no_root_squash,insecure,sync,no_subtree_check)
127 /run/archiso/bootmnt 192.168.1.0/255.255.255.0(rw,no_root_squash,insecure,sync,no_subtree_check)
131 v
/etc
/init.d
/portmap start
132 v
/etc
/init.d
/nfsd start
133 v
/etc
/init.d
/portmap
enable
134 v
/etc
/init.d
/nfsd
enable
141 ######### uci example:#######
142 # # https://wiki.openwrt.org/doc/uci
143 # wan_index=$(uci show firewall | sed -rn 's/firewall\.@zone\[([0-9])+\]\.name=wan/\1/p')
144 # wan="firewall.@zone[$wan_index]"
145 # if [[ $(uci get firewall.@forwarding[0].dest) != $forward_dest ]]; then
147 # v uci set firewall.@forwarding[0].dest=$forward_dest
148 # uci commit firewall
149 # firewall_restart=true
154 ########## openvpn exampl
155 ########## missing firewall settings for routing lan
157 # v /etc/init.d/openvpn start
158 # v /etc/init.d/openvpn enable
160 # # from https://wiki.openwrt.org/doc/uci/firewall
161 # # todo: not sure if /etc/init.d/network needs restarting.
162 # # I did, and I had to restart the vpn afterwards.
163 # # This maps a uci interface to a real interface which is
164 # # managed outside of uci.
165 # v cedit /etc/config/network <<'EOF' ||:
166 # config interface 'tun0'
167 # option ifname 'tun0'
168 # option proto 'none'
170 # v cedit /etc/config/openvpn <<'EOF' || v /etc/init.d/openvpn restart
171 # config openvpn my_client_config
173 # option config /etc/openvpn/client.conf
177 v cedit
/etc
/config
/network
<<'EOF' || v /etc/init.d/network reload
178 config 'route' 'transmission'
179 option 'interface' 'lan'
180 option 'target' '10.173.0.0'
181 option 'netmask' '255.255.0.0'
182 option 'gateway' '192.168.1.3'
185 v cedit
/etc
/config
/firewall
<<'EOF' || firewall_restart=true
190 option dest_ip 192.168.1.8
200 option src_dport 2222
202 option dest_ip 192.168.1.3
207 option dest_port 2222
213 option dest_ip 192.168.1.8
223 option src_dport 1196
225 option dest_ip 192.168.1.8
230 option dest_port 1196
238 option dest_ip 192.168.1.8
247 option name syncthing
249 option src_dport 22001
250 option dest_ip 192.168.1.8
255 option dest_port 22001
264 dnsmasq_restart
=false
265 mail_host
=$
(grep -F mail.iankelling.org
/etc
/hosts |
awk '{print $1}')
266 v cedit
/etc
/hosts
<<EOF || dnsmasq_restart=true
274 #192.168.1.7 faiserver
275 192.168.1.8 tp faiserver b8.nz
283 # netns creation looks for next free subnet starting at 10.173, but I only
284 # use one, and I would keep this one as the first created.
285 10.173.0.2 transmission
288 # if [[ $mail_host ]]; then
289 # sed -i '/^$mail_host/a mail.iankelling.org' /etc/hosts
293 # avoid using the dns servers that my isp tells me about.
294 if [[ $
(uci get dhcp.@dnsmasq
[0].resolvfile
) ]]; then
295 # default is '/tmp/resolv.conf.auto', we switch to the dnsmasq default of
296 # /etc/resolv.conf. not sure why I did this.
297 v uci delete dhcp.@dnsmasq
[0].resolvfile
302 if [[ $
(uci get dhcp.@dnsmasq
[0].domain
) != b8.nz
]]; then
303 v uci
set dhcp.@dnsmasq
[0].domain
=b8.nz
307 if [[ $
(uci get dhcp.@dnsmasq
[0].
local) != b8.nz
]]; then
308 v uci
set dhcp.@dnsmasq
[0].
local=/b8.nz
/
313 if [[ $
(uci get system.@system
[0].hostname
) != wrt
]]; then
314 v uci
set system.@system
[0].hostname
=wrt
319 # useful: http://wiki.openwrt.org/doc/howto/dhcp.dnsmasq
321 # sometimes /mnt/usb fails, cuz it's just a flash drive,
322 # so make sure we have this dir or else dnsmasq will fail
324 mkdir
-p /mnt
/usb
/tftpboot
325 v cedit
/etc
/dnsmasq.conf
<<'EOF' || dnsmasq_restart=true
327 ############ updating dns servers ###################3
330 # this says the ip of default gateway and dns server,
331 # but I think they are unneded and default
332 #dhcp-option=3,192.168.1.1
333 #dhcp-option=6,192.168.1.1
337 # results from googling around dnsmasq optimizations
338 # about 50k in memory. router has 62 megs.
339 # in a browsing session, I probably won't ever do 5000 lookups
340 # before the ttl expiration or whatever does expiration.
343 # ask all servers, use the one which responds first.
344 # http://ma.ttwagner.com/make-dns-fly-with-dnsmasq-all-servers/
347 # namebench benchmarks dns servers. google's dns was only
348 # slightly less fast than some others, and I trust it more
349 # to give accurate results, stay relatively fast, and
350 # not do anythin too malicious, so just use that.
351 # download namebench and run it like this:
352 # 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
356 server=2001:4860:4860::8888
357 server=2001:4860:4860::8844
360 # to fixup existin ips, on the client you can do
361 # sudo dhclient -r; sudo dhclient <interface-name>
363 # default dhcp range is 100-150
364 dhcp-host=f4:6d:04:02:ed:66,set:treetowl,192.168.1.2,treetowl
365 dhcp-host=00:26:18:97:bb:16,set:frodo,192.168.1.3,frodo
366 dhcp-host=10:78:d2:da:29:22,set:htpc,192.168.1.4,htpc
367 dhcp-host=00:1f:16:16:39:24,set:kw,192.168.1.5,x2
368 #dhcp-host=00:1f:16:16:39:24,set:kw,192.168.1.10,kw
369 #dhcp-host=00:c0:ca:27:e9:b2,set:kww,192.168.1.11,kww
370 # this is so fai can have an explicit name to use for testing,
371 # or else any random machine which did a pxe boot would get
372 # reformatted. The mac is from doing a virt-install, cancelling it,
373 # and copying the generated mac, so it should be randomish.
374 dhcp-host=52:54:00:9c:ef:ad,set:demohost,192.168.1.6,demohost
375 #dhcp-host=52:54:00:56:09:f9,set:faiserver,192.168.1.7,faiserver
376 dhcp-host=80:fa:5b:1c:6e:cf,set:tp,192.168.1.8,tp
377 dhcp-host=c4:43:8f:f2:79:1f,set:n5,192.168.1.9,n5
378 # this is the ip it picks by default if dhcp fails,
379 # so might as well use it.
380 # hostname is the name it uses according to telnet
381 dhcp-host=b4:75:0e:94:29:ca,set:switch9429ca,192.168.1.251,switch9429ca
384 # dhcp-host=,192.168.1.,
386 # Just leave the tftp server up even if we aren't doing pxe boot.
387 # It has no sensitive info.
389 tftp-root=/mnt/usb/tftpboot
392 if $dnsmasq_restart; then
393 v
/etc
/init.d
/dnsmasq restart
396 if $firewall_restart; then
397 v
/etc
/init.d
/firewall restart