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
24 # background: upgrading all packages is not recommended because it
25 # doesn't go into the firmware. build new firmware if you want
28 if ! (( $
(date -r $f +%s
) + 60*60*24 > $
(date +%s
) )); then
35 if [[ ! $
(opkg list-installed
"$x") ]]; then
47 cat >/usr
/bin
/arch-pxe-mount
<<'EOFOUTER'
49 # symlinks are collapsed for nfs mount points, so use a bind mount.
50 # tried putting this in /etc/config/fstab,
51 # then doig block mount, it didn't work. This doesn't persist across reboots,
52 # todo: figure that out
53 d=/run/archiso/bootmnt
54 cat > /etc/fstab <<EOF
55 /mnt/usb/tftpboot $d none bind 0 0
57 mount | grep $d &>/dev/null || mount $d
58 /etc/init.d/nfsd restart
60 chmod +x
/usr
/bin
/arch-pxe-mount
63 # changing login shell emits spam on ssh single commands & scp
64 # sed -i 's#/bin/ash$#/bin/bash#' /etc/passwd
65 #https://dev.openwrt.org/ticket/13852
71 v pi kmod-usb-storage block-mount kmod-fs-ext4 nfs-kernel-server \
72 tcpdump openvpn-openssl
76 sed -ri "s/option[[:space:]]*encryption[[:space:]]*'?none'?/option encryption psk2\n option key pictionary49/" /etc
/config
/wireless
77 sed -i '/^[[:space:]]*option disabled/d' /etc
/config
/wireless
81 v
/etc
/init.d
/fstab
enable ||
:
83 # rebooting makes mounting work, but comparing lsmod,
84 # i'm guessing this will too. todo, test it.
85 # 255 == module already loaded
86 for mod
in scsi_mod sd_mod
; do v modprobe
$mod ||
[[ $?
== 255 ]]; done
88 # for arch pxe. The default settings in the installer expect to find
89 # the NFS at /run/archiso/bootmnt
90 mkdir
-p /run
/archiso
/bootmnt
92 # todo: at some later time, i found /mnt/usb not mounted, watch to see if
93 # that is the case after running this or rebooting.
94 # wiki says safe to do in case of fstab changes:
95 cedit
/etc
/config
/fstab
<<'EOF' || { v block umount; v block mount; }
96 config global automount
100 config global autoswap
105 option target /mnt/usb
106 option device /dev/sda2
108 option options rw,async,noatime,nodiratime
110 option enabled_fsck 0
113 option device /dev/sda1
120 # exportfs -ra wont cut it when its the same path, but now a bind mount
121 cedit
/etc
/exports
<<'EOF' || v /etc/init.d/nfsd restart ||:
122 /mnt/usb 192.168.1.0/255.255.255.0(rw,no_root_squash,insecure,sync,no_subtree_check)
124 /run/archiso/bootmnt 192.168.1.0/255.255.255.0(rw,no_root_squash,insecure,sync,no_subtree_check)
128 v
/etc
/init.d
/portmap start
129 v
/etc
/init.d
/nfsd start
130 v
/etc
/init.d
/portmap
enable
131 v
/etc
/init.d
/nfsd
enable
138 ######### uci example:#######
139 # # https://wiki.openwrt.org/doc/uci
140 # wan_index=$(uci show firewall | sed -rn 's/firewall\.@zone\[([0-9])+\]\.name=wan/\1/p')
141 # wan="firewall.@zone[$wan_index]"
142 # if [[ $(uci get firewall.@forwarding[0].dest) != $forward_dest ]]; then
144 # v uci set firewall.@forwarding[0].dest=$forward_dest
145 # uci commit firewall
146 # firewall_restart=true
151 ########## openvpn exampl
152 ########## missing firewall settings for routing lan
154 # v /etc/init.d/openvpn start
155 # v /etc/init.d/openvpn enable
157 # # from https://wiki.openwrt.org/doc/uci/firewall
158 # # todo: not sure if /etc/init.d/network needs restarting.
159 # # I did, and I had to restart the vpn afterwards.
160 # # This maps a uci interface to a real interface which is
161 # # managed outside of uci.
162 # v cedit /etc/config/network <<'EOF' ||:
163 # config interface 'tun0'
164 # option ifname 'tun0'
165 # option proto 'none'
167 # v cedit /etc/config/openvpn <<'EOF' || v /etc/init.d/openvpn restart
168 # config openvpn my_client_config
170 # option config /etc/openvpn/client.conf
174 v cedit
/etc
/config
/network
<<'EOF' || v /etc/init.d/network reload
175 config 'route' 'transmission'
176 option 'interface' 'lan'
177 option 'target' '10.173.0.0'
178 option 'netmask' '255.255.0.0'
179 option 'gateway' '192.168.1.2'
182 v cedit
/etc
/config
/firewall
<<'EOF' || firewall_restart=true
187 option dest_ip 192.168.1.2
197 option src_dport 2222
199 option dest_ip 192.168.1.3
204 option dest_port 2222
210 option dest_ip 192.168.1.2
222 option dest_ip 192.168.1.2
231 option name syncthing
233 option src_dport 22001
234 option dest_ip 192.168.1.2
239 option dest_port 22001
246 dnsmasq_restart
=false
247 v cedit
/etc
/hosts
<<EOF || dnsmasq_restart=true
249 192.168.1.2 treetowl mail.iankelling.org $HOME_DOMAIN
250 192.168.1.3 frodo faiserver
254 #192.168.1.7 faiserver
259 # netns creation looks for next free subnet starting at 10.173, but I only
260 # use one, and I would keep this one as the first created.
261 10.173.0.2 transmission
265 # avoid using the dns servers that my isp tells me about.
266 if [[ $
(uci get dhcp.@dnsmasq
[0].resolvfile
) ]]; then
267 # default is '/tmp/resolv.conf.auto', we switch to the dnsmasq default of
269 v uci delete dhcp.@dnsmasq
[0].resolvfile
275 # useful: http://wiki.openwrt.org/doc/howto/dhcp.dnsmasq
277 # sometimes /mnt/usb fails, cuz it's just a flash drive,
278 # so make sure we have this dir or else dnsmasq will fail
280 mkdir
-p /mnt
/usb
/tftpboot
281 v cedit
/etc
/dnsmasq.conf
<<'EOF' || dnsmasq_restart=true
283 ############ updating dns servers ###################3
286 # this says the ip of default gateway and dns server,
287 # but I think they are unneded and default
288 #dhcp-option=3,192.168.1.1
289 #dhcp-option=6,192.168.1.1
293 # results from googling around dnsmasq optimizations
294 # about 50k in memory. router has 62 megs.
295 # in a browsing session, I probably won't ever do 5000 lookups
296 # before the ttl expiration or whatever does expiration.
299 # ask all servers, use the one which responds first.
300 # http://ma.ttwagner.com/make-dns-fly-with-dnsmasq-all-servers/
303 # namebench benchmarks dns servers. google's dns was only
304 # slightly less fast than some others, and I trust it more
305 # to give accurate results, stay relatively fast, and
306 # not do anythin too malicious, so just use that.
307 # download namebench and run it like this:
308 # 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
312 server=2001:4860:4860::8888
313 server=2001:4860:4860::8844
316 # to fixup existin ips, on the client you can do
317 # sudo dhclient -r; sudo dhclient <interface-name>
319 # default dhcp range is 100-150
320 dhcp-host=f4:6d:04:02:ed:66,set:treetowl,192.168.1.2,treetowl
321 dhcp-host=00:26:18:97:bb:16,set:frodo,192.168.1.3,frodo
322 dhcp-host=10:78:d2:da:29:22,set:htpc,192.168.1.4,htpc
323 dhcp-host=00:1f:16:16:39:24,set:x2,192.168.1.5,x2
324 # this is so fai can have an explicit name to use for testing,
325 # or else any random machine which did a pxe boot would get
326 # reformatted. The mac is from doing a virt-install, cancelling it,
327 # and copying the generated mac, so it should be randomish.
328 dhcp-host=52:54:00:9c:ef:ad,set:demohost,192.168.1.6,demohost
329 #dhcp-host=52:54:00:56:09:f9,set:faiserver,192.168.1.7,faiserver
330 dhcp-host=80:fa:5b:1c:6e:cf,set:tp,192.168.1.8,tp
331 # this is the ip it picks by default if dhcp fails,
332 # so might as well use it.
333 # hostname is the name it uses according to telnet
334 dhcp-host=b4:75:0e:94:29:ca,set:switch9429ca,192.168.1.251,switch9429ca
338 # dhcp-host=,192.168.1.,
340 # Just leave the tftp server up even if we aren't doing pxe boot.
341 # It has no sensitive info.
343 tftp-root=/mnt/usb/tftpboot
346 if $dnsmasq_restart; then
347 v
/etc
/init.d
/dnsmasq restart
350 if $firewall_restart; then
351 v
/etc
/init.d
/firewall restart