#! /bin/ash #vars for downloading base configurations ff_s='http://fabfi.fablab.af' #fabfi server ff_dld='/download/software/base_config/2_1/' # dld needs leading and trailing / ff_u='fabfi' #user ff_cfg='fabfi-files.tgz' ec="etc/config/" i_d="etc/init.d/" r_d="etc/rc.d/" #temporary directory for downloaded files ff_tmp='/tmp/' ff_tdld='/tmp/setup/' #needs trailing / ff_td='/tmp/setup/packages/' #needs trailing / expected to be a direct sub of tdld. Tar file defines fabfi_config part ff_tdo='/tmp/setup/packages_optional/' #needs trailing / expected to be a direct sub of tdld. Tar file defines fabfi_config part ff_MACEnd=':fa:bf:1f:ab:f1' #misc constants ff_cIP=0 ff_dIP=0 ff_wm_abIP="10.102." #needs trailing . ff_m_abIP="10.101." #needs trailing . ff_m_cIP="0." #needs trailing . ff_l_abIP="10.103." #needs trailing . ff_gw_dIP="1" default_wep="8bb8d3c8d3d8bb3dffd38db33f" echo "" echo "Welcome to the FabFi 2.1 device configuration script." sleep 2 echo "" i="nothing" until (test "y" == $i || test "n" == $i); do echo "Do you need to download config files y/n? (respond y unless you have already download $ff_cfg to $ff_tdld)" read i done if test "y" == $i; then #get tarball for base config files echo "Retrieving configuration files with wget" mkdir $ff_tdld if !(wget $ff_s$ff_dld$ff_cfg -O $ff_tdld$ff_cfg); then echo "Could not download config files." exit fi fi until ((echo $channel | grep "^1[0-1]$")||(echo $channel | grep "^[0-9]$")); do echo "Now you must select the wireless channel, it must be the same for all connecting nodes." echo "Enter the wireless channel (between 1-11):" read channel done if test $channel -lt 10; then bssid=0$channel$ff_MACEnd else bssid=$channel$ff_MACEnd fi until (echo $distance | grep "^[1-9][0-9]*$"); do echo "fabfi distance must be a positive integer greater than 0" echo "Enter the transmit distance in meters" read distance done wep_key="ZzZzzZZ//"; until (echo $wep_key | grep "^[0-9A-fA-F]*$"); do echo "Now you need to select a wep key." echo "Select a wep key to use (type 'd' for default):" read wep_key if [ $wep_key == "d" ]; then wep_key=$default_wep; fi; done location="////"; until (echo $location | grep "^[0-9a-zA-z\-\_]*$"); do echo "What is your location? NO SPACES or special characters:" read location done until ((echo $fabfi_num | grep "^1[0-9][0-9]$")||(echo $fabfi_num | grep "^2[0-4][0-9]$")||(echo $fabfi_num | grep "^25[0-4]$")||(echo $fabfi_num | grep "^[1-9][0-9]\{0,1\}$")); do echo "Enter the number of your FabFi (must be in range 1-254):" read fabfi_num done let m_dIP="$fabfi_num+$ff_dIP" echo MESH and WIFIMESH Class D IP is: $meshing_dIP let lan_cIP="$fabfi_num+$ff_cIP" echo LAN Class C IP is: $lan_cIP #unzip config files to temp dir. tar -C $ff_tdld -xzf $ff_tdld$ff_cfg cp -rf ${ff_tdld}lib/ / cp -f ${ff_tdld}${ec}network /${ec} cp -f ${ff_tdld}${ec}wireless /${ec} cp -f ${ff_tdld}${ec}httpd /${ec} cp -f ${ff_tdld}${ec}dhcp /${ec} cp -f ${ff_tdld}${ec}system /${ec} cp -f ${ff_tdld}etc/opkg.conf.offline /etc/opkg.conf echo "Replacing wget temporarily. If you quit now, you'll have to restore it manually from /usr/bin/wget-real" # Copy wget for opkg-spoofing purposes cp -df /usr/bin/wget /usr/bin/wget-real rm /usr/bin/wget echo '#!/bin/ash' > /usr/bin/wget-opkg echo 'cp $4 $3' >> /usr/bin/wget-opkg chmod ugo+x /usr/bin/wget-opkg ln -s /usr/bin/wget-opkg /usr/bin/wget echo "Installing base software" ### Doing it the old fashioned way.... opkg update opkg -force-reinstall install luci-app-olsr luci-app-firewall luci-app-qos mini-snmpd opkg -force-reinstall install olsrd-luci-mod-nameservice olsrd-luci-mod-dyn-gw opkg -force-reinstall install iperf iptables-mod-extra opkg -force-reinstall install nodogsplash opkg -force-reinstall install wl rm -rf /etc/nodogsplash/htdocs/images/ #rm /etc/nodogsplash/htdocs/images/wifidog.png rm /${i_d}/nodogsplash.init cp -df ${ff_tdld}www/index.html /www/ cp -df ${ff_tdld}www/images /www/ cp -f ${ff_tdld}${ec}olsrd /${ec} cp -f ${ff_tdld}${ec}firewall /${ec} cp -f ${ff_tdld}${ec}qos /${ec} cp -rf ${ff_tdld}etc/fabfi-scripts/ /etc/ cp -f ${ff_tdld}etc/crontabs/root /etc/crontabs/ cp -f ${ff_tdld}etc/firewall.user /etc/ cp -f ${ff_tdld}${i_d}custom-user-startup /${i_d} cp -df ${ff_tdld}${r_d}S98customuserstartup /${r_d} cp -df ${ff_tdld}${r_d}S50olsrd /${r_d} cp -df ${ff_tdld}${r_d}S65mini_snmpd /${r_d} cp -df ${ff_tdld}${r_d}S66nodogsplash /${r_d} cp -f ${ff_tdld}${ec}luci_ethers /${ec} cp -f ${ff_tdld}${ec}luci_hosts /${ec} cp -f ${ff_tdld}${ec}mini_snmpd /${ec} cp -f ${ff_tdld}${i_d}mini_snmpd /${i_d} cp -f ${ff_tdld}etc/passwd /etc/ cp -f ${ff_tdld}etc/nodogsplash/nodogsplash.conf /etc/nodogsplash/ rm /etc/nodogsplash/htdocs/splash.html cp -df ${ff_tdld}etc/nodogsplash/htdocs/splash.html /etc/nodogsplash/htdocs/ cp -df ${ff_tdld}etc/nodogsplash/splash.base /etc/nodogsplash/ cp -df ${ff_tdld}etc/nodogsplash/splash-auth.base /etc/nodogsplash/ cp -rf ${ff_tdld}/etc/nodogsplash/htdocs/images/ /etc/nodogsplash/htdocs/ cp -f ${ff_tdld}etc/nodogsplash/htdocs/infoskel.html /etc/nodogsplash/htdocs/ ln -s /var/etc/ffstatus.log /www/ffstatus.log rm /etc/hosts cp -df ${ff_tdld}etc/hosts /etc/ cp -f ${ff_tdld}${i_d}nodogsplash /${i_d} # Restoring wget.. rm /usr/bin/wget cp -df /usr/bin/wget-real /usr/bin/wget rm /usr/bin/wget-real rm /usr/bin/wget-opkg cp -f ${ff_tdld}etc/opkg.conf.online /etc/opkg.conf echo "wget has been restored to normal." ns_index=`uci show olsrd | grep -e 'olsrd\.@LoadPlugin\[.*\]\.library=olsrd_nameservice\.so' | awk 'FS="[";{print $2}' | awk 'FS="]";{print $1};' | tail -1` #set config variables uci set system.@system[0].hostname=fabfi${fabfi_num} uci set network.lan.ipaddr=${ff_l_abIP}${lan_cIP}.${ff_gw_dIP} uci set network.mesh.ipaddr=$ff_m_abIP${ff_m_cIP}${m_dIP} uci set network.wifimesh.ipaddr=$ff_wm_abIP${ff_m_cIP}${m_dIP} uci set olsrd.@Hna4[0].netaddr=${ff_l_abIP}${lan_cIP}.0 uci set olsrd.@LoadPlugin[${ns_index}].name=fabfi${fabfi_num} uci set mini_snmpd.@mini_snmpd[0].location=$location echo Hostname = `uci get system.@system[0].hostname` echo "" echo LAN IP = `uci get network.lan.ipaddr` echo MESH IP = `uci get network.mesh.ipaddr` echo WIFIMESH IP = `uci get network.wifimesh.ipaddr` echo "" uci set wireless.wl0.channel=$channel uci set wireless.@wifi-iface[0].bssid=$bssid uci set wireless.@wifi-iface[0].ssid=fabfi${channel} uci set wireless.wl0.distance=$distance uci set wireless.@wifi-iface[0].key=$wep_key echo Wireless channel = `uci get wireless.wl0.channel` echo Wireless distance = `uci get wireless.wl0.distance` echo Wireless WEP key = `uci get wireless.@wifi-iface[0].key` sleep 2 uci commit echo "" echo "Choose a root password" passwd root #hack so I don't have to keep fixing setrouter in the AP and STA tarballs. cp ${ff_tmp}fabfi-setup /etc/fabfi-scripts/fabfi-setup echo "" echo Configuration is complete! echo You must reboot your router for the changes to take effect. echo POWER DOWN YOUR ROUTER WHEN THIS SCRIPT EXITS echo "" sleep 4