NBash

Форк
0
177 строк · 5.3 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2023  Etersoft
4
# Copyright (C) 2023  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
load_helper epm-sh-altlinux
21
load_helper epm-assure
22
load_helper epm-repack
23

24
[ -n "$EPM_PACK_SCRIPTS_DIR" ] || EPM_PACK_SCRIPTS_DIR="$CONFIGDIR/pack.d"
25

26
# <packname> <abstarname> [packversion]
27
# fills returntarname with returned tar name or empty
28
__epm_pack_run_handler()
29
{
30
    local packname="$1"
31
    local tarname="$2"
32
    local packversion="$3"
33
    local url="$3"
34
    returntarname=''
35

36
    local repackcode="$EPM_PACK_SCRIPTS_DIR/$packname.sh"
37
    [ -x "$repackcode" ] || return
38
    [ -f "$repackcode.rpmnew" ] && warning "There is .rpmnew file(s) in $EPM_PACK_SCRIPTS_DIR dir. The pack script can be outdated."
39

40
    # a file to keep filename of generated tarball
41
    filefortarname="$(pwd)/filefortarname"
42

43
    [ "$PROGDIR" = "/usr/bin" ] && SCPATH="$PATH" || SCPATH="$PROGDIR:$PATH"
44
    local bashopt=''
45
    [ -n "$debug" ] && bashopt='-x'
46
    #info "Running $($script --description 2>/dev/null) ..."
47
    # TODO: add url info here
48
    ( unset EPMCURDIR ; export PATH=$SCPATH ; docmd $CMDSHELL $bashopt $repackcode "$tarname" "$filefortarname" "$packversion" "$url") || fatal
49
    returntarname="$(cat "$filefortarname")" || fatal "pack script $repackcode didn't set tarname"
50

51
    local i
52
    for i in $returntarname ; do
53
        [ -s "$i" ] || fatal "pack script for $packname returned unexist $i file"
54
    done
55

56
    return 0
57
}
58

59
# we run this function in a tmpdir
60
__epm_pack()
61
{
62
    local packname="$1"
63
    local URL="$4"
64

65
    # fills returntarname with packed tar
66
    __epm_pack_run_handler "$@" || fatal "Can't find pack script for packname $packname"
67

68
    if [ -n "$download_only" ] ; then
69
        mv $returntarname $EPMCURDIR
70
        return
71
    fi
72

73
    # TODO: merge eepm.yaml here (common with $returntarname.eepm.yaml)
74
    # add upstream_url: $URL too
75

76
    # note: this repack related code here for follow reasons:
77
    #  * repack by default if we have repack rule
78
    #  * get repacked files
79
    #  * install (repacked) files
80
    # the most replacement is epm repack [--install] or epm install [--repack]
81

82
    # FIXME: check for every package would be more reliable
83
    # by default
84
    dorepack='--repack'
85
    # don't repack by default there is our pkg format
86
    __epm_split_by_pkg_type $PKGFORMAT $returntarname && dorepack=''
87
    # repack if we have a repack rule for it
88
    [ -z "$norepack" ] && __epm_have_repack_rule $returntarname && dorepack='--repack'
89
    # repack if forced
90
    [ -n "$repack" ] && dorepack='--repack'
91

92
    local pkgnames
93
    if [ -n "$dorepack" ]  ; then
94
        __epm_repack $returntarname
95
        [ -n "$repacked_pkgs" ] || fatal "Can't repack $returntarname"
96
        # remove packed file if we have repacked one
97
        rm -f $returntarname
98
        pkgnames="$repacked_pkgs"
99
    else
100
        pkgnames="$returntarname"
101
    fi
102

103
    if [ -n "$install" ] ; then
104
        docmd epm install $pkgnames
105
        return
106
    fi
107

108
    # we need put result in the cur dir
109
    mv -v $pkgnames $EPMCURDIR || fatal
110

111
    local i
112
    for i in $pkgnames ; do
113
        [ -r "$i.eepm.yaml" ] && mv -v "$i.eepm.yaml" $EPMCURDIR
114
    done
115

116
    return 0
117
}
118

119
epm_pack_help()
120
{
121
    cat <<EOF
122
epm pack - create rpm package from files
123
Usage: epm pack [options] <packname> <tar|url|dir> [version]
124
Options:
125
    <packname>            - receipt
126
    <dir>                 - create tarball from the dir before
127
    <url>                 - download tar from url
128
    [version]             - force version for unversioned sources
129
    --install             - install after pack result
130
    --repack              - force repack ever if returned package can be installed without repack
131
    --download-only       - save pack result and exit
132
    --save-only           - save repacked packages and exit (this is default behaviour)
133
EOF
134
}
135

136

137
epm_pack()
138
{
139

140
    if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
141
        epm_pack_help
142
        exit
143
    fi
144

145
    local tmpdir
146
    tmpdir="$(mktemp -d --tmpdir=$BIGTMPDIR)" || fatal
147
    remove_on_exit "$tmpdir"
148

149
    local packname="$1"
150
    local tarname="$2"
151
    local packversion="$3"
152
    local url=''
153

154
    [ -n "$packname" ] || fatal "run with packname, see --help"
155

156
    if is_url "$tarname"; then
157
        url="$tarname"
158
        pkg_urls="$tarname"
159
        load_helper epm-download
160
        cd $tmpdir || fatal
161
        __handle_pkg_urls_to_install
162
        [ -n "$pkg_files" ] || fatal "Can't download $tarname"
163
        tarname="$(realpath "$pkg_files")"
164
    elif [ -d "$tarname" ] ; then
165
        tarname="$(realpath "$tarname")"
166
    elif [ -s "$tarname" ] ; then
167
        # get full path for real name
168
        tarname="$(realpath "$tarname")"
169
    else
170
        # just pass name
171
        true
172
    fi
173

174
    cd $tmpdir || fatal
175
    __epm_pack "$packname" "$tarname" "$packversion" "$url"
176

177
}
178

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

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

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

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