-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync_env2form
executable file
·46 lines (38 loc) · 1.31 KB
/
sync_env2form
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
#!/usr/local/bin/cbsd
#v11.0.15
MYARG=""
MYOPTARG="module"
MYDESC="Synchronize/populate 'cur' value in forms from forms_env.conf"
ADDHELP="module= specify module name. Default - scan formfile dir and apply to all\n"
. ${subr}
. ${system}
. ${tools}
. ${strings}
. ${cbsdinit}
tmp=$( ${MKTEMP_CMD} )
trap "${RM_CMD} -f ${tmp}" HUP INT ABRT BUS TERM EXIT
if [ -r ${etcdir}/forms_env.conf ]; then
merge from=${etcdir}/defaults/forms_env.conf to=${etcdir}/forms_env.conf out=${tmp}
else
${GREP_CMD} ^H ${etcdir}/defaults/forms_env.conf > ${tmp}
fi
${GREP_CMD} ^H ${tmp} | while read _line; do
myline=$( echo ${_line} | ${SED_CMD} s:^H_::g )
strpos --str="${myline}" --search="="
pos=$?
[ ${pos} -eq 0 ] && continue
pos1=${pos}
pos2=$(( pos + 2 ))
prefix=
prefix=$( substr --pos=0 --len=${pos1} --str="${myline}" )
tmp_val=$( substr --pos=${pos2} --len=0 --str="${myline}" )
value=$( echo ${tmp_val} | ${SED_CMD} s:\"::g )
[ -z "${module}" ] && module=$( ${FIND_CMD} ${workdir}/formfile/ -name *.sqlite -type f -depth 1 -maxdepth 1 -exec ${REALPATH_CMD} {} \; )
for modfile in ${module}; do
param=$( cbsdsql ${modfile} SELECT param FROM forms WHERE param=\"${prefix}\" 2>/dev/null )
if [ -n "${param}" ]; then
cbsdsql ${modfile} "UPDATE forms SET cur=\"${value}\" WHERE param=\"${prefix}\""
fi
done
done
exit 0