-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.sh
84 lines (73 loc) · 1.51 KB
/
util.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
#!/bin/sh
# $Id$
function prepend_to_env_variable()
{
local env_variable=$1
local new_arguments=$2
local seperate_field=" "
if [[ $# -eq 3 ]]; then
local seperate_field=$3
fi
local cmd="export $env_variable=\"${new_arguments}${seperate_field}\$${env_variable}\""
eval "$cmd"
return
}
function append_to_env_variable()
{
local env_variable=$1
local new_arguments=$2
local seperate_field=" "
if [[ $# -eq 3 ]]; then
local seperate_field=$3
fi
local cmd="export $env_variable=\"\$${env_variable}${seperate_field}${new_arguments}\""
eval "$cmd"
return
}
function LD_LIBRARY_PATH_to_rpath()
{
local ld_lib_paths=$(echo $LD_LIBRARY_PATH | sed -e "s/:/\n/g" | /bin/sort -u)
local lib_path=
for lib_path in $ld_lib_paths; do
if [ "$lib_path" != "." ]; then
if [ -d $lib_path ]; then
echo -n "-Wl,-rpath=$lib_path "
fi
fi
done
echo
}
function cecho()
{
local black='\E[30;47m'
local red='\E[31;47m'
local green='\E[32;47m'
local yellow='\E[33;47m'
local blue='\E[34;47m'
local magenta='\E[35;47m'
local cyan='\E[36;47m'
local white='\E[37;47m'
local color=$1
local message="$2"
local command="echo -en \$$color\$message"
eval $command
tput sgr0
echo
}
function _error_exit_()
{
cecho "red" "$*"
echo
exit 1
}
function _warn_()
{
cecho "cyan" "$*"
echo
}
function sort_and_uniq()
{
if [ "$*" != "" ]; then
echo "$*" | tr ' ' '\n' | sort -u
fi
}