-
Notifications
You must be signed in to change notification settings - Fork 22
/
config.bash
197 lines (179 loc) · 7.85 KB
/
config.bash
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# Copyright © 2017-2018 Dmytro Katyukha <dmytro.katyukha@gmail.com>
#######################################################################
# This Source Code Form is subject to the terms of the Mozilla Public #
# License, v. 2.0. If a copy of the MPL was not distributed with this #
# file, You can obtain one at http://mozilla.org/MPL/2.0/. #
#######################################################################
if [ -z "$ODOO_HELPER_LIB" ]; then
echo "Odoo-helper-scripts seems not been installed correctly.";
echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)";
exit 1;
fi
if [ -z "$ODOO_HELPER_COMMON_IMPORTED" ]; then
source "$ODOO_HELPER_LIB/common.bash";
fi
ohelper_require 'git';
# -----------------------------------------------------------------------------
# function to print odoo-helper config
function config_print {
echo "PROJECT_ROOT_DIR=$PROJECT_ROOT_DIR;";
echo "PROJECT_CONFIG_VERSION=$PROJECT_CONFIG_VERSION;";
echo "ODOO_VERSION=$ODOO_VERSION;";
echo "ODOO_BRANCH=$ODOO_BRANCH;";
echo "CONF_DIR=$CONF_DIR;";
echo "LOG_DIR=$LOG_DIR;";
echo "LOG_FILE=$LOG_FILE;";
echo "LIBS_DIR=$LIBS_DIR;";
echo "DOWNLOADS_DIR=$DOWNLOADS_DIR;";
echo "ADDONS_DIR=$ADDONS_DIR;";
echo "DATA_DIR=$DATA_DIR;";
echo "BIN_DIR=$BIN_DIR;";
echo "VENV_DIR=$VENV_DIR;";
echo "ODOO_PATH=$ODOO_PATH;";
echo "ODOO_CONF_FILE=$ODOO_CONF_FILE;";
echo "ODOO_TEST_CONF_FILE=$ODOO_TEST_CONF_FILE;";
echo "ODOO_PID_FILE=$ODOO_PID_FILE;";
echo "BACKUP_DIR=$BACKUP_DIR;";
echo "REPOSITORIES_DIR=$REPOSITORIES_DIR;";
if [ -n "$INIT_SCRIPT" ]; then
echo "INIT_SCRIPT=$INIT_SCRIPT;";
fi
if [ -n "$ODOO_REPO" ]; then
echo "ODOO_REPO=$ODOO_REPO;";
fi
if [ -n "$USE_UNBUFFER" ]; then
echo "USE_UNBUFFER=$USE_UNBUFFER";
fi
}
# Function to configure default variables
function config_set_defaults {
if [ -z "$PROJECT_ROOT_DIR" ]; then
echo -e "${REDC}There is no PROJECT_ROOT_DIR set!${NC}";
return 1;
fi
PROJECT_CONFIG_VERSION="${PROJECT_CONFIG_VERSION:-$ODOO_HELPER_CONFIG_VERSION}";
CONF_DIR="${CONF_DIR:-$PROJECT_ROOT_DIR/conf}";
ODOO_CONF_FILE="${ODOO_CONF_FILE:-$CONF_DIR/odoo.conf}";
ODOO_TEST_CONF_FILE="${ODOO_TEST_CONF_FILE:-$CONF_DIR/odoo.test.conf}";
LOG_DIR="${LOG_DIR:-$PROJECT_ROOT_DIR/logs}";
LOG_FILE="${LOG_FILE:-$LOG_DIR/odoo.log}";
LIBS_DIR="${LIBS_DIR:-$PROJECT_ROOT_DIR/libs}";
DOWNLOADS_DIR="${DOWNLOADS_DIR:-$PROJECT_ROOT_DIR/downloads}";
ADDONS_DIR="${ADDONS_DIR:-$PROJECT_ROOT_DIR/custom_addons}";
DATA_DIR="${DATA_DIR:-$PROJECT_ROOT_DIR/data}";
BIN_DIR="${BIN_DIR:-$PROJECT_ROOT_DIR/bin}";
VENV_DIR="${VENV_DIR:-$PROJECT_ROOT_DIR/venv}";
ODOO_PID_FILE="${ODOO_PID_FILE:-$PROJECT_ROOT_DIR/odoo.pid}";
ODOO_PATH="${ODOO_PATH:-$PROJECT_ROOT_DIR/odoo}";
BACKUP_DIR="${BACKUP_DIR:-$PROJECT_ROOT_DIR/backups}";
REPOSITORIES_DIR="${REPOSITORIES_DIR:-$PROJECT_ROOT_DIR/repositories}";
# No default value for init script
# INIT_SCRIPT="${INIT_SCRIPT}";
}
# Return default config for specified tool
# TODO: look at project level for configuration files
# config_get_default_tool_conf <conf-name>
function config_get_default_tool_conf {
local default_conf_dir="${ODOO_HELPER_LIB}/default_config";
local tool_name="$1";
local git_repo_root_dir;
if git_is_git_repo "$(pwd)"; then
git_repo_root_dir=$(git_get_abs_repo_path "$(pwd)");
fi
if [ -n "$git_repo_root_dir" ] && [ -f "$git_repo_root_dir/$tool_name" ]; then
echo "$git_repo_root_dir/$tool_name";
elif [ -f "$CONF_DIR/$tool_name" ]; then
echo "$CONF_DIR/$tool_name";
elif [ -f "$default_conf_dir/$tool_name" ]; then
echo "$default_conf_dir/$tool_name";
else
return 1;
fi
}
# Check current project configuration
function config_check_project_config {
local proj_conf_version=${PROJECT_CONFIG_VERSION:-0};
local expected_conf_version=${ODOO_HELPER_CONFIG_VERSION};
if [[ $proj_conf_version -ge $expected_conf_version ]]; then
return 0;
fi
echoe -e "${YELLOWC}WARNING${NC}: Current project config version" \
"${YELLOWC}${proj_conf_version}${NC} is less than" \
"odoo-helper expected config version ${YELLOWC}${expected_conf_version}${NC}.\n" \
"Please, upgrade config file for this project (${YELLOWC}$ODOO_HELPER_PROJECT_CONF${NC})!";
if [ -z "$PROJECT_CONFIG_VERSION" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}PROJECT_CONFIG_VERSION${NC} is not specified.";
fi
if [ -z "$PROJECT_ROOT_DIR" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}PROJECT_ROOT_DIR${NC} is not specified.";
fi
if [ -z "$CONF_DIR" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}CONF_DIR${NC} is not specified.";
fi
if [ -z "$ODOO_CONF_FILE" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}ODOO_CONF_FILE${NC} is not specified.";
fi
if [ -z "$ODOO_TEST_CONF_FILE" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}ODOO_TEST_CONF_FILE${NC} is not specified.";
fi
if [ -z "$LOG_DIR" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}LOG_DIR${NC} is not specified.";
fi
if [ -z "$LOG_FILE" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}LOG_FILE${NC} is not specified.";
fi
if [ -z "$LIBS_DIR" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}LIBS_DIR${NC} is not specified.";
fi
if [ -z "$DOWNLOADS_DIR" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}DOWNLOADS_DIR${NC} is not specified.";
fi
if [ -z "$ADDONS_DIR" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}ADDONS_DIR${NC} is not specified.";
fi
if [ -z "$DATA_DIR" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}DATA_DIR${NC} is not specified.";
fi
if [ -z "$BIN_DIR" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}BIN_DIR${NC} is not specified.";
fi
if [ -z "$ODOO_PID_FILE" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}ODOO_PID_FILE${NC} is not specified.";
fi
if [ -z "$ODOO_PATH" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}ODOO_PATH${NC} is not specified.";
fi
if [ -z "$BACKUP_DIR" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}BACKUP_DIR${NC} is not specified.";
fi
if [ -z "$REPOSITORIES_DIR" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}REPOSITORIES_DIR${NC} is not specified.";
fi
if [ -z "$ODOO_VERSION" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}ODOO_VERSION${NC} is not specified.";
fi
if [ -z "$ODOO_BRANCH" ]; then
echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}ODOO_BRANCH${NC} is not specified.";
fi
}
# Load project configuration. No args provided
function config_load_project {
local project_conf;
local work_dir="${1:-$(pwd)}";
if [ -z "$PROJECT_ROOT_DIR" ]; then
# Load project conf, only if it is not loaded yet.
project_conf=$(search_file_up "$work_dir" "$CONF_FILE_NAME");
if [ -f "$project_conf" ] && [ ! "$project_conf" == "$HOME/odoo-helper.conf" ]; then
echov -e "${LBLUEC}Loading conf${NC}: $project_conf";
ODOO_HELPER_PROJECT_CONF=$project_conf;
source "$project_conf";
# Set configuration defaults
config_set_defaults;
fi
if [ -z "$PROJECT_ROOT_DIR" ]; then
echoe -e "${YELLOWC}WARNING${NC}: no project config file found!";
else
config_check_project_config;
fi
fi
}