Skip to content

Commit 0dd2561

Browse files
committed
init commit
0 parents  commit 0dd2561

12 files changed

Lines changed: 572 additions & 0 deletions

bin/auto_config.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
## Initiates the autoconfig and lateron a restart
4+
5+
. ../cfg/auto.config.sh
6+
. ../lib/autoconfig.sh
7+
8+
DEBUG=1
9+
10+
_start_

cfg/auto.config

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
###offlineArt Modfications
3+
4+
#### Content Folder
5+
#### Will contain the files from WebUI
6+
##oa_ext_www_content="$pb_usbdir/www_content"
7+
8+
#### SetUp the folders for non-terminal configuration of the artBox
9+
#### config/set contains nothing and there will be looked for changes (new files)
10+
oa_config="$pb_usbdir/config"
11+
12+
#### config contains the current configuration
13+
oa_current_config="/tmp/config"
14+
15+
oa_cfg_ssid="ssid.txt"
16+
oa_cfg_txpower="txpower.txt"
17+
oa_cfg_channel="channel.txt"
18+
oa_cfg_hostname="hostname.txt"
19+
20+
#export datasets from the current uci config
21+
oa_current_config_ssid="$oa_current_config/$oa_cfg_ssid"
22+
oa_current_config_txpower="$oa_current_config/$oa_cfg_txpower"
23+
oa_current_config_channel="$oa_current_config/$oa_cfg_channel"
24+
oa_current_config_hostname="$oa_current_config/$oa_cfg_hostname"
25+
26+
#import datasets which changes currents setup
27+
oa_new_config_ssid="$oa_config/$oa_cfg_ssid"
28+
oa_new_config_txpower="$oa_config/$oa_cfg_txpower"
29+
oa_new_config_channel="$oa_config/$oa_cfg_channel"
30+
oa_new_config_hostname="$oa_config/$oa_cfg_hostname"
31+

cfg/auto.config.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
#### Temporary folder to put the current output to
4+
cfg_tmp_folder=/tmp/auto_config
5+
6+
#### Folder where the user changable files are located
7+
cfg_auto_folder=/tmp/config
8+
9+
#### Enabled-Modules folder
10+
cfg_modules=/tmp/modules.enabled
11+

lib/autoconfig.common

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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+
}

lib/autoconfig.sh

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/sh
2+
3+
MODULE_LIST=""
4+
5+
6+
#Default compare and set
7+
auto_config_lookup_and_set(){
8+
local config=$1; shift
9+
local filename=$1; shift
10+
local current_status_file=$1; shift
11+
12+
[ $DEBUG ] && echo "lookup_set: config - $config"
13+
[ $DEBUG ] && echo "lookup_set: filename - $filename"
14+
[ $DEBUG ] && echo "lookup_set: current_status_file - $current_status_file"
15+
16+
if [ -f $filename ] ; then
17+
if [ "`cat $filename`" != "`cat $current_status_file`" ] ; then
18+
echo " $config - configuration is different, setting to new value"
19+
func_set_system_config_$config "`cat $filename `" "`cat $current_status_file`"
20+
changed=1
21+
fi
22+
fi
23+
24+
return $changed
25+
}
26+
27+
#Processes all modules.enabled
28+
auto_config_process_all() {
29+
30+
#### Global var
31+
changed=0
32+
uci_commit_needed="0"
33+
####
34+
35+
for config in $MODULE_LIST
36+
do
37+
echo "Working on $config"
38+
func_read_system_config_$config $cfg_tmp_folder
39+
func_compare_and_set_$config
40+
#save new set value, which will be moved later
41+
func_read_system_config_$config $cfg_tmp_folder
42+
done
43+
44+
if [ "$changed" = "1" ] ; then
45+
echo "done some changes.."
46+
if [ "$uci_commit_needed" == "1" ] ; then
47+
echo "doing uci commit"
48+
uci commit
49+
fi
50+
fi
51+
return 0
52+
}
53+
54+
_load_modules_() {
55+
local module_path=$1 ; shift
56+
57+
58+
local available_module_files=$(ls $cfg_modules)
59+
60+
[ $DEBUG ] && echo "modules_folder $cfg_modules "
61+
[ $DEBUG ] && echo "ls result: $available_module_files"
62+
63+
for module in $available_module_files
64+
do
65+
echo -n "Loading module $module .."
66+
. $cfg_modules/$module
67+
echo "done"
68+
done
69+
70+
[ $DEBUG ] && echo "Available modules: $MODULE_LIST "
71+
72+
return 0
73+
}
74+
75+
76+
_start_() {
77+
78+
79+
# check if $cfg_modules is available
80+
if [ ! -d $cfg_modules ] ; then
81+
echo "config module folder $cfg_modules does not exists"
82+
exit 1
83+
fi
84+
85+
# load modules
86+
_load_modules_ || exit $?
87+
88+
# check & create folder, if needed
89+
mkdir -p $cfg_tmp_folder
90+
mkdir -p $cfg_auto_folder
91+
92+
93+
# Run configuration
94+
auto_config_process_all
95+
96+
# Transfer exported config values
97+
cp $cfg_tmp_folder/* $cfg_auto_folder
98+
}
99+
100+
uci() {
101+
102+
echo $*
103+
}

lib/template_module.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/sh
2+
#
3+
# AutoConfiguration via USB file
4+
# This is a template module, which contains empty functions, which can be called
5+
#
6+
# name shema is
7+
# nn_name.sh
8+
#
9+
# functions are named with
10+
# name_fffff
11+
# where ffff is the predifined template step.
12+
13+
# Available global variables
14+
# CONFIG_TMP_STORE
15+
# CONFIG_STORE
16+
17+
18+
#uncommend the following line for REAL modules
19+
#MODULE_LIST="$MODULE_LIST template"
20+
21+
template_myself="template" #contains the name of the module
22+
template_config_file="template"
23+
24+
# Read configuration out of the system and save it to template_system_config depending on the
25+
# parameter
26+
func_read_system_config_template() {
27+
local path=$1 ; shift
28+
echo "" > $path/$template_config_file
29+
}
30+
31+
# Parse the first parameter with the changed value
32+
# do the stuff you need to do for changing the configuratioj
33+
func_set_system_config_template(){
34+
local value=$1 ; shift
35+
local old_value=$1 ; shift
36+
}
37+
38+
39+
#This function is called to compare content and et differences
40+
# to initiate a restart in the end, set "changed=1"
41+
# the easiest comparison can be used with auto_default_compare
42+
# see below
43+
func_compare_and_set_template(){
44+
45+
auto_config_lookup_and_set "$openwrt_ssid_myself" \
46+
"$cfg_auto_folder/$openwrt_ssid_config_file" \
47+
"$cfg_tmp_folder/$openwrt_ssid_config_file"
48+
49+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh
2+
#
3+
# AutoConfiguration via USB file
4+
##
5+
# Set SSID on OpenWRT
6+
#
7+
8+
9+
#uncommend the following line for REAL modules
10+
MODULE_LIST="$MODULE_LIST openwrt_ssid"
11+
12+
openwrt_ssid_myself="openwrt_ssid" #contains the name of the module
13+
openwrt_ssid_config_file="ssid.txt"
14+
15+
interface_no=0
16+
17+
# Read configuration out of the system and save it to openwrt_ssid_system_config depending on the
18+
# parameter
19+
func_read_system_config_openwrt_ssid() {
20+
local path=$1 ; shift
21+
22+
echo "Getting SSID of iface-$interface_no via uci"
23+
uci get "wireless.@wifi-iface[$interface_no].ssid" > $path/$openwrt_ssid_config_file
24+
}
25+
26+
# Parse the first parameter with the changed value
27+
# do the stuff you need to do for changing the configuratioj
28+
func_set_system_config_openwrt_ssid(){
29+
local value=$1 ; shift
30+
uci set "wireless.@wifi-iface[$interface_no].ssid=$value"
31+
}
32+
33+
34+
#This function is called to compare content and et differences
35+
# to initiate a restart in the end, set "changed=1"
36+
# the easiest comparison can be used with auto_default_compare
37+
# see below
38+
func_compare_and_set_openwrt_ssid(){
39+
40+
41+
auto_config_lookup_and_set "$openwrt_ssid_myself" \
42+
"$cfg_auto_folder/$openwrt_ssid_config_file" \
43+
"$cfg_tmp_folder/$openwrt_ssid_config_file"
44+
45+
46+
}

0 commit comments

Comments
 (0)