epm-repopkg 3.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/bin/sh
#
# Copyright (C) 2023  Etersoft
# Copyright (C) 2023  Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

load_helper epm-sh-altlinux

__epm_repo_pkgadd_alt()
{
24
    local archlist="i586 x86_64 aarch64 noarch"
25

26 27
    local REPO_DIR="$1"
    shift
28
    [ -d "$REPO_DIR" ] || fatal 'Can'\''t find repo dir $REPO_DIR.'
29

30 31 32 33 34 35 36
    # default name
    REPO_NAME="addon"
    # detect if already exists
    for arch in $archlist ; do
        local rd="$(echo $REPO_DIR/$arch/RPMS.*)"
        [ -d "$rd" ] && REPO_NAME="$(echo "$rd" | sed -e 's|.*\.||')" && break
    done
37

38
    [ -n "$1" ] || fatal "Missed package name"
39

40 41
    while [ -s "$1" ] ; do
        arch="$(epm print arch from filename "$1")" || fatal
42 43 44
        # arch hack (it is better to repack firstly)
        [ "$arch" = "i686" ] && arch="i586"
        [ "$arch" = "i386" ] && arch="i586"
45
        [ -d $REPO_DIR/$arch/RPMS.$REPO_NAME ] || fatal
46 47 48 49
        epm checkpkg "$1" || fatal
        cp -v "$1" $REPO_DIR/$arch/RPMS.$REPO_NAME || fatal
        shift
    done
50 51 52 53 54 55

}


__epm_repo_pkgdel_alt()
{
56 57 58 59
    local archlist="i586 x86_64 aarch64 noarch"

    local REPO_DIR="$1"
    shift
60
    [ -d "$REPO_DIR" ] || fatal 'Can'\''t find repo dir $REPO_DIR.'
61 62 63 64 65 66 67 68 69 70 71 72 73 74

    [ -n "$1" ] || fatal "Missed package name"

    # default name
    REPO_NAME="addon"
    # detect if already exists
    for arch in $archlist ; do
        local rd="$(echo $REPO_DIR/$arch/RPMS.*)"
        [ -d "$rd" ] && REPO_NAME="$(echo "$rd" | sed -e 's|.*\.||')" && break
    done

    while [ -s "$1" ] ; do
        for arch in $archlist ; do
            local rd="$REPO_DIR/$arch/RPMS.$REPO_NAME"
75
            [ -d $REPO_DIR/$arch/RPMS.$REPO_NAME ] || continue
76
            for i in $rd/$1* ; do
77
                [ "$1" = "$(epm print name for package $i)" ] || continue
78 79 80 81 82
                rm -v $rd/$1*
            done
        done
        shift
    done
83 84 85 86 87 88

}


__epm_repo_pkgupdate_alt()
{
89 90 91 92 93 94 95
    local dir="$1"
    shift
    for i in "$@" ; do
        pkg="$(epm print name for package $i)" || fatal
        __epm_repo_pkgdel_alt "$dir" $pkg
    done
    __epm_repo_pkgadd_alt "$dir" "$@"
96 97 98 99 100 101 102 103
}



epm_repo_pkgadd()
{

case $PMTYPE in
104 105 106 107
    apt-rpm)
        __epm_repo_pkgadd_alt "$@"
        ;;
    *)
108
        fatal 'Have no suitable command for $PMTYPE'
109
        ;;
110 111 112 113 114 115 116 117 118
esac

}


epm_repo_pkgupdate()
{

case $PMTYPE in
119 120 121 122
    apt-rpm)
        __epm_repo_pkgupdate_alt "$@"
        ;;
    *)
123
        fatal 'Have no suitable command for $PMTYPE'
124
        ;;
125 126 127 128 129 130 131 132 133
esac

}


epm_repo_pkgdel()
{

case $PMTYPE in
134 135 136 137
    apt-rpm)
        __epm_repo_pkgdel_alt "$@"
        ;;
    *)
138
        fatal 'Have no suitable command for $PMTYPE'
139
        ;;
140 141 142 143
esac

}

144 145 146 147 148
# call with packages to put to $put_to_repo
epm_put_to_repo()
{
    epm_repo_pkgupdate "$put_to_repo" "$@"
}