-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp_config.sh
More file actions
77 lines (66 loc) · 2.24 KB
/
Copy pathwp_config.sh
File metadata and controls
77 lines (66 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
verbose 15 "Loading wp_config.sh"
declare -A CONFIG
function read_configuration() {
verbose 10 "function: $FUNCNAME $1"
local file=$1
verbose 5 "Loading configuration from ${file}"
while read line
do
if [[ $line == *=* ]]
then
key=$(trim "${line%%=*}")
value=$(trim "${line#*=}")
CONFIG[$key]=$value
fi
done < "$file"
if [[ ${#CONFIG[@]} = 0 ]]
then
echo "Empty Configuration File or file does not contain"
echo "necessary values!"
exit EXIT_MALFORMED_CONFIG
fi
}
# If the user specifies a configuration use that, if not look in the
# same directory as the file being posted for a file of the same name
# but with the extension .config and a leading dot to hide it from
# normal directry scans. If that is not found look in the same
# directory for .wp_post.config, lastly look in ~/.wp_post.config.
# The reason for looking twice in the file directory is so that we can
# have multiple blogs in the same directory each consisting of only
# one file or a single blog consisting of many files.
# When looking for config files we do not look in a global standard
# location so as to avoid embarrasing mistakes like posting your sex
# blog to the one you share with the rest of your family.
# Expects the blog_fn argument to be a full path.
function load_configuration() {
verbose 10 "function: $FUNCNAME $1 $2"
local config_fn="$1"
local blog_fn=$2
if [[ "$config_fn" = "" ]]
then
verbose 3 "No configuration file specified, trying default locations and names"
config_fn=".${blog_fn}.config"
if [[ ! -f "$config_fn" ]]
then
verbose 3 "Config named for file <${config_fn}> does not exist"
if [[ "${blog_fn}" = *"/"* ]]
then
d="${blog_fn%/*}/"
else
d=""
fi
config_fn="${d}.wp_post.config"
fi
fi
if [[ ! -f "$config_fn" ]]
then
die "Configuration file <${config_fn}> does not exist"
fi
read_configuration "$config_fn"
}
function make_config_template() {
verbose 10 "function: $FUNCNAME $1"
echo "url=xxxx"
echo "user=yyyy"
echo "pass=zzzz"
}