-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcix_upgrade
executable file
·259 lines (225 loc) · 7.25 KB
/
cix_upgrade
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
259
#!/usr/local/bin/cbsd
#v13.1.0
MYARG="mode"
MYOPTARG="dryrun"
MYDESC="Upgrade MyB/ClonOS via pkg"
ADDHELP="
dryrun - (1 - default ) chech for updates only;
mode=list - list current packages;
mode=listjson - list current/available packages in JSON;
mode=check_upgrade - dryrun/show available updates;
mode=upgrade - upgrade;
"
. ${subr}
dryrun=1
. ${cbsdinit}
. ${system}
[ ! -r /root/bin/upgrade.sh ] && err 1 "${W1_COLOR}${CBSD_APP}: ${N1_COLOR}no such script: ${N2_COLOR}/root/bin/upgrade.sh${N0_COLOR}"
upgrade_packages()
{
case "${dryrun}" in
1)
/root/bin/upgrade.sh -c 1 -w 1
;;
0)
# not for DEV server:
myhost=$( ${HOSTNAME_CMD} | ${AWK_CMD} '{printf $1}' )
if [ "${mod_cbsd_queue_enabled}" = "YES" -a -z "${MOD_CBSD_QUEUE_DISABLED}" ]; then
readconf cbsd_queue.conf
if [ -z "${cbsd_queue_backend}" ]; then
MOD_CBSD_QUEUE_DISABLED="1"
else
[ -n "${cbsd_jail_queue_name}" ] && ${cbsd_queue_backend} cbsd_queue_name=${cbsd_settings_queue_name} id=update cmd=update status=1 workdir="${workdir}" jname="0" data_msg="starting..."
fi
fi
if [ -z "${myhost}" -o "${myhost}" = "home.olevole.ru" ]; then
echo "Dev server"
echo "Upgrade in progress..."
for i in $( seq 1 5 ); do
echo "Phase ${i}..."
if [ "${mod_cbsd_queue_enabled}" = "YES" -a -z "${MOD_CBSD_QUEUE_DISABLED}" ]; then
if [ -z "${cbsd_queue_backend}" ]; then
MOD_CBSD_QUEUE_DISABLED="1"
else
p=$(( 15 * i ))
[ -n "${cbsd_jail_queue_name}" ] && ${cbsd_queue_backend} cbsd_queue_name=${cbsd_settings_queue_name} id=update cmd=update status=${p} workdir="${workdir}" jname="0" data_msg="update phase ${i}/5.."
fi
fi
sleep 1
done
else
/root/bin/upgrade.sh -c 0 -w 1
fi
if [ "${mod_cbsd_queue_enabled}" = "YES" -a -z "${MOD_CBSD_QUEUE_DISABLED}" ]; then
if [ -z "${cbsd_queue_backend}" ]; then
MOD_CBSD_QUEUE_DISABLED="1"
else
[ -n "${cbsd_jail_queue_name}" ] && ${cbsd_queue_backend} cbsd_queue_name=${cbsd_settings_queue_name} id=update cmd=update status=100 workdir="${workdir}" jname="0" data_msg="complete"
fi
fi
;;
*)
err 1 "${W1_COLOR}${CBSD_APP}: ${N1_COLOR}unknown dryrun: ${N2_COLOR}${dryrun}${N0_COLOR}"
;;
esac
}
## SYNC WITH CPR/Build
list_packages()
{
local STD_OUT="/dev/stdout"
local STD_OUT_JSON="/dev/stdout"
[ -z "${json}" ] && json="1"
[ -z "${save_repo}" ] && save_repo="1"
local OPATH="${PATH}"
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
[ -z "${PKG_CMD}" ] && PKG_CMD=$( which pkg || which pkg-static )
[ -z "${PKG_CMD}" ] && PKG_CMD=$( which pkg )
[ -z "${CUT_CMD}" ] && CUT_CMD=$( which cut )
[ -z "${AWK_CMD}" ] && AWK_CMD=$( which awk )
[ -z "${GREP_CMD}" ] && GREP_CMD=$( which grep )
[ -z "${SED_CMD}" ] && SED_CMD=$( which sed )
[ -z "${TRUNCATE_CMD}" ] && TRUNCATE_CMD=$( which truncate )
[ -z "${CAT_CMD}" ] && CAT_CMD=$( which cat )
PATH="${OPATH}"
if [ ${save_repo} -eq 1 ]; then
STD_OUT="/tmp/cix_upgrade.conf"
STD_OUT_JSON="/tmp/cix_upgrade.conf.json"
${TRUNCATE_CMD} -s0 ${STD_OUT} ${STD_OUT_JSON}
fi
cbsd_ver=$( /usr/local/bin/cbsd version 2>/dev/null | ${AWK_CMD} '{printf $1}' )
if [ -z "${cbsd_ver}" ]; then
cbsd_ver=$( ${PKG_CMD} info cbsd 2>/dev/null | ${GREP_CMD} ^Version | ${CUT_CMD} -d : -f 2 | ${AWK_CMD} '{printf $1}' )
fi
php_ver=$( ${PKG_CMD} info php[0-9][0-9]-[0-9]* 2>/dev/null )
myb_ver=$( ${PKG_CMD} info myb 2>/dev/null | ${GREP_CMD} ^Version | ${CUT_CMD} -d : -f 2 | ${AWK_CMD} '{printf $1}' )
clonos_ver=$( ${PKG_CMD} info clonos 2>/dev/null | ${GREP_CMD} ^Version | ${CUT_CMD} -d : -f 2 | ${AWK_CMD} '{printf $1}' )
cbsd_api_ver=$( ${PKG_CMD} info cbsd-mq-api 2>/dev/null | ${GREP_CMD} ^Version | ${CUT_CMD} -d : -f 2 | ${AWK_CMD} '{printf $1}' )
cbsd_router_ver=$( ${PKG_CMD} info cbsd-mq-router 2>/dev/null | ${GREP_CMD} ^Version | ${CUT_CMD} -d : -f 2 | ${AWK_CMD} '{printf $1}' )
freebsd_runtime_ver=$( ${PKG_CMD} info FreeBSD-runtime 2>/dev/null | ${GREP_CMD} ^Version | ${CUT_CMD} -d : -f 2 | ${AWK_CMD} '{printf $1}' )
installed_component=
for i in cbsd_api_ver cbsd_router_ver cbsd_ver clonos_ver myb_ver php_ver freebsd_runtime_ver; do
_val=
eval _val="\$$i"
[ -z "${_val}" ] && continue
component=$( echo ${i} | ${SED_CMD} 's:_ver::g' )
if [ ${save_repo} -eq 1 ]; then
printf "${component}_ver_new=\"${_val}\"\n" >>${STD_OUT}
else
if [ ${json} -eq 0 ]; then
printf "${component}: ${_val}\n" >>${STD_OUT}
continue
fi
fi
if [ -z "${installed_component}" ]; then
installed_component="${i}"
else
installed_component="${installed_component} ${i}"
fi
installed_component_num=$(( installed_component_num + 1 ))
done
[ ${json} -eq 0 ] && return 0
${CAT_CMD} >>${STD_OUT_JSON} <<EOF
{
"installed": {
EOF
current_component=0
for i in ${installed_component}; do
current_component=$(( current_component + 1 ))
_val=
eval _val="\$$i"
[ -z "${_val}" ] && continue
component=$( echo ${i} | ${SED_CMD} 's:_ver::g' )
if [ ${current_component} -eq ${installed_component_num} ]; then
printf " \"${component}\": \"${_val}\"\n" >>${STD_OUT_JSON}
else
printf " \"${component}\": \"${_val}\",\n" >>${STD_OUT_JSON}
fi
done
if [ ${save_repo} -eq 1 ]; then
echo " }" >>${STD_OUT_JSON}
echo "}" >>${STD_OUT_JSON}
return 0
fi
[ -r ${cache_file} ] && . ${cache_file}
${CAT_CMD} <<EOF
},
"latest": {
EOF
latest_component_num=0
current_component_num=0
for i in ${installed_component}; do
current_component=$(( current_component + 1 ))
_val=
eval _val="\$$i"
[ -z "${_val}" ] && continue
i_new="${i}_new"
eval _val_new="\$$i_new"
[ -z "${_val_new}" ] && continue
if [ "${_val_new}" != "${_val}" ]; then
latest_component_num=$(( latest_component_num + 1 ))
eval latest_param${latest_component_num}="\"${i}\""
eval latest_val${latest_component_num}="${_val_new}"
fi
done
while [ ${current_component_num} -ne ${latest_component_num} ]; do
current_component_num=$(( current_component_num + 1 ))
eval _par="\$latest_param${current_component_num}"
eval _val="\$latest_val${current_component_num}"
component=$( echo ${_par} | ${SED_CMD} 's:_ver::g' )
if [ ${current_component_num} -eq ${latest_component_num} ]; then
printf " \"${component}\": \"${_val}\"\n" >>${STD_OUT_JSON}
else
printf " \"${component}\": \"${_val}\",\n" >>${STD_OUT_JSON}
fi
done
${CAT_CMD} <<EOF
}
}
EOF
}
#### MAIN
# Keep in sync with CPR!
json=0
save_repo=0
cache_file="/tmp/cix_upgrade_latest.conf"
case "${mode}" in
list)
list_packages
;;
listjson|listjson2)
cache_file="/tmp/cix_upgrade_latest.conf"
json=1
list_packages
;;
upgrade)
dryrun=0
upgrade_packages
;;
# check_upgrade)
# dryrun=1
# upgrade_packages
# ;;
check_upgrade)
URL="https://clonos-pkg.convectix.com/FreeBSD:14:amd64/latest/clonos_ver.conf"
_res=$( timeout 10 ${FETCH_CMD} -o ${cache_file} ${URL} 2>&1 )
ret=$?
if [ ${ret} -eq 0 ]; then
cache_file="/tmp/cix_upgrade_latest.conf"
json=1
list_packages
chmod 0777 ${cache_file}
else
${RM_CMD} -f ${cache_file}
err 1 "check_uprade fetch error: ${_res}"
fi
;;
repo)
json=1
save_repo=1
list_packages
;;
*)
err 1 "${W1_COLOR}${CBSD_APP}: ${N1_COLOR}unknown mode: ${N2_COLOR}${mode}${N0_COLOR}"
;;
esac
exit 0