-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.sh
90 lines (70 loc) · 1.45 KB
/
functions.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
#!/bin/bash
get_filename () {
if [[ $1 == *CMakeLists.txt ]]; then
if [ $1 == "CMakeLists.txt" ]; then
echo "packages/CMakeLists.txt"
else
echo $1
fi
else
path=$(find -name "$1.cmake")
echo ${path:2}
fi
}
replace_option () {
echo "replace_option $1 $2 $3"
sed -i "s/$2/$3/g" $(get_filename $1)
}
append_option () {
echo "append_option $1 $3"
fn=$(get_filename "$1")
if ! grep -- "$3" $fn; then
sed -i "/$2/a \ $3" $fn
fi >/dev/null 2>&1
}
append_option_exact () {
echo "append_option $1 $3"
fn=$(get_filename "$1")
if ! (grep -A1 "$2" $fn | grep -- "$3"); then
sed -i "/$2/a \ $3" $fn
fi >/dev/null 2>&1
}
add_option () {
echo "add_option $1 $3"
fn=$(get_filename "$1")
if ! (grep -A1 "$2" $fn | grep -- "$3"); then
sed -i "/$2/i \ $3" $fn
fi >/dev/null 2>&1
}
comment_line () {
echo "comment_line $1 $2"
sed -i "/^\s*$2/s/^/#/g" $(get_filename $1)
}
uncomment_line () {
echo "uncomment_line $1 $2"
sed -i "/^#.*$2/s/^#//g" $(get_filename $1)
}
delete_line () {
echo "delete_line $1 $2"
sed -i "/$2/d" $(get_filename $1)
}
replace_patch () {
sed -i "s/$2/$3/g" packages/$1.patch
}
echo_info () {
echo -e '\e[1;38;5;120m'$1'\e[0m'
}
echo_warn () {
echo -e '\e[1;38;5;166m'$1'\e[0m'
}
echo_error () {
echo -e '\e[1;38;5;196m'$1'\e[0m'
}
echo_build () {
echo_info "+ ninja $@"
ninja $@
if [ $? -ne 0 ]; then
echo_error "Error in building $1"
exit
fi
}