]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blame - firewall/src/functions.config
Move all packages to root.
[people/ms/ipfire-3.x.git] / firewall / src / functions.config
CommitLineData
8838c71a
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2009 Michael Tremer & Christian Schmidt #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
21
22CONFIG_NONE=0
23CONFIG_TEXT=1
24CONFIG_SQLITE=2
25
26function config_type() {
27 if _config_is_sqlite $1; then
28 echo $CONFIG_SQLITE
29 else
30 echo $CONFIG_TEXT
31 fi
32}
33
34function config_load() {
35 local file
36 local type
37 file=$1
38
39 if ! [ -f "$file" ]; then
40 error "Cannot load config file $file. File does not exist!"
41 exit 1
42 fi
43
44 vecho "Loading config file: $file"
45
46 type=$(config_type $file)
47 if [ "$type" = "$CONFIG_SQLITE" ]; then
48 eval $(_config_load_sqlite $file)
49 else
50 eval $(_config_load_text $file)
51 fi
52}
53
54function _config_is_sqlite() {
55 file $1 2>/dev/null | grep -q "SQLite 3.x database"
56}
57
58function _config_dump_sqlite() {
59 sqlite3 -noheader -column $1 "SELECT * FROM config;"
60}
61
62function _config_load_sqlite() {
63 _config_dump_sqlite $1 | while read KEY VALUE; do
64 echo "$KEY=$VALUE"
65 done
66}
67
68function _config_load_text() {
69 readhash $1
70}