-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy path2-build-picons.sh
More file actions
executable file
·259 lines (218 loc) · 9.79 KB
/
2-build-picons.sh
File metadata and controls
executable file
·259 lines (218 loc) · 9.79 KB
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
#!/bin/bash
########################################################
## Search for required commands and exit if not found ##
########################################################
commands=( convert pngquant rsvg-convert ar tar xz sed grep tr column cat sort find echo mkdir chmod rm cp mv ln pwd basename mktemp )
for i in "${commands[@]}"; do
if ! which $i &> /dev/null; then
missingcommands="$i $missingcommands"
fi
done
if [[ ! -z $missingcommands ]]; then
echo "The following commands are not found: $missingcommands"
echo ""
echo "Try installing the following packages:"
echo "imagemagick pngquant binutils librsvg2-bin (Ubuntu)"
echo "imagemagick pngquant binutils rsvg (Cygwin)"
read -p "Press any key to exit..." -n1 -s
exit
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 Name"; do
case $choice in
"Service Reference" ) style=srp; break;;
"Service Name" ) style=snp; break;;
esac
done
else
style=$1
fi
############################
## Setup folder locations ##
############################
location="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
buildsource="$location/build-source"
buildtools="$location/resources/tools"
binaries="$location/build-output/binaries-$style"
temp=$(mktemp -d --suffix=.picons)
logfile=$(mktemp --suffix=.picons.log)
#############################################
## Check if previously chosen style exists ##
#############################################
if [[ $style = "srp" ]] || [[ $style = "snp" ]]; then
for file in "$location/build-output/servicelist-"*"-$style" ; do
if [[ ! -f $file ]]; then
echo "No $style servicelist has been found! Exiting..."
read -p "Press any key to exit..." -n1 -s
exit
fi
done
else
echo "You are using an unsupported style! Keep it tidy!"
fi
###########################################################
## Ask the user which resolution and background to build ##
###########################################################
if [[ -z $2 ]]; then
for background in "$buildsource/backgrounds/"* ; do
backgroundname=$(basename $background)
backgrounds="$backgroundname $backgrounds"
done
echo "Which resolution would you like to build?"
select choice in $backgrounds; do
if [[ ! -z $choice ]]; then
backgroundname=$choice; break
fi
done
for backgroundcolor in "$buildsource/backgrounds/$backgroundname/"* ; do
backgroundcolorname=$(basename ${backgroundcolor%.*})
backgroundcolors="$backgroundcolorname $backgroundcolors"
done
echo "Which background would you like to build?"
select choice in $backgroundcolors; do
if [[ ! -z $choice ]]; then
backgroundcolorname=$choice; break
fi
done
else
if [[ $2 = "all" ]]; then
backgroundname=""
backgroundcolorname=""
else
backgroundname=$2
if [[ -z $3 ]]; then
for backgroundcolor in "$buildsource/backgrounds/$backgroundname/"* ; do
backgroundcolorname=$(basename ${backgroundcolor%.*})
backgroundcolors="$backgroundcolorname $backgroundcolors"
done
echo "Which background would you like to build?"
select choice in $backgroundcolors; do
if [[ ! -z $choice ]]; then
backgroundcolorname=$choice; break
fi
done
else
if [[ $3 = "all" ]]; then
backgroundcolorname=""
else
backgroundcolorname=$3
fi
fi
fi
fi
############################################################
## Cleanup previously created folders/files and re-create ##
############################################################
if [[ -d $binaries ]]; then rm -rf "$binaries"; fi
mkdir "$binaries"
##############################
## Determine version number ##
##############################
if [[ -d $location/.git ]] && which git &> /dev/null; then
hash="$(git rev-parse --short HEAD)"
version="$(date --date=@$(git show -s --format=%ct $hash) +'%Y-%m-%d--%H-%M-%S')"
timestamp="$(date --date=@$(git show -s --format=%ct $hash) +'%Y%m%d%H%M.%S')"
else
epoch="date +%s"
version="$(date --date=@$($epoch) +'%Y-%m-%d--%H-%M-%S')"
timestamp="$(date --date=@$($epoch) +'%Y%m%d%H%M.%S')"
fi
echo "$(date +'%H:%M:%S') - Version: $version"
#############################################
## Some basic checking of the source files ##
#############################################
chmod -R 755 "$buildtools/"*.sh
echo "$(date +'%H:%M:%S') - Checking index"
"$buildtools/check-index.sh" "$buildsource" "srp"
"$buildtools/check-index.sh" "$buildsource" "snp"
echo "$(date +'%H:%M:%S') - Checking logos"
"$buildtools/check-logos.sh" "$buildsource/logos"
#############################################################
## Create symlinks, copy required logos and convert to png ##
#############################################################
echo "$(date +'%H:%M:%S') - Creating symlinks and copying logos"
"$buildtools/create-symlinks+copy-logos.sh" "$location/build-output/servicelist-" "$temp/newbuildsource" "$buildsource" "$style" "$location"
echo "$(date +'%H:%M:%S') - Converting svg files"
for file in "$temp/newbuildsource/logos/"*.svg; do
rsvg-convert -w 1000 -h 1000 -a -f png -o ${file%.*}.png "$file"
rm "$file"
done
####################################################################
## Start the actual conversion to picons and creation of packages ##
####################################################################
logocount=$(find "$temp/newbuildsource/logos/" -maxdepth 2 -type f | wc -l)
for background in "$buildsource/backgrounds/$backgroundname"* ; do
backgroundname=$(basename $background)
for backgroundcolor in "$buildsource/backgrounds/$backgroundname/$backgroundcolorname"*.png ; do
currentlogo=""
backgroundcolorname=$(basename ${backgroundcolor%.*})
OLDIFS=$IFS
IFS="-"
sizes=($backgroundname)
IFS="."
logotype=($backgroundcolorname)
IFS=$OLDIFS
backgroundname=${sizes[0]}
logotype=${logotype[0]}
if [[ $backgroundcolorname == *-nopadding ]]; then
resize=${sizes[0]}
else
resize=${sizes[1]}
fi
mkdir -p "$temp/finalpicons/picon/logos"
echo "$(date +'%H:%M:%S') -----------------------------------------------------------"
echo "$(date +'%H:%M:%S') - Creating picons: $style.$backgroundname.$backgroundcolorname"
for logo in "$temp/newbuildsource/logos/"*.default.png ; do
((currentlogo++))
echo -ne " Converting logo: $currentlogo/$logocount"\\r
logoname=$(basename ${logo%.*.*})
if [[ -f $temp/newbuildsource/logos/$logoname.$logotype.png ]]; then
logo="$temp/newbuildsource/logos/$logoname.$logotype.png"
fi
echo "$logo" >> $logfile
convert "$backgroundcolor" \( "$logo" -background none -bordercolor none -border 100 -trim -border 1% -resize $resize -gravity center -extent ${sizes[0]} +repage \) -layers merge - 2>> $logfile | pngquant - 2>> $logfile > "$temp/finalpicons/picon/logos/$logoname.png"
#cat "$backgroundcolor" | git lfs smudge 2>> $logfile | convert - \( "$logo" -background none -bordercolor none -border 100 -trim -border 1% -resize $resize -gravity center -extent ${sizes[0]} +repage \) -layers merge - 2>> $logfile | pngquant - 2>> $logfile > "$temp/finalpicons/picon/logos/$logoname.png"
done
echo "$(date +'%H:%M:%S') - Creating binary packages: $style.$backgroundname.$backgroundcolorname"
cp --no-dereference "$temp/newbuildsource/symlinks/"* "$temp/finalpicons/picon"
packagename="$style.$backgroundname.${backgroundcolorname}_${version}"
mkdir "$temp/finalpicons/CONTROL" ; cat > "$temp/finalpicons/CONTROL/control" <<-EOF
Package: enigma2-plugin-picons-$style.$backgroundname.$backgroundcolorname
Version: $version
Section: base
Architecture: all
Maintainer: https://picons.xyz
Source: https://picons.xyz
Description: $style.$backgroundname.$backgroundcolorname
OE: enigma2-plugin-picons-$style.$backgroundname.$backgroundcolorname
HomePage: https://picons.xyz
License: unknown
Priority: optional
EOF
find "$temp/finalpicons" -exec touch --no-dereference -t "$timestamp" {} \;
"$buildtools/ipkg-build.sh" -o root -g root "$temp/finalpicons" "$binaries" > /dev/null
mv "$temp/finalpicons/picon" "$temp/finalpicons/$packagename"
tar --dereference --owner=root --group=root -cf - --directory="$temp/finalpicons" "$packagename" --exclude="logos" | xz -9 --extreme --memlimit=40% 2>> $logfile > "$binaries/$packagename.hardlink.tar.xz"
tar --owner=root --group=root -cf - --directory="$temp/finalpicons" "$packagename" | xz -9 --extreme --memlimit=40% 2>> $logfile > "$binaries/$packagename.symlink.tar.xz"
find "$binaries" -exec touch -t "$timestamp" {} \;
rm -rf "$temp/finalpicons"
done
backgroundcolorname=""
done
################################################################################
## Cleanup temporary files and let the user know the location of the packages ##
################################################################################
if [[ -d $temp ]]; then rm -rf "$temp"; fi
echo -e "\nThe binary packages are located in:\n$binaries\n"
##########################
## Ask the user to exit ##
##########################
if [[ -z $1 ]]; then
read -p "Press any key to exit..." -n1 -s
fi
echo -e "\n"
exit 0