Added _set_edited_theme_details function.
[irreco.git] / script / variables.sh
blob4ed53fbbcf9492b51d060f803eea1cc27fdbc8bb
3 # Variables
6 # Get the absolute path of a file.
7 # Args 1: Relative path to file
8 get_absolute_path() {
9 readlink -f "$1"
10 if [[ "$?" != "0" ]]; then
11 echo "Error: Could not get absolute path to \"$1\"." 1>&2
12 exit 1
16 SCRIPT_NAME=`basename "$0"`
17 SCRIPT_DIR=`get_absolute_path "$PWD"`
18 SCRIPT_TMP_DIR="$SCRIPT_DIR/tmp"
19 SCRIPT_PARENT_DIR=`get_absolute_path "$SCRIPT_DIR/.."`
20 SCRIPT_PATH="$SCRIPT_DIR/$SCRIPT_NAME"
21 BACKEND_DIR=`get_absolute_path ../backend`
22 IRRECO_DIR=`get_absolute_path ../irreco`
23 IRRECO_DATA="$IRRECO_DIR/data"
24 IRRECO_SRC="$IRRECO_DIR/src"
25 INSTALL_DIR=`get_absolute_path ".."`"/install"
26 MAKE_LOG_FILE="$SCRIPT_TMP_DIR/make_log"
27 RUN_LOG_FILE="$SCRIPT_TMP_DIR/run_log"
28 DEB_LOG_FILE="$SCRIPT_TMP_DIR/deb_log"
29 ERROR_CONTEXT=0
30 EXIT_CODE_FILE="$SCRIPT_TMP_DIR/exit_code"
32 mkdir -p "$SCRIPT_TMP_DIR"
34 find_theme_dir()
36 #THEME_DIR='../../../../themes'
37 #if [ ! -d "$THEME_DIR" ]; then
38 # THEME_DIR='../../../themes'
39 # if [ ! -d "$THEME_DIR" ]; then
40 # THEME_DIR='../../themes'
41 # if [ ! -d "$THEME_DIR" ]; then
42 # echo "Cant find theme dir"
43 # exit 1
44 # fi
45 # fi
46 #fi
48 THEME_DIR='../themes'
49 if [ ! -d "$THEME_DIR" ]; then
50 echo "Cant find theme dir"
51 exit 1
54 THEME_DIR=`get_absolute_path "$THEME_DIR"`
57 find_irtrans_dir()
59 #IRTRANS_DIR='../../../../irtrans/'
60 #if [ ! -d "$IRTRANS_DIR" ]; then
61 # IRTRANS_DIR='../../../irtrans/'
62 # if [ ! -d "$IRTRANS_DIR" ]; then
63 # IRTRANS_DIR='../../irtrans/'
64 # if [ ! -d "$IRTRANS_DIR" ]; then
65 # echo "Cant find theme dir"
66 # exit 1
67 # fi
68 # fi
69 #fi
71 IRTRANS_DIR='../irtrans/'
72 if [ ! -d "$IRTRANS_DIR" ]; then
73 echo "Cant find theme dir"
74 exit 1
77 IRTRANS_DIR=`get_absolute_path "$IRTRANS_DIR"`
78 IRTRANS_SHLIB_DIR="$IRTRANS_DIR/shlib"
79 IRTRANS_IRSERVER_DIR="$IRTRANS_DIR/irserver"
84 # Utility functions
87 create_install_dir()
89 if [ ! -e "$INSTALL_DIR" ]; then
90 mkdir "$INSTALL_DIR"
91 check_exit_code "$?"
95 scratchbox_need()
97 if [[ "$_SBOX_DIR" == "" ||
98 "$_SBOX_RESTART_FILE" == "" ||
99 "$_SBOX_SHELL_PID" == "" ||
100 "$_SBOX_USER_GROUPNAME" == "" ]]; then
101 echo "Error: Need scratchbox."
102 exit 1
105 #which sb-conf &> /dev/null
106 #if [[ "$?" != "0" ]]; then
107 # echo "Error: Need scratchbox."
108 # exit 1
112 scratchbox_avoid()
114 if [[ "$_SBOX_DIR" != "" ||
115 "$_SBOX_RESTART_FILE" != "" ||
116 "$_SBOX_SHELL_PID" != "" ||
117 "$_SBOX_USER_GROUPNAME" != "" ]]; then
118 echo "Error: Cant run this command inside scratchbox."
119 exit 1
122 #which sb-conf &> /dev/null
123 #if [[ "$?" == "0" ]]; then
124 # echo "Error: Cant run this command inside scratchbox."
125 # exit 1
129 print_title()
131 TITLE="$1"
132 echo -en "\n___ "
133 echo -n "$TITLE "
135 LEN=`echo ${#TITLE}`
136 for ((LEN += 6; LEN <= 80; LEN++)); do
137 echo -n _
138 done
139 echo
143 # Check log for error & warnings
144 # Args 1: Log file
145 # 2: Exit on match
146 check_log()
148 REGEX="(warning|error|cannot find"
149 REGEX="$REGEX|^[0-9a-zA-Z\/._-]+\.[cho]:"
150 REGEX="$REGEX|^[0-9a-zA-Z\/._-]+:[0-9]+"
151 REGEX="$REGEX|^[0-9a-zA-Z\/._-]+:[0-9]+:[0-9]+"
152 REGEX="$REGEX|^:[0-9a-zA-Z\/._-]+"
153 REGEX="${REGEX})"
155 egrep -i -A $ERROR_CONTEXT -B $ERROR_CONTEXT --color=yes "$REGEX" "$1"
156 EXIT_CODE="$?"
157 if [[ "$2" == "1" ]]; then
158 if [[ "$EXIT_CODE" != "0" ]]; then
159 echo "... none"
160 else
161 exit 1
166 save_exit_code()
168 "$@"
169 echo "$?" > "$EXIT_CODE_FILE"
172 get_exit_code()
174 EXIT_CODE=`cat "$EXIT_CODE_FILE"`
175 rm "$EXIT_CODE_FILE"
176 return $EXIT_CODE
180 # Stop script if exit code is not 0
182 # Usage: check_exit_code "$?"
183 check_exit_code()
185 if [[ "$1" != "0" ]]; then
186 if [[ "$2" != "" ]]; then
187 echo "Error:" "$2" "$3" "$4" "$5"
189 echo "Exit code: $1"
190 exit "$1"
194 scripts_src_pad()
196 while read LINE; do
197 echo "\\"
198 echo -n " $LINE"
199 LEN=32-${#LINE}
200 for ((; LEN > 0; LEN--)); do
201 echo -n " "
202 done
203 done
204 echo
210 # Generic build functions
213 generic_make()
215 MAKE_ARGS=("$@")
216 TITLE_FUNC="$1"
218 $TITLE_FUNC "MAKE"
219 save_exit_code make "${MAKE_ARGS[@]:1}" 2>&1 | tee "$MAKE_LOG_FILE"
221 $TITLE_FUNC "ERRORS"
222 check_log "$MAKE_LOG_FILE" "1"
223 get_exit_code
224 check_exit_code "$?"
227 generic_clean()
229 TITLE_FUNC="$1"
231 $TITLE_FUNC "CLEAN"
233 if [ -e "Makefile" ]; then
234 make uninstall
235 make clean
236 make distclean
239 if [ -e "autoclean.sh" ]; then
240 ./autoclean.sh
246 # Save current sb_target to file,
247 # and return 0 if it is the same as current target.
249 match_sb_target()
251 SB_TARGET_FILE="$1"
252 CURRENT_TARGET=`sb-conf current`
254 if [ -f "$SB_TARGET_FILE" ]; then
255 PREVIOUS_TARGET=`cat "$SB_TARGET_FILE"`
256 else
257 PREVIOUS_TARGET=""
260 #echo "SB_TARGET_FILE = $SB_TARGET_FILE"
261 #echo "CURRENT_TARGET = $CURRENT_TARGET"
262 #echo "PREVIOUS_TARGET = $PREVIOUS_TARGET"
264 if [[ "$CURRENT_TARGET" != "$PREVIOUS_TARGET" ]]; then
265 echo "Saving \"$CURRENT_TARGET\" to \"$SB_TARGET_FILE\""
266 echo "$CURRENT_TARGET" > "$SB_TARGET_FILE"
267 check_exit_code "$?"
268 #echo return 1
269 return 1
272 #echo return 0
273 return 0