NBash

Форк
0
247 строк · 8.3 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2017-2018, 2020  Etersoft
4
# Copyright (C) 2017-2018, 2020  Vitaly Lipatov <lav@etersoft.ru>
5
#
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.
10
#
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.
15
#
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/>.
18
#
19

20
__get_icons_hicolor_list()
21
{
22
    local i j
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"
27
        done
28
    done
29
}
30

31
# args: pkgname buildroot spec
32
__fix_spec()
33
{
34
    local pkgname="$1"
35
    local buildroot="$2"
36
    local spec="$3"
37
    local i
38

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
44
        sed -i \
45
            -e "s|/\./|/|" \
46
            -e "s|^%dir[[:space:]]\"$i/*\"$||" \
47
            -e "s|^%dir[[:space:]]$i/*$||" \
48
            -e "s|^\"$i/*\"$||" \
49
            -e "s|^$i/*$||" \
50
            $spec
51
    done
52

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"
58
    #done
59

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
65
        #else
66
        #    subst 's|^\("'$i'"\)$|\1|' $spec
67
        fi
68
    done
69

70
}
71

72
has_repack_script()
73
{
74
    local repackcode="$EPM_REPACK_SCRIPTS_DIR/$1.sh"
75
    [ -s "$repackcode" ]
76
}
77

78
# args: pkgname buildroot spec
79
__apply_fix_code()
80
{
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."
84

85
    shift
86
    [ "$PROGDIR" = "/usr/bin" ] && SCPATH="$PATH" || SCPATH="$PROGDIR:$PATH"
87
    local bashopt=''
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"
90
}
91

92
__create_rpmmacros()
93
{
94
    cat <<EOF >$HOME/.rpmmacros
95
%_topdir    $HOME/RPM
96
%_tmppath    $TMPDIR
97

98
%packager    EPM <support@eepm.ru>
99
%_vendor    EEPM
100
%_gpg_name    support@etersoft.ru
101
# TODO: use special user for repack (instead of root of local user)
102
%_allow_root_build    1
103
EOF
104
    remove_on_exit "$HOME/.rpmmacros"
105
}
106

107
# will set RPMBUILD
108
__try_install_eepm_rpmbuild()
109
{
110
    RPMBUILD=/usr/bin/rpmbuild
111
    [ -x "$RPMBUILD" ] && return
112

113
    RPMBUILD=/usr/bin/eepm-rpmbuild
114
    if [ ! -x $RPMBUILD ] ; then
115
        epm install eepm-rpm-build
116
    fi
117

118
    if [ -x $RPMBUILD ] ; then
119
        warning "will use eepm-rpmbuild for rpm packing"
120
        export EPM_RPMBUILD=$RPMBUILD
121
        return
122
    fi
123

124
    RPMBUILD=/usr/bin/rpmbuild
125
}
126

127
# will fill repacked_pkgs var
128
__epm_repack_to_rpm()
129
{
130
    local pkgs="$*"
131

132
    # Note: install epm-repack for static (package based) dependencies
133
    assure_exists alien || fatal
134

135
    # will set RPMBUILD
136
    __try_install_eepm_rpmbuild
137

138
    if [ ! -x $RPMBUILD ] ; then
139
        RPMBUILD=/usr/bin/rpmbuild
140
        # TODO: check for all systems
141
        case $PKGFORMAT in
142
            rpm)
143
                assure_exists $RPMBUILD rpm-build || fatal
144
                ;;
145
            deb)
146
                assure_exists $RPMBUILD rpm || fatal
147
                ;;
148
        esac
149
    fi
150

151
    umask 022
152

153
    # TODO: improve
154
    if echo "$pkgs" | grep -q "\.deb" ; then
155
        assure_exists dpkg || fatal
156
        # TODO: Для установки требует: /usr/share/debconf/confmodule но пакет не может быть установлен
157
        # assure_exists debconf
158
    fi
159

160
    local pkg
161
    local alpkg
162
    local abspkg
163
    local tmpbuilddir
164
    repacked_pkgs=''
165
    for pkg in $pkgs ; do
166
        # TODO: keep home?
167
        HOME="$(mktemp -d --tmpdir=$BIGTMPDIR)" || fatal
168
        remove_on_exit $HOME
169
        export HOME
170
        __create_rpmmacros
171

172
        tmpbuilddir=$HOME/$(basename $pkg).tmpdir
173
        mkdir $tmpbuilddir
174
        abspkg="$(realpath $pkg)"
175
        info ""
176
        info "Repacking $abspkg to local rpm format (inside $tmpbuilddir) ..."
177

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
181

182
        cd $tmpbuilddir/../ || fatal
183
        # fill alpkg and SUBGENERIC
184
        __prepare_source_package "$(realpath $alpkg)"
185
        cd $tmpbuilddir/ || fatal
186

187
        if [ -n "$verbose" ] ; then
188
            docmd alien --generate --to-rpm $verbose $scripts "../$alpkg" || fatal
189
        else
190
            showcmd alien --generate --to-rpm $scripts "../$alpkg"
191
            a='' alien --generate --to-rpm $scripts "../$alpkg" >/dev/null || fatal
192
        fi
193

194
        # remove all empty dirs (hack against broken dpkg with LF in the end of line) (hack for linux_pantum.deb)
195
        rmdir * 2>/dev/null
196

197
        local subdir="$(echo *)"
198
        [ -d "$subdir" ] || fatal "can't find subdir in $(pwd)"
199

200
        local buildroot="$tmpbuilddir/$subdir"
201

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/*
204

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")"
210

211
        local pkgname="$(grep "^Name: " $spec | sed -e "s|Name: ||g" | head -n1)"
212

213
        # run generic scripts and repack script for the pkg
214
        cd $buildroot || fatal
215

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
222
        fi
223
        cd - >/dev/null
224

225
        TARGETARCH=$(epm print info -a | sed -e 's|^x86$|i586|')
226

227
        showcmd $RPMBUILD --buildroot $buildroot --target $TARGETARCH -bb $spec
228
        if [ -n "$verbose" ] ; then
229
            a='' $RPMBUILD --buildroot $buildroot --target $TARGETARCH -bb $spec || fatal
230
        else
231
            a='' $RPMBUILD --buildroot $buildroot --target $TARGETARCH -bb $spec >/dev/null || fatal
232
        fi
233

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"
240
        else
241
            warning "Can't find converted rpm for source binary package '$pkg' (got $repacked_rpm)"
242
        fi
243
        cd $EPMCURDIR >/dev/null
244
    done
245

246
    true
247
}
248

249

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.