-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.sh
219 lines (193 loc) · 5.13 KB
/
helpers.sh
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/bash
# returns full path to the script that holds the current line of code
this_line_location() {
if [ -n "$ZSH_VERSION" ]
then
this_line_location_path="$( dirname $( realpath -s ${(%):-%x} ) )"
elif [ -n "$BASH_VERSION" ]
then
this_line_location_path="$( dirname $( realpath -s ${BASH_SOURCE[0]} ) )"
else
>&2 echo "Shell interpreter does NOT supported. Use bash or zsh."
exit 1
fi
printf $this_line_location_path
}
# version_compare <v1> <v2> function
# "=" if equal
# ">" if v1 greater than v2
# "<" if v1 less than v2
version_compare () {
if [[ $1 == $2 ]]
then
printf "="
return 0;
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
printf ">"
return 0;
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
printf "<"
return 0;
fi
done
printf "="
return 0;
}
clean_directory()
{
local readonly dir_to_clean="$1";
if [ -d "$dir_to_clean" ] && [ -n "$dir_to_clean" ] && [ "$dir_to_clean" != "/" ]
then
echo " ---> Cleaning directory '$dir_to_clean' .."
rm -rf $dir_to_clean/*
fi
}
on_abort()
{
if [ "$#" -eq 0 ]
then
echo ">&2 usage: $FUNCNAME message" >&2
exit 1
fi
echo >&2 "
***************************************************
*** ABORTED: $@
***************************************************
"
trap : 0
exit 1
}
on_startup()
{
if [ "$#" -eq 0 ]
then
>&2 echo "usage: $FUNCNAME message" >&2
exit 1
fi
echo "
***********************************************
*** STARTUP: $@
***********************************************"
}
on_success()
{
local readonly rv=$?
if [ "$#" -eq 0 ]
then
>&2 echo "usage: $FUNCNAME message" >&2
exit 1
fi
echo "
***********************************************
*** DONE: $@
***********************************************
"
trap : 0
exit $rv
}
# usage: cur_user_has_write_permissions <dir_to_check>"
cur_user_has_write_permissions()
{
if [ "$#" -ne 1 ]
then
printf "false";
return -1;
fi
local directory_to_check=$1
if [ -w $directory_to_check ]
then
printf "true"
else
printf "false"
fi
return 0
}
sync_repo()
{
if [ "$#" -ne 3 ]; then
>&2 echo "usage: sync_repo <work_dir> <link> <hash>"
return -1
fi
local repo_work_dir=$1
local repo_link=$2
local repo_hash=$3
echo " ---> Repo dir '$repo_work_dir', repo link '$repo_link', repo hash '$repo_hash'"
if ! [ -d $repo_work_dir ]
then
git -C "$( dirname $repo_work_dir )" clone $repo_link || return -1
fi
local git_branch_name=$( echo "$repo_hash" | rev | cut -d"/" -f1 | rev )
if [[ $( git -C $repo_work_dir merge-base $repo_hash $repo_hash ) == $repo_hash* ]]
then
# SHA1 were passed
git_branch_name="tmp"
fi
git -C $repo_work_dir remote set-url origin "$repo_link" || return -1
git -C $repo_work_dir checkout -B $git_branch_name || return -1
git -C $repo_work_dir fetch --all --prune || return -1
git -C $repo_work_dir reset --hard $repo_hash || return -1
git -C $repo_work_dir submodule update --init || return -1
}
# add_path <var> <path_to_add> [after]
add_path_to_var()
{
if ! [ $1 ]
then
printf "$2"
else
if ! echo "$1" | grep -Eq "(^|:)$2($|:)"
then
if [ "$3" = "after" ]
then
printf "$1:$2"
else
printf "$2:$1"
fi
else
printf "$1"
fi
fi
}
# get_ip_by_interface_name <interface_name>
get_ip_by_interface_name()
{
if [ "$#" -ne 1 ]; then
>&2 echo "usage: get_ip_by_interface_name <interface_name>"
return -1
fi
local interface_name="$1"
local ip_addr=$( ifconfig $interface_name | grep 'inet addr:'| cut -d: -f2 | awk '{ print $1}' )
printf "$ip_addr"
}
typeset -A cmake_ide_generators
cmake_ide_generators["codeblocks"]="CodeBlocks - Unix Makefiles"
cmake_ide_generators["codelite"]="CodeLite - Unix Makefiles"
cmake_ide_generators["sublime"]="Sublime Text 2 - Unix Makefiles"
cmake_ide_generators["kate"]="Kate - Unix Makefiles"
cmake_ide_generators["eclipse"]="Eclipse CDT4 - Unix Makefiles"
project_source_dir=$( dirname $( this_line_location ) )
project_third_party_dir=$project_source_dir/3rd_party
sdl_core_source_dir=$project_source_dir/sdl_core
project_binary_dir="$(dirname $sdl_core_source_dir)/build_$(basename $sdl_core_source_dir)"
build_utils_source_dir=$project_source_dir/sdl_infrastructure
sdl_atf_source_dir=$project_source_dir/sdl_atf
sdl_atf_test_scripts_source_dir=$project_source_dir/sdl_atf_test_scripts
sdl_core_api_dir="$sdl_core_source_dir/src/components/interfaces"