forked from reidemei/synology-autorun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
157 lines (144 loc) · 5.65 KB
/
build
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
#!/bin/bash
# generate the *.spk file (without the help of the toolkit)
# non-UTF-8 files with international characters and Windows-CR-LF may cause problems. Detect such files ...
# recursive calls for sub directories
checkCoding() {
for f in "${1}"*; do
if [[ -d "$f" ]]; then
checkCoding "${f}/"
else
res=$(file -b "$f")
ret=$?
# echo " File coding check '$f' result $ret: $res"
if [[ $res == *"CRLF line terminators"* ]]; then
echo " File coding check '$f' result $ret: $res"
echo " ######## Windows line terminator need to be converted to Unix! #########"
((errCnt=errCnt+1))
elif [[ "$res" == *"ISO-8859 text"* ]]; then
echo " File coding check '$f' result $ret: $res"
echo " ######## Please convert to UTF-8! ##########"
((errCnt=errCnt+1))
elif [[ "$res" == *"PNG image"* ]]; then
echo " File coding check PNG image '$f' result $ret: $res"
# are there some PNG formats which need to be converted?
fi
fi
done
}
######################### start ###########################
SCRIPTPATHbuild="$( cd -- "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 ; /bin/pwd -P )"
PKG_DIR="$SCRIPTPATHbuild"
cd "$PKG_DIR"
echo "'${BASH_SOURCE[0]}' started ..."
# non-UTF-8 files with international characters and Windows-CR-LF may cause problems.
# Detect such files by checking all source files ...
echo "File coding check ..."
# checkCoding needs the 'file' command, which is e.g. in "SynoCli File Tools":
res=$(which "file")
if [[ -n "$res" ]]; then
checkCoding "$SCRIPTPATHbuild/"
else
echo "=================================================================================================================="
echo "Linux command 'file' is not available. Checking source files for correct line terminator and UTF-8-coding skipped!"
echo "The 'file' command is part of the package 'SynoCli File Tools'! You may install that from https://packages.synocommunity.com/"
echo "=================================================================================================================="
fi
echo "... finished file coding check"
ret=0
# "$(./translate.sh)" # Update tranlations via DeepL if necessary
# /bin/bash ./translate.sh
# ret=$?
if [[ "$ret" -gt 0 ]]; then
exit $ret
fi
if [[ -f "INFO.sh" ]]; then
infoFile="INFO.sh"
elif [[ -f "INFO" ]]; then
infoFile="INFO"
else
echo "=================================================================================================================="
echo "Error: Neither the file INFO.sh nor INFO foun in folder '$PKG_DIR'"
echo "=================================================================================================================="
exit 2
fi
### get the version and the package name from INFO.sh or INFO:
line=$(grep -i "VERSION=" "$infoFile")
echo "line with version: '$line'"
line="${line^^}" # toUpper
eval "$line"
line="$(grep -i "package=" "$infoFile")"
line="${line#*package=\"}"
pck="${line%%\"*}"
# pck=$(grep -i "package=" "$infoFile" | /bin/sed -e 's/package=//i' -e 's/"//g')
echo "pck='$pck'"
dsmuidir=""
line="$(grep "dsmuidir=" "$infoFile")" # most often dsmuidir="ui"
eval "$line"
echo "dsmuidir='$dsmuidir'"
# Check for well formed JSON:
errCnt=0
for f1 in "package/$dsmuidir/config" "package/$dsmuidir/index.conf" "package/$dsmuidir/helptoc.conf" conf/* WIZARD_UIFILES/*.json WIZARD_UIFILES/uninstall_uifile_*
# for f1 in package/$dsmuidir/config package/$dsmuidir/index.conf conf/* WIZARD_UIFILES/uninstall_uifile* WIZARD_UIFILES/wizard_*.json
do
f2="$SCRIPTPATHbuild/$1$f1"
if [[ -f "$f2" ]]; then
# res=$(cat "$f2" | python3 -mjson.tool)
res=$(python3 -mjson.tool < "$f2")
ret=$?
echo "JSON syntax check '$f2': $ret"
if [[ "$ret" != 0 ]]; then
echo "#### !!!!!! JSON syntax error in '$f2'!!!!! #####"
((errCnt=errCnt+1))
fi
else
echo "$f2 not found!"
((errCnt=errCnt+1))
fi
done
if [[ "$errCnt" -gt "0" ]]; then
echo "Stopped due to errCnt=$errCnt"
exit 2
fi
# shellcheck disable=2153
echo "building V$VERSION of $pck ..."
# echo "Actual working directory is $PKG_DIR"
rm -f "package.tgz"
rm -f "${pck}-$VERSION.spk"
chmod -R 777 package
echo "building package.tgz ..."
# tar --exclude="*/@eaDir" --owner=0 --group=0 -czvvf package.tgz -C package/ auto.sh bin "$dsmuidir" common log_hlp.sh rules udev
tar --exclude="*/@eaDir" --owner=0 --group=0 -czvvf package.tgz -C package/ auto.sh bin "$dsmuidir" common rules udev
path="package/$dsmuidir/images"
cp -av "$path/icon_64.png" "PACKAGE_ICON.PNG"
p256=""
if [[ -f "$path/icon_256.png" ]]; then
p256="PACKAGE_ICON_256.PNG"
cp -av "$path/icon_256.png" "PACKAGE_ICON_256.PNG"
# during package installation the icons will be inserted to the INFO file
fi
chmod 755 INFO.sh
if [[ -f INFO.sh ]]; then
rm -f "INFO"
echo "Executing now INFO.sh to build INFO file ..."
source INFO.sh NoToolkitScripts
chmod 755 INFO
echo "create_time=\"$(date '+%Y-%m-%d %T')\"" >> INFO
echo "... INFO.sh done."
fi
echo "... package.tgz done"
echo "building ${pck}-$VERSION.spk ..."
chmod 700 package.tgz
# --exclude="Thumbs.db" --exclude="Browse.plb"
license=""
if [[ -f "LICENSE*" ]]; then
license="LICENSE*"
fi
# tar --exclude="*/@eaDir" --owner=0 --group=0 -cvvf "${pck}-$VERSION.spk" INFO CHANGELOG $license PACKAGE_ICON.PNG "$p256" WIZARD_UIFILES conf scripts package.tgz
# shellcheck disable=2086
tar --exclude="*/@eaDir" --owner=0 --group=0 -cvvf "${pck}-$VERSION.spk" INFO $license PACKAGE_ICON.PNG "$p256" WIZARD_UIFILES conf scripts package.tgz
rm "package.tgz"
rm "INFO"
rm "PACKAGE_ICON.PNG"
rm "PACKAGE_ICON_256.PNG"
# chmod 777 ${pck}-$VERSION.spk
echo "... ${BASH_SOURCE[0]} done, file $SCRIPTPATHbuild/${pck}-$VERSION.spk generated!"