-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
compile-addons.sh
executable file
·181 lines (172 loc) · 6.14 KB
/
compile-addons.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
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
#!/usr/bin/env bash
set -e
TMP_PATH="/tmp"
YQ_BIN="`dirname $0`/yq"
TOOLKIT_VER="7.2"
###############################################################################
#
# 1 - Path of key
function hasConfigKey() {
[ "`${YQ_BIN} eval '.'${1}' | has("'${2}'")' "${3}"`" == "true" ] && return 0 || return 1
}
###############################################################################
# Read key value from yaml config file
# 1 - Path of key
# 2 - Path of yaml config file
# Return Value
function readConfigKey() {
RESULT=`${YQ_BIN} eval '.'${1}' | explode(.)' "${2}"`
[ "${RESULT}" == "null" ] && echo "" || echo ${RESULT}
}
###############################################################################
# Read Entries as array from yaml config file
# 1 - Path of key
# 2 - Path of yaml config file
# Returns array of values
function readConfigEntriesArray() {
${YQ_BIN} eval '.'${1}' | explode(.) | to_entries | map([.key])[] | .[]' "${2}"
}
###############################################################################
function compile-addon() {
# Read manifest file
MANIFEST="${1}/manifest.yml"
if [ ! -f "${MANIFEST}" ]; then
echo -e "\033[1;44mWarning: ${MANIFEST} not found, ignoring it\033[0m"
return 0
fi
echo -e "\033[7mProcessing manifest ${MANIFEST}\033[0m"
OUT_PATH="${TMP_PATH}/${1}"
rm -rf "${OUT_PATH}"
mkdir -p "${OUT_PATH}"
VER=`readConfigKey "version" "${MANIFEST}"`
# Check manifest version
if [ ${VER} -ne 1 ]; then
echo -e "\033[1;44mWarning: version ${VER} of manifest not suported, ignoring it\033[0m"
return 0
fi
# Check if has compile script
COMPILESCRIPT=`readConfigKey "compile-script" "${MANIFEST}"`
if [ -n "${COMPILESCRIPT}" ]; then
echo "Running compile script"
pushd . >/dev/null
cd "${1}"
./${COMPILESCRIPT}
popd >/dev/null
fi
# Copy manifest to destiny
cp "${MANIFEST}" "${OUT_PATH}"
# Check if exist files for all platforms
if hasConfigKey "" "all" "${MANIFEST}"; then
echo -e "\033[1;32m Processing 'all' section\033[0m"
HAS_FILES=0
# Get name of script to install, if defined. This script has low priority
INSTALL_SCRIPT="`readConfigKey "all.install-script" "${MANIFEST}"`"
if [ -n "${INSTALL_SCRIPT}" ]; then
if [ -f "${1}/${INSTALL_SCRIPT}" ]; then
echo -e "\033[1;35m Copying install script ${INSTALL_SCRIPT}\033[0m"
mkdir -p "${OUT_PATH}/all"
cp "${1}/${INSTALL_SCRIPT}" "${OUT_PATH}/all/install.sh"
HAS_FILES=1
else
echo -e "\033[1;33m WARNING: install script '${INSTALL_SCRIPT}' not found\033[0m"
fi
fi
# Get folder name for copy
COPY_PATH="`readConfigKey "all.copy" "${MANIFEST}"`"
# If folder exists, copy
if [ -n "${COPY_PATH}" ]; then
if [ -d "${1}/${COPY_PATH}" ]; then
echo -e "\033[1;35m Copying folder '${COPY_PATH}'\033[0m"
mkdir -p "${OUT_PATH}/all/root"
cp -R "${1}/${COPY_PATH}/"* "${OUT_PATH}/all/root"
HAS_FILES=1
else
echo -e "\033[1;33m WARNING: folder '${COPY_PATH}' not found\033[0m"
fi
fi
if [ ${HAS_FILES} -eq 1 ]; then
# Create tar gziped
tar caf "${OUT_PATH}/all.tgz" -C "${OUT_PATH}/all" .
echo -e "\033[1;36m Created file '${OUT_PATH}/all.tgz' \033[0m"
fi
# Clean
rm -rf "${OUT_PATH}/all"
fi
# Now check files for individual models
unset AVAL_FOR
declare -a AVAL_FOR
for P in `readConfigEntriesArray "available-for" "${MANIFEST}"`; do
AVAL_FOR+=(${P})
done
# Loop in each available platform-kver
for P in ${AVAL_FOR[@]}; do
echo -e "\033[1;32m Processing '${P}' platform-kver section\033[0m"
HAS_FILES=0
# Get name of script to install, if defined. This script has high priority
INSTALL_SCRIPT="`readConfigKey 'available-for."'${P}'".install-script' "${MANIFEST}"`"
if [ -n "${INSTALL_SCRIPT}" ]; then
if [ -f "${1}/${INSTALL_SCRIPT}" ]; then
echo -e "\033[1;35m Copying install script ${INSTALL_SCRIPT}\033[0m"
mkdir -p "${OUT_PATH}/${P}"
cp "${1}/${INSTALL_SCRIPT}" "${OUT_PATH}/${P}/install.sh"
HAS_FILES=1
else
echo -e "\033[1;33m WARNING: install script '${INSTALL_SCRIPT}' not found\033[0m"
fi
fi
# Get folder name for copy
COPY_PATH="`readConfigKey 'available-for."'${P}'".copy' "${MANIFEST}"`"
# If folder exists, copy
if [ -n "${COPY_PATH}" ]; then
if [ -d "${1}/${COPY_PATH}" ]; then
echo -e "\033[1;35m Copying folder '${COPY_PATH}'\033[0m"
mkdir -p "${OUT_PATH}/${P}/root"
cp -R "${1}/${COPY_PATH}/"* "${OUT_PATH}/${P}/root"
HAS_FILES=1
else
echo -e "\033[1;33m WARNING: folder '${1}/${COPY_PATH}' not found\033[0m"
fi
fi
HAS_MODULES="`readConfigKey 'available-for."'${P}'".modules' "${MANIFEST}"`"
# Check if has modules for compile
if [ "${HAS_MODULES}" = "true" ]; then
echo "Compiling modules"
PLATFORM="`echo ${P} | cut -d'-' -f1`"
KVER="`echo ${P} | cut -d'-' -f2`"
# Compile using docker
rm -rf "${TMP_PATH}/${1}-mods"
mkdir -p "${TMP_PATH}/${1}-mods"
# docker run --rm -t -v "${TMP_PATH}/${1}-mods":/output \
# -v "${PWD}/${1}/src/${KVER}":/input fbelavenuto/syno-toolkit:${PLATFORM}-${TOOLKIT_VER} compile-module
docker run --rm -t --user `id -u` -v "${TMP_PATH}/${1}-mods":/output \
-v "${PWD}/${1}/src/${KVER}":/input fbelavenuto/syno-compiler:${TOOLKIT_VER} compile-module ${PLATFORM}
mkdir -p "${OUT_PATH}/${P}/root/modules"
mv "${TMP_PATH}/${1}-mods/"*.ko "${OUT_PATH}/${P}/root/modules/"
rm -rf "${TMP_PATH}/${1}-mods"
HAS_FILES=1
fi
if [ ${HAS_FILES} -eq 1 ]; then
# Create tar gziped
tar caf "${OUT_PATH}/${P}.tgz" -C "${OUT_PATH}/${P}" .
echo -e "\033[1;36m Created file '${P}.tgz' \033[0m"
fi
# Clean
rm -rf "${OUT_PATH}/${P}"
done
# Create addon package
tar caf "${1}.addon" -C "${OUT_PATH}" .
rm -rf "${OUT_PATH}"
}
# Main
if [ $# -ge 1 ]; then
for A in $@; do
compile-addon ${A%/}
done
else
while read D; do
DRIVER=`basename ${D}`
[ "${DRIVER:0:1}" = "." ] && continue
compile-addon ${DRIVER}
done < <(find -maxdepth 1 -type d)
fi
wait