forked from picons/picons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-build-picons.sh
executable file
·273 lines (237 loc) · 10.4 KB
/
2-build-picons.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
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/bin/bash
#####################
## Setup locations ##
#####################
location=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
temp=$(mktemp -d --suffix=.picons)
logfile=$(mktemp --suffix=.picons.log)
echo "$(date +'%H:%M:%S') - INFO: Log file located at: $logfile"
###########################
## Check path for spaces ##
###########################
if [[ $location == *" "* ]]; then
echo "$(date +'%H:%M:%S') - ERROR: The path contains spaces, please move the repository to a path without spaces!"
exit 1
fi
########################################################
## Search for required commands and exit if not found ##
########################################################
commands=( tar sed grep tr cat sort find mkdir rm cp mv ln readlink )
for i in ${commands[@]}; do
if ! which $i &> /dev/null; then
missingcommands="$i $missingcommands"
fi
done
if [[ -z $missingcommands ]]; then
echo "$(date +'%H:%M:%S') - INFO: All required commands are found!"
else
echo "$(date +'%H:%M:%S') - ERROR: The following commands are not found: $missingcommands"
exit 1
fi
if which ar &> /dev/null; then
skipipk="false"
echo "$(date +'%H:%M:%S') - INFO: Creation of ipk files enabled!"
else
skipipk="true"
echo "$(date +'%H:%M:%S') - WARNING: Creation of ipk files disabled! Try installing: ar (found in package: binutils)"
fi
if which xz &> /dev/null; then
compressor="xz -9 --extreme --memlimit=40%" ; ext="xz"
echo "$(date +'%H:%M:%S') - INFO: Using xz as compression!"
elif which bzip2 &> /dev/null; then
compressor="bzip2 -9" ; ext="bz2"
echo "$(date +'%H:%M:%S') - INFO: Using bzip2 as compression!"
else
echo "$(date +'%H:%M:%S') - ERROR: No archiver has been found! Try installing: xz (or: bzip2)"
exit 1
fi
if which pngquant &> /dev/null; then
pngquant="pngquant"
echo "$(date +'%H:%M:%S') - INFO: Image compression enabled!"
else
pngquant="cat"
echo "$(date +'%H:%M:%S') - WARNING: Image compression disabled! Try installing: pngquant"
fi
if which convert &> /dev/null; then
echo "$(date +'%H:%M:%S') - INFO: ImageMagick was found!"
else
echo "$(date +'%H:%M:%S') - ERROR: ImageMagick was not found! Try installing: imagemagick"
exit 1
fi
if [[ -f $location/build-input/svgconverter.conf ]]; then
svgconverterconf=$location/build-input/svgconverter.conf
else
echo "$(date +'%H:%M:%S') - WARNING: No \"svgconverter.conf\" file found in \"build-input\", using default file!"
svgconverterconf=$location/build-source/config/svgconverter.conf
fi
if which inkscape &> /dev/null && [[ $(grep -v -e '^#' -e '^$' $svgconverterconf) = "inkscape" ]]; then
svgconverter="inkscape -w 850 --without-gui --export-area-drawing --export-png="
echo "$(date +'%H:%M:%S') - INFO: Using inkscape as svg converter!"
elif which rsvg-convert &> /dev/null && [[ $(grep -v -e '^#' -e '^$' $svgconverterconf) = "rsvg" ]]; then
svgconverter="rsvg-convert -w 1000 --keep-aspect-ratio --output "
echo "$(date +'%H:%M:%S') - INFO: Using rsvg as svg converter!"
else
echo "$(date +'%H:%M:%S') - ERROR: SVG converter: $(grep -v -e '^#' -e '^$' $svgconverterconf), was not found!"
exit 1
fi
##############################################
## Ask the user whether to build SNP or SRP ##
##############################################
if [[ -z $1 ]]; then
echo "Which style are you going to build?"
select choice in "Service Reference" "Service Reference (Full)" "Service Name" "Service Name (Full)"; do
case $choice in
"Service Reference" ) style=srp; break;;
"Service Reference (Full)" ) style=srp-full; break;;
"Service Name" ) style=snp; break;;
"Service Name (Full)" ) style=snp-full; break;;
esac
done
else
style=$1
fi
#############################################
## Check if previously chosen style exists ##
#############################################
if [[ ! $style = "srp-full" ]] && [[ ! $style = "snp-full" ]]; then
for file in $location/build-output/servicelist-*-$style.txt ; do
if [[ ! -f $file ]]; then
echo "$(date +'%H:%M:%S') - ERROR: No $style servicelist has been found!"
exit 1
fi
done
fi
###########################################
## Cleanup binaries folder and re-create ##
###########################################
binaries=$location/build-output/binaries-$style
if [[ -d $binaries ]]; then rm -rf $binaries; fi
mkdir $binaries
##############################
## Determine version number ##
##############################
if [[ -d $location/.git ]] && which git &> /dev/null; then
cd $location
hash=$(git rev-parse --short HEAD)
version=$(date --utc --date=@$(git show -s --format=%ct $hash) +'%Y-%m-%d--%H-%M-%S')
timestamp=$(date --utc --date=@$(git show -s --format=%ct $hash) +'%Y%m%d%H%M.%S')
else
epoch="date --utc +%s"
version=$(date --utc --date=@$($epoch) +'%Y-%m-%d--%H-%M-%S')
timestamp=$(date --utc --date=@$($epoch) +'%Y%m%d%H%M.%S')
fi
echo "$(date +'%H:%M:%S') - INFO: Version: $version"
#############################################
## Some basic checking of the source files ##
#############################################
if [[ $- == *i* ]]; then
echo "$(date +'%H:%M:%S') - EXECUTING: Checking index"
$location/resources/tools/check-index.sh $location/build-source srp
$location/resources/tools/check-index.sh $location/build-source snp
echo "$(date +'%H:%M:%S') - EXECUTING: Checking logos"
$location/resources/tools/check-logos.sh $location/build-source/logos
fi
#####################
## Create symlinks ##
#####################
echo "$(date +'%H:%M:%S') - EXECUTING: Creating symlinks"
$location/resources/tools/create-symlinks.sh $location $temp $style
####################################################################
## Start the actual conversion to picons and creation of packages ##
####################################################################
logocollection=$(grep -v -e '^#' -e '^$' $temp/create-symlinks.sh | sed -e 's/^.*logos\///g' -e 's/.png.*$//g' | sort -u )
logocount=$(echo "$logocollection" | wc -l)
mkdir -p $temp/cache
if [[ -f $location/build-input/backgrounds.conf ]]; then
backgroundsconf=$location/build-input/backgrounds.conf
else
echo "$(date +'%H:%M:%S') - WARNING: No \"backgrounds.conf\" file found in \"build-input\", using default file!"
backgroundsconf=$location/build-source/config/backgrounds.conf
fi
grep -v -e '^#' -e '^$' $backgroundsconf | while read lines ; do
currentlogo=""
OLDIFS=$IFS
IFS=";"
line=($lines)
IFS=$OLDIFS
resolution=${line[0]}
resize=${line[1]}
type=${line[2]}
background=${line[3]}
tag=$2
packagenamenoversion=$style$tag.$resolution-$resize.$type.on.$background
packagename=$style$tag.$resolution-$resize.$type.on.${background}_${version}
mkdir -p $temp/package/picon/logos
echo "$(date +'%H:%M:%S') - EXECUTING: Creating picons: $packagenamenoversion"
echo "$logocollection" | while read logoname ; do
((currentlogo++))
if [[ $- == *i* ]]; then
echo -ne " Converting logo: $currentlogo/$logocount"\\r
fi
# Determine the logo type with fallbacks
if [[ $type == "white" ]]; then
if [[ -f $location/build-source/logos/$logoname.white.png ]] || [[ -f $location/build-source/logos/$logoname.white.svg ]]; then
logotype=white
elif [[ -f $location/build-source/logos/$logoname.light.png ]] || [[ -f $location/build-source/logos/$logoname.light.svg ]]; then
logotype=light
else
logotype=default
fi
elif [[ $type == "light" ]]; then
if [[ -f $location/build-source/logos/$logoname.light.png ]] || [[ -f $location/build-source/logos/$logoname.light.svg ]]; then
logotype=light
else
logotype=default
fi
elif [[ $type == "dark" ]]; then
if [[ -f $location/build-source/logos/$logoname.light.png ]] || [[ -f $location/build-source/logos/$logoname.light.svg ]]; then
logotype=dark
else
logotype=default
fi
else
logotype=default
fi
echo $logoname.$logotype >> $logfile
if [[ -f $location/build-source/logos/$logoname.$logotype.svg ]]; then
logo=$temp/cache/$logoname.$logotype.png
if [[ ! -f $logo ]]; then
$svgconverter$logo $location/build-source/logos/$logoname.$logotype.svg 2>> $logfile >> $logfile
fi
else
logo=$location/build-source/logos/$logoname.$logotype.png
fi
convert $location/build-source/backgrounds/$resolution/$background.png \( $logo -background none -bordercolor none -border 100 -trim -border 1% -resize $resize -gravity center -extent $resolution +repage \) -layers merge - 2>> $logfile | $pngquant - 2>> $logfile > $temp/package/picon/logos/$logoname.png
done
echo "$(date +'%H:%M:%S') - EXECUTING: Creating binary packages: $packagenamenoversion"
$temp/create-symlinks.sh
find $temp/package -exec touch --no-dereference -t $timestamp {} \;
if [[ $skipipk = "false" ]]; then
mkdir $temp/package/CONTROL ; cat > $temp/package/CONTROL/control <<-EOF
Package: enigma2-plugin-picons-$packagenamenoversion
Version: $version
Section: base
Architecture: all
Maintainer: https://github.com/picons
Source: https://github.com/picons
Description: $packagenamenoversion
OE: enigma2-plugin-picons-$packagenamenoversion
HomePage: https://github.com/picons
License: unknown
Priority: optional
EOF
touch --no-dereference -t $timestamp $temp/package/CONTROL/control
$location/resources/tools/ipkg-build.sh -o root -g root $temp/package $binaries >> $logfile
fi
mv $temp/package/picon $temp/package/$packagename
tar --dereference --owner=root --group=root -cf - --exclude=logos --directory=$temp/package $packagename | $compressor 2>> $logfile > $binaries/$packagename.hardlink.tar.$ext
tar --owner=root --group=root -cf - --directory=$temp/package $packagename | $compressor 2>> $logfile > $binaries/$packagename.symlink.tar.$ext
find $binaries -exec touch -t $timestamp {} \;
rm -rf $temp/package
done
######################################
## Cleanup temporary files and exit ##
######################################
if [[ -d $temp ]]; then rm -rf $temp; fi
echo "$(date +'%H:%M:%S') - INFO: Finished building $style!"
exit 0