3
# Copyright (C) 2017-2018, 2020 Etersoft
4
# Copyright (C) 2017-2018, 2020 Vitaly Lipatov <lav@etersoft.ru>
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
__get_icons_hicolor_list()
23
for i in apps scalable symbolic 8x8 14x14 16x16 20x20 22x22 24x24 28x28 32x32 36x36 42x42 45x45 48x48 64 64x64 72x72 96x96 128x128 144x144 160x160 192x192 256x256 256x256@2x 480x480 512 512x512 1024x1024 ; do
24
echo "/usr/share/icons/hicolor/$i"
25
for j in actions animations apps categories devices emblems emotes filesystems intl mimetypes places status stock ; do
26
echo "/usr/share/icons/hicolor/$i/$j"
31
# args: pkgname buildroot spec
39
# drop forbidded paths
40
# https://bugzilla.altlinux.org/show_bug.cgi?id=38842
41
for i in / /etc /etc/init.d /etc/systemd /bin /opt /usr /usr/bin /usr/lib /usr/lib64 /usr/share /usr/share/doc /var /var/log /var/run \
42
/etc/cron.daily /usr/share/icons/usr/share/pixmaps /usr/share/man /usr/share/man/man1 /usr/share/appdata /usr/share/applications /usr/share/menu \
43
/usr/share/icons/hicolor $(__get_icons_hicolor_list) ; do
46
-e "s|^%dir[[:space:]]\"$i/*\"$||" \
47
-e "s|^%dir[[:space:]]$i/*$||" \
53
# commented out: conflicts with already installed package
54
# drop %dir for existed system dirs
55
#for i in $(grep '^%dir "' $spec | sed -e 's|^%dir *"\(.*\)".*|\1|' ) ; do #"
56
# echo "$i" | grep -q '^/opt/' && continue
57
# [ -d "$i" ] && [ -n "$verbose" ] && echo "drop dir $i from packing, it exists in the system"
60
# replace dir "/path/dir" -> %dir /path/dir
61
grep '^"/' $spec | sed -e 's|^"\(/.*\)"$|\1|' | while read i ; do
62
# add dir as %dir in the filelist
63
if [ -d "$buildroot$i" ] ; then
64
subst "s|^\(\"$i\"\)$|%dir \1|" $spec
66
# subst 's|^\("'$i'"\)$|\1|' $spec
74
local repackcode="$EPM_REPACK_SCRIPTS_DIR/$1.sh"
78
# args: pkgname buildroot spec
81
local repackcode="$EPM_REPACK_SCRIPTS_DIR/$1.sh"
82
[ -s "$repackcode" ] || return
83
[ -f "$repackcode.rpmnew" ] && warning "There is .rpmnew file(s) in $EPM_REPACK_SCRIPTS_DIR dir. The pack script can be outdated."
86
[ "$PROGDIR" = "/usr/bin" ] && SCPATH="$PATH" || SCPATH="$PROGDIR:$PATH"
88
[ -n "$debug" ] && bashopt='-x'
89
( unset EPMCURDIR ; export PATH=$SCPATH ; docmd $CMDSHELL $bashopt $repackcode "$1" "$2" "$3" "$4" "$5" ) || fatal "There is an error from $repackcode script"
94
cat <<EOF >$HOME/.rpmmacros
98
%packager EPM <support@eepm.ru>
100
%_gpg_name support@etersoft.ru
101
# TODO: use special user for repack (instead of root of local user)
104
remove_on_exit "$HOME/.rpmmacros"
108
__try_install_eepm_rpmbuild()
110
RPMBUILD=/usr/bin/rpmbuild
111
[ -x "$RPMBUILD" ] && return
113
RPMBUILD=/usr/bin/eepm-rpmbuild
114
if [ ! -x $RPMBUILD ] ; then
115
epm install eepm-rpm-build
118
if [ -x $RPMBUILD ] ; then
119
warning "will use eepm-rpmbuild for rpm packing"
120
export EPM_RPMBUILD=$RPMBUILD
124
RPMBUILD=/usr/bin/rpmbuild
127
# will fill repacked_pkgs var
132
# Note: install epm-repack for static (package based) dependencies
133
assure_exists alien || fatal
136
__try_install_eepm_rpmbuild
138
if [ ! -x $RPMBUILD ] ; then
139
RPMBUILD=/usr/bin/rpmbuild
140
# TODO: check for all systems
143
assure_exists $RPMBUILD rpm-build || fatal
146
assure_exists $RPMBUILD rpm || fatal
154
if echo "$pkgs" | grep -q "\.deb" ; then
155
assure_exists dpkg || fatal
156
# TODO: Для установки требует: /usr/share/debconf/confmodule но пакет не может быть установлен
157
# assure_exists debconf
165
for pkg in $pkgs ; do
167
HOME="$(mktemp -d --tmpdir=$BIGTMPDIR)" || fatal
172
tmpbuilddir=$HOME/$(basename $pkg).tmpdir
174
abspkg="$(realpath $pkg)"
176
info "Repacking $abspkg to local rpm format (inside $tmpbuilddir) ..."
178
alpkg=$(basename $pkg)
179
# don't use abs package path: copy package to temp dir and use there
180
cp -l $verbose $pkg $tmpbuilddir/../$alpkg || cp $verbose $pkg $tmpbuilddir/../$alpkg || fatal
182
cd $tmpbuilddir/../ || fatal
183
# fill alpkg and SUBGENERIC
184
__prepare_source_package "$(realpath $alpkg)"
185
cd $tmpbuilddir/ || fatal
187
if [ -n "$verbose" ] ; then
188
docmd alien --generate --to-rpm $verbose $scripts "../$alpkg" || fatal
190
showcmd alien --generate --to-rpm $scripts "../$alpkg"
191
a='' alien --generate --to-rpm $scripts "../$alpkg" >/dev/null || fatal
194
# remove all empty dirs (hack against broken dpkg with LF in the end of line) (hack for linux_pantum.deb)
197
local subdir="$(echo *)"
198
[ -d "$subdir" ] || fatal "can't find subdir in $(pwd)"
200
local buildroot="$tmpbuilddir/$subdir"
202
# for tarballs fix permissions (ideally fix in pack.d/generic-tar.sh, but there is tar repacking only)
203
[ "$SUBGENERIC" = "tar" ] && chmod $verbose -R a+rX $buildroot/*
205
# detect spec and move to prev dir
206
local spec="$(echo $buildroot/*.spec)"
207
[ -s "$spec" ] || fatal "Can't find spec $spec"
208
mv $spec $tmpbuilddir || fatal
209
spec="$tmpbuilddir/$(basename "$spec")"
211
local pkgname="$(grep "^Name: " $spec | sed -e "s|Name: ||g" | head -n1)"
213
# run generic scripts and repack script for the pkg
214
cd $buildroot || fatal
216
__fix_spec $pkgname $buildroot $spec
217
__apply_fix_code "generic" $buildroot $spec $pkgname $abspkg $SUBGENERIC
218
__apply_fix_code "generic-$SUBGENERIC" $buildroot $spec $pkgname $abspkg
219
__apply_fix_code $pkgname $buildroot $spec $pkgname $abspkg
220
if ! has_repack_script $pkgname ; then
221
__apply_fix_code "generic-default" $buildroot $spec $pkgname $abspkg
225
TARGETARCH=$(epm print info -a | sed -e 's|^x86$|i586|')
227
showcmd $RPMBUILD --buildroot $buildroot --target $TARGETARCH -bb $spec
228
if [ -n "$verbose" ] ; then
229
a='' $RPMBUILD --buildroot $buildroot --target $TARGETARCH -bb $spec || fatal
231
a='' $RPMBUILD --buildroot $buildroot --target $TARGETARCH -bb $spec >/dev/null || fatal
234
# remove copy of source binary package (don't mix with generated)
235
rm -f $tmpbuilddir/../$alpkg
236
local repacked_rpm="$(realpath $tmpbuilddir/../*.rpm)"
237
if [ -s "$repacked_rpm" ] ; then
238
remove_on_exit "$repacked_rpm"
239
[ -n "$repacked_pkgs" ] && repacked_pkgs="$repacked_pkgs $repacked_rpm" || repacked_pkgs="$repacked_rpm"
241
warning "Can't find converted rpm for source binary package '$pkg' (got $repacked_rpm)"
243
cd $EPMCURDIR >/dev/null