|
| 1 | +. /etc/auto.config |
| 2 | +#additional_usb_www_init() { |
| 3 | +# |
| 4 | +# echo "${initscript}: Creating enhanced www content folder on usb-stick..." |
| 5 | +# mkdir -p $oa_ext_www_content |
| 6 | +# |
| 7 | +#} |
| 8 | + |
| 9 | +auto_config_init() { |
| 10 | + |
| 11 | + echo "${initscript}: Creating USB config folders..." |
| 12 | + mkdir -p $oa_current_config |
| 13 | + mkdir -p $oa_config |
| 14 | + |
| 15 | + echo "${initscript}: Placing config check to rc.local..." |
| 16 | + |
| 17 | + #Preparing autostart for config via USB Stick |
| 18 | + #ensure that the exit is disabled |
| 19 | + sed 's;^exit;#exit;' -i /etc/rc.local |
| 20 | + echo '/etc/init.d/piratebox config &> ' "$pb_usbdir/tmp_apply_config.log" >> /etc/rc.local |
| 21 | + echo 'cat ' "$pb_usbdir/tmp_apply_config.log"' >> ' "$pb_usbdir/apply_config.log" >> /etc/rc.local |
| 22 | + echo 'rm '"$pb_usbdir/tmp_apply_config.log" >> /etc/rc.local |
| 23 | + |
| 24 | + #Fill up USB config folder |
| 25 | + auto_config_export_form_uci && auto_config_transfer_config |
| 26 | +} |
| 27 | + |
| 28 | + |
| 29 | +auto_config_export_form_uci(){ |
| 30 | + mkdir -p $oa_current_config |
| 31 | + echo "Exporting current config to $oa_current_config" |
| 32 | + echo "Getting SSID of iface0 via uci" |
| 33 | + local ssid=$(auto_config_uci_export 'wireless' '@wifi-iface[0].ssid' ) |
| 34 | + echo "Getting txpower of device0 via uci" |
| 35 | + local txpower=$(auto_config_uci_export 'wireless' '@wifi-device[0].txpower' ) |
| 36 | + echo "Getting channel of device0 via uci" |
| 37 | + local channel=$(auto_config_uci_export 'wireless' '@wifi-device[0].channel' ) |
| 38 | + |
| 39 | + echo "Getting hostname via uci" |
| 40 | + local hostname=$(auto_config_uci_export 'system' '@system[0].hostname' ) |
| 41 | + |
| 42 | + echo $ssid > "$oa_current_config_ssid" |
| 43 | + echo $txpower > "$oa_current_config_txpower" |
| 44 | + echo $channel > "$oa_current_config_channel" |
| 45 | + |
| 46 | + echo $hostname > "$oa_current_config_hostname" |
| 47 | +} |
| 48 | + |
| 49 | +auto_config_transfer_config() { |
| 50 | + cp $oa_current_config/* $oa_config |
| 51 | +} |
| 52 | + |
| 53 | +auto_config_uci_export(){ |
| 54 | + #read config via uci end print to stdout, which can be catched |
| 55 | + local config=$1 ; shift |
| 56 | + local section=$1 ; shift |
| 57 | +# local type=$1 ; shift |
| 58 | + |
| 59 | + uci get "$config.$section" |
| 60 | + |
| 61 | +} |
| 62 | + |
| 63 | +auto_config_set_ssid(){ |
| 64 | + echo "--->SSID: $1<----" |
| 65 | + pb_setSSID "$1" |
| 66 | +# uci set "wireless.@wifi-iface[0].ssid=$1" |
| 67 | +} |
| 68 | + |
| 69 | +auto_config_set_txpower(){ |
| 70 | + echo "--->txpower: $1<----" |
| 71 | + uci set "wireless.radio0.txpower=$1" |
| 72 | +} |
| 73 | + |
| 74 | +auto_config_set_channel(){ |
| 75 | + echo "--->channel: $1<----" |
| 76 | + uci set "wireless.@wifi-device[0].channel=$1" |
| 77 | +} |
| 78 | + |
| 79 | +auto_config_set_hostname(){ |
| 80 | + echo "--->hostname: $1<----" |
| 81 | + pb_setHostname $1 |
| 82 | +} |
| 83 | + |
| 84 | +auto_config_lookup_and_set_step(){ |
| 85 | + local in_changed=$1; shift |
| 86 | + local config=$1; shift |
| 87 | + local filename=$1; shift |
| 88 | + local current_status_file=$1; shift |
| 89 | + |
| 90 | + |
| 91 | + if [ -f $filename ] ; then |
| 92 | + if [ "`cat $filename`" != "`cat $current_status_file`" ] ; then |
| 93 | + echo " $config - configuration is different, setting to new value" |
| 94 | + auto_config_set_$config "`cat $filename `" |
| 95 | + changed=1 |
| 96 | + fi |
| 97 | + fi |
| 98 | + |
| 99 | + return $changed |
| 100 | +} |
| 101 | + |
| 102 | +auto_config_lookup_and_set(){ |
| 103 | + #checks defined variables if any file exists and run set to |
| 104 | + echo "Checking $oa_config folder for values to be set" |
| 105 | + #remember if I set anything |
| 106 | + changed=0 |
| 107 | + |
| 108 | + echo " ... Checking ssid $oa_new_config_ssid" |
| 109 | + auto_config_lookup_and_set_step "$changed" 'ssid' "$oa_new_config_ssid" "$oa_current_config_ssid" |
| 110 | + echo " ... Checking txpower $oa_new_config_txpower" |
| 111 | + auto_config_lookup_and_set_step "$changed" 'txpower' "$oa_new_config_txpower" "$oa_current_config_txpower" |
| 112 | + echo " ... Checking channel $oa_new_config_channel" |
| 113 | + auto_config_lookup_and_set_step "$changed" 'channel' "$oa_new_config_channel" "$oa_current_config_channel" |
| 114 | + echo " ... Checking hostname $oa_new_config_hostname" |
| 115 | + auto_config_lookup_and_set_step "$changed" 'hostname' "$oa_new_config_hostname" "$oa_current_config_hostname" |
| 116 | + |
| 117 | + |
| 118 | + if [ "$changed" = "1" ] ; then |
| 119 | + echo "done some changes... saving..." |
| 120 | + uci commit |
| 121 | + return 1 |
| 122 | + fi |
| 123 | + return 0 |
| 124 | +} |
0 commit comments