-
Notifications
You must be signed in to change notification settings - Fork 26
/
2-build-picons.sh
executable file
·206 lines (172 loc) · 7.71 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
#!/bin/bash
#####################
## Setup locations ##
#####################
location=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
temp=$(mktemp -d --suffix=.picons)
logfile=$(mktemp --suffix=.picons.log)
echo -e "\nLog file located at: $logfile\n"
########################################################
## Search for required commands and exit if not found ##
########################################################
commands=( convert pngquant ar tar xz sed grep tr column 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 "ERROR: The following commands are not found: $missingcommands" >> $logfile
echo "ERROR: Try installing: imagemagick pngquant binutils" >> $logfile
exit 1
fi
if which "inkscape" &> /dev/null && [[ -f $location/build-input/svgconverter.inkscape ]]; then
svgconverter="inkscape -w 850 --without-gui --export-area-drawing --export-png="
elif which "rsvg-convert" &> /dev/null; then
svgconverter="rsvg-convert -w 1000 --keep-aspect-ratio --output "
else
echo "ERROR: No SVG converter has been found!" >> $logfile
echo "ERROR: Try installing on Ubuntu: librsvg2-bin (or: inkscape)" >> $logfile
echo "ERROR: Try installing on Cygwin: rsvg (or: inkscape)" >> $logfile
exit 1
fi
###########################
## Check path for spaces ##
###########################
if [[ $location == *" "* ]]; then
echo "ERROR: The path contains spaces, please move the repository to a path without spaces!" >> $logfile
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 ; do
if [[ ! -f $file ]]; then
echo "ERROR: No $style servicelist has been found!" >> $logfile
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 --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 ##
#############################################
echo "$(date +'%H:%M:%S') - 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') - Checking logos"
$location/resources/tools/check-logos.sh $location/build-source/logos
#####################
## Create symlinks ##
#####################
echo "$(date +'%H:%M:%S') - Creating symlinks"
$location/resources/tools/create-symlinks.sh $location $temp $style
####################################################################
## Start the actual conversion to picons and creation of packages ##
####################################################################
logocount=$(readlink $temp/symlinks/* | sed -e 's/logos\///g' -e 's/.png//g' | sort -u | 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') - No \"backgrounds.conf\" file found in \"build-input\", using default file!"
backgroundsconf=$location/build-source/backgrounds/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]}
packagenamenoversion=$style.$resolution-$resize.$type.on.$background
packagename=$style.$resolution-$resize.$type.on.${background}_${version}
mkdir -p $temp/package/picon/logos
echo "$(date +'%H:%M:%S') -----------------------------------------------------------"
echo "$(date +'%H:%M:%S') - Creating picons: $packagenamenoversion"
readlink $temp/symlinks/* | sed -e 's/logos\///g' -e 's/.png//g' | sort -u | while read logoname ; do
((currentlogo++))
echo -ne " Converting logo: $currentlogo/$logocount"\\r
if [[ -f $location/build-source/logos/$logoname.$type.png ]] || [[ -f $location/build-source/logos/$logoname.$type.svg ]]; then
logotype=$type
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 >> $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') - Creating binary packages: $packagenamenoversion"
cp --no-dereference $temp/symlinks/* $temp/package/picon
mkdir $temp/package/CONTROL ; cat > $temp/package/CONTROL/control <<-EOF
Package: enigma2-plugin-picons-$packagenamenoversion
Version: $version
Section: base
Architecture: all
Maintainer: https://picons.xyz
Source: https://picons.xyz
Description: $packagenamenoversion
OE: enigma2-plugin-picons-$packagenamenoversion
HomePage: https://picons.xyz
License: unknown
Priority: optional
EOF
find $temp/package -exec touch --no-dereference -t $timestamp {} \;
$location/resources/tools/ipkg-build.sh -o root -g root $temp/package $binaries >> $logfile
mv $temp/package/picon $temp/package/$packagename
tar --dereference --owner=root --group=root -cf - --directory=$temp/package $packagename --exclude=logos | xz -9 --extreme --memlimit=40% 2>> $logfile > $binaries/$packagename.hardlink.tar.xz
tar --owner=root --group=root -cf - --directory=$temp/package $packagename | xz -9 --extreme --memlimit=40% 2>> $logfile > $binaries/$packagename.symlink.tar.xz
find $binaries -exec touch -t $timestamp {} \;
rm -rf $temp/package
done
######################################
## Cleanup temporary files and exit ##
######################################
if [[ -d $temp ]]; then rm -rf $temp; fi
exit 0