-
Notifications
You must be signed in to change notification settings - Fork 1
/
sys
executable file
·259 lines (238 loc) · 9.51 KB
/
sys
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/bin/bash
#SPDX-License-Identifier: EPL-2.0
#Copyright 2019 DaSoftver LLC. Written by Sergio Mijatovic.
#Licensed under Eclipse Public License - v 2.0. See LICENSE file.
#On the web https://vely.dev/ - this file is part of Vely framework.
# Set variables for building and installing a Vely application.
# If your system doesn't conform, you can change these variables to fit
# VV_OSNAME_ID is 0(archlinux), 1(ubuntu 22), 2(ubuntu 20), 3(ubuntu 18), 4(debian 10), 5(debian 11), 6(fedora 37), 7(fedora 38), 8(redhat 8), 9(redhat 9), 10(opensuse tumbleweed), 11(mageia 8)...
function lowest_version() {
echo "$@" | sed 's/ /\n/g'| sort -V | head -n 1
}
#utility to check for versions matching
if [ "$1" == "greater_than_eq" ]; then
L=$(lowest_version "$2" "$3" )
if [ "$L" == "$3" ]; then echo "1"; else echo "0"; fi
exit 0
fi
#do not do all twice if already done
if [ "$VV_SYSTEM_DONE" != "1" ]; then
#determine operating system
. /etc/os-release
#check if lsb-release present, and use it to override os-release, as it is generally more accurate
if [ -f "/etc/lsb-release" ]; then
. /etc/lsb-release
fi
#get the leading part in case of split (such as OSNAME-xxx)
export SUBID=$(echo $ID|awk -F "-" '{print $2}')
export ID=$(echo $ID|awk -F "-" '{print $1}')
export VV_PLATFORM_ID=$ID
if [[ "$ID" == "opensuse" && "$SUBID" == "tumbleweed" ]]; then
#no version really for tumbleweed as it's just a date of build, not a designation of features
export VERSION_ID="tumbleweed"
fi
if [ "$VV_PLATFORM_ID" == "sles" ]; then
export VV_PLATFORM_ID="opensuse"
fi
if [ "$VV_PLATFORM_ID" == "ol" ]; then
export VV_PLATFORM_ID="oracle_linux"
fi
if [ "$VV_PLATFORM_ID" == "rhel" ]; then
export VV_PLATFORM_ID="redhat"
fi
#version is always whatever comes prior to the first dot (usually just a number), even for Ubuntu (where version is technically 20.04 for instance, it's 20) to make things simpler. The actual version is always the lowest one for any release, so if the latest version of RH is 8.3, it's 8.1 that we try to use if available (to ensure compatibility), and thus we just call it "8".
if [ "$VERSION_ID" == "" ]; then
#if VERSION_ID not available, try DISTRIB_RELEASE , typically in lsb-release
export VERSION_ID="$DISTRIB_RELEASE"
fi
if [ "$VERSION_ID" == "" ]; then
#if VERSION_ID still empty, make it "rolling"
export VERSION_ID="rolling"
fi
export VV_PLATFORM_VERSION=$(sed 's/\([^\.]\+\)\..*/\1/g'<<<$VERSION_ID)
export VV_VERSION_ID="$VERSION_ID"
if [[ "$VV_PLATFORM_ID" == "fedora" || "$VV_PLATFORM_ID" == "redhat" || "$VV_PLATFORM_ID" == "opensuse" || "$VV_PLATFORM_ID" == "mageia" ]]; then
export VV_ISFEDORA=1
elif [ "$VV_PLATFORM_ID" == "arch" ]; then
export VV_PLATFORM_ID="archlinux"
export VV_ISARCH=1
elif [[ "$VV_PLATFORM_ID" == "ubuntu" || "$VV_PLATFORM_ID" == "debian" || "$VV_PLATFORM_ID" == "raspbian" ]]; then
export VV_ISDEBIAN=1
if [ "$UBUNTU_CODENAME" != "" ]; then
export VV_DEBIAN_DISTRIBUTION=$UBUNTU_CODENAME
else
export VV_DEBIAN_DISTRIBUTION=$VERSION_CODENAME
fi
#DISTRIB_CODENAME would come from lsb-release, if present, take it if not available yet
if [[ "$VV_DEBIAN_DISTRIBUTION" == "" && "$DISTRIB_CODENAME" != "" ]]; then
export VV_DEBIAN_DISTRIBUTION=$DISTRIB_CODENAME
fi
else
#try to figure out what this system may be, and use that
for i in $(echo "$ID_LIKE"); do
if [ "$i" == "fedora" ]; then
export VV_ISFEDORA=1
export VV_PLATFORM_ID="fedora"
break
elif [ "$i" == "arch" ]; then
export VV_PLATFORM_ID="archlinux"
export VV_ISARCH=1
break
elif [ "$i" == "debian" ]; then
export VV_ISDEBIAN=1
export VV_PLATFORM_ID="debian"
break
elif [[ "$i" == "redhat" || "$i" == "rhel" ]]; then
export VV_ISFEDORA=1
export VV_PLATFORM_ID="redhat"
break
elif [ "$i" == "ubuntu" ]; then
export VV_ISDEBIAN=1
export VV_PLATFORM_ID="ubuntu"
break
elif [[ "$i" == "opensuse" || "$i" == "sles" ]]; then
export VV_ISFEDORA=1
export VV_PLATFORM_ID="opensuse"
break
elif [ "$i" == "mageia" ]; then
export VV_ISFEDORA=1
export VV_PLATFORM_ID="mageia"
break
fi
done
fi
#figure out the numerical osname for all supported platforms
if [ "$VV_PLATFORM_ID" == "fedora" ]; then
if [ "$VV_PLATFORM_VERSION" == "37" ]; then export VV_OSNAME_ID="6"; fi
if [ "$VV_PLATFORM_VERSION" == "38" ]; then export VV_OSNAME_ID="7"; fi
elif [ "$VV_PLATFORM_ID" == "archlinux" ]; then
export VV_OSNAME_ID="0"
elif [ "$VV_PLATFORM_ID" == "debian" ]; then
if [ "$VV_PLATFORM_VERSION" == "10" ]; then export VV_OSNAME_ID="4"; fi
if [ "$VV_PLATFORM_VERSION" == "11" ]; then export VV_OSNAME_ID="5"; fi
if [ "$VV_PLATFORM_VERSION" == "12" ]; then export VV_OSNAME_ID="12"; fi
elif [[ "$VV_PLATFORM_ID" == "redhat" ]]; then
if [ "$VV_PLATFORM_VERSION" == "8" ]; then export VV_OSNAME_ID="8"; fi
if [ "$VV_PLATFORM_VERSION" == "9" ]; then export VV_OSNAME_ID="9"; fi
elif [ "$VV_PLATFORM_ID" == "ubuntu" ]; then
if [ "$VV_PLATFORM_VERSION" == "22" ]; then export VV_OSNAME_ID="1"; fi
if [ "$VV_PLATFORM_VERSION" == "20" ]; then export VV_OSNAME_ID="2"; fi
if [ "$VV_PLATFORM_VERSION" == "18" ]; then export VV_OSNAME_ID="3"; fi
elif [[ "$VV_PLATFORM_ID" == "opensuse" ]]; then
export VV_OSNAME_ID="10"
elif [ "$VV_PLATFORM_ID" == "mageia" ]; then
if [ "$VV_PLATFORM_VERSION" == "8" ]; then export VV_OSNAME_ID="11"; fi
fi
#
#At this point, the system should have been recognized, or the closest possible established based on ID_LIKE, since the
#order of space-separated entires in ID_LIKE is that of likeness (the first being the most like)
#
#the following three should not be changed manually, make tools set them
export VV_LIBRARY_PATH=/usr/lib64/vely
export VV_INCLUDE_PATH=/usr/include/vely
export VV_VERSION=100.100
#also obtain the libraries to link with for pcre2
#pcre2_version may not exist until sys is called to produce VV_LIBRARY_PATH, so must guard if it exists
#we use library path for vely, because this must work with our without source
if [ -f $VV_LIBRARY_PATH/pcre2_version ]; then
export VV_PCRE2_LIBS=$(cat $VV_LIBRARY_PATH/pcre2_libs)
if [ "$_VV_PCRE2_LO" == "10.37" ]; then
export VV_PCRE2_NEW="1"
else
export VV_PCRE2_NEW="0"
fi
fi
if [ "$VV_ISFEDORA" == "1" ]; then
if [ "$VV_PLATFORM_ID" == "opensuse" ]; then
export VV_PKG="zypper"
export VV_PKG_NONINTERACTIVE="-n"
elif [ "$VV_PLATFORM_ID" == "mageia" ]; then
export VV_PKG="dnf"
export VV_PKG_NONINTERACTIVE="-y"
else
export VV_PKG="dnf"
export VV_PKG_NONINTERACTIVE="-y"
fi
elif [ "$VV_ISDEBIAN" == "1" ]; then
export VV_PKG="apt"
export VV_PKG_NONINTERACTIVE="-y"
elif [ "$VV_ISARCH" == "1" ]; then
export VV_PKG="pacman"
export VV_PKG_NONINTERACTIVE="--noconfirm"
else
echo "Unknown Operating System [$VV_PLATFORM_ID]"
exit -4
fi
#do not execute again if already done
export VV_SYSTEM_DONE=1
fi
#
#
#
#From here on, only system requests are allowed, each exiting with 'exit'
#
#
#
if [ "$1" == "pgconf" ]; then
ECODE="0"
which pg_config 2>/dev/null 1>/dev/null || ECODE=$?
if [ "$ECODE" == "0" ]; then
echo "yes"
else
echo "no"
fi
exit 0
fi
if [ "$1" == "showid" ]; then
echo $VV_PLATFORM_ID
exit 0
fi
if [ "$1" == "showtype" ]; then
if [ "$VV_ISFEDORA" == "1" ]; then
echo "fedora"
elif [ "$VV_ISDEBIAN" == "1" ]; then
echo "debian"
elif [ "$VV_ISARCH" == "1" ]; then
echo "archlinux"
else
echo "unknown"
fi
exit 0
fi
#
#
#The following is a hack due to the bug in RH annobin (annotation for binaries)
#Set HASANNOBIN to nothing (default) to let Vely figure it out, or set it to
#override: 0 if annobin is enabled and 1 if annobin is disabled (right now we
#disable it). This only applies to fedora and such.
#
#
HASANNOBIN=
if [[ "$1" == "annobin" && "$HASANNOBIN" == "" ]]; then
HASANNOBIN="1"
if [ "$VV_ISFEDORA" == "1" ]; then
if [[ "$VV_PLATFORM_ID" == "redhat" || "$VV_PLATFORM_ID" == "centos" || "$VV_PLATFORM_ID" == "oracle_linux" ]]; then
LO=$(lowest_version $VV_PLATFORM_VERSION "7.999999")
#VV_PLATFORM_VERSION lt 8
if [ "$LO" == "$VV_PLATFORM_VERSION" ]; then
HASANNOBIN="0"
fi
fi
if [ "$VV_PLATFORM_ID" == "fedora" ]; then
#VV_PLATFORM_VERSION lt 27
LO=$(lowest_version $VV_PLATFORM_VERSION "26.999999")
if [ "$LO" == "$VV_PLATFORM_VERSION" ]; then
HASANNOBIN="0"
fi
fi
if [[ "$VV_PLATFORM_ID" == "opensuse" || "$VV_PLATFORM_ID" == "mageia" ]]; then
HASANNOBIN="0"
fi
else
HASANNOBIN="0"
fi
if [ "$HASANNOBIN" == "1" ]; then
echo "-Wc,-fplugin=annobin -Wc,-fplugin-arg-annobin-disable"
fi
exit 0
fi