epm-repoindex 3.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#!/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

22 23 24 25 26 27 28 29 30 31 32 33
# copied from epm-addrepo
get_archlist()
{
    echo "noarch"
    echo "$DISTRARCH"
    case $DISTRARCH in
        x86_64)
            echo "i586"
            ;;
    esac
}

34 35 36
# https://www.altlinux.org/APT_%D0%B2_ALT_Linux/CreateRepository
__epm_repoindex_alt()
{
37
    local archlist="i586 x86_64 x86_64-i586 aarch64 noarch"
38 39 40 41 42 43 44 45 46 47 48 49

    local init=''
    if [ "$1" = "--init" ] ; then
        init='--init'
        shift
    fi

    epm assure genbasedir apt-repo-tools || fatal
    REPO_DIR="$1"
    # TODO: check if we inside arch dir or RPMS.*
    [ -n "$REPO_DIR" ] || REPO_DIR="$(pwd)"
    if [ -z "$init" ] ; then
50
        [ -d "$REPO_DIR" ] || fatal 'Repo dir $REPO_DIR does not exist'
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    fi

    REPO_NAME="$2"
    if [ -z "$REPO_NAME" ] ; then
        # default name
        REPO_NAME="addon"
        # detect name 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
    fi

    if [ -n "$init" ] ; then
        for arch in $(get_archlist); do
            mkdir -pv "$REPO_DIR/$arch/base/"
            mkdir -pv "$REPO_DIR/$arch/RPMS.$REPO_NAME/"
        done
        return
    fi

    for arch in $archlist; do
        [ -d "$REPO_DIR/$arch/RPMS.$REPO_NAME" ] || continue
        mkdir -pv "$REPO_DIR/$arch/base/"
75
        docmd genbasedir --bloat --progress --topdir=$REPO_DIR $arch $REPO_NAME
76
    done
77 78 79 80
}

__epm_repoindex_deb()
{
81 82 83 84 85 86 87
    local init=''
    if [ "$1" = "--init" ] ; then
        init='--init'
        shift
    fi

    local dir="$1"
88
    docmd mkdir -pv "$dir" || fatal
89
    assure_exists gzip
90
    docmd dpkg-scanpackages -t deb "$dir" | gzip | cat > "$dir/Packages.gz"
91 92 93 94 95 96 97
}


epm_repoindex()
{

case $PMTYPE in
98 99 100 101 102 103 104 105
    apt-rpm)
        __epm_repoindex_alt "$@"
        ;;
    apt-dpkg|aptitude-dpkg)
        __epm_repoindex_deb "$@"
        ;;
    yum-rpm)
        epm install --skip-installed yum-utils createrepo || fatal
106 107 108
        docmd mkdir -pv "$@"
        docmd createrepo -v -s md5 "$@"
        docmd verifytree
109 110 111
        ;;
    dnf-rpm)
        epm install --skip-installed yum-utils createrepo || fatal
112 113 114
        docmd mkdir -pv "$@"
        docmd createrepo -v -s md5 "$@"
        docmd verifytree
115 116 117 118 119
        ;;
    eoget)
        docmd eoget index "$@"
        ;;
    *)
120
        fatal 'Have no suitable command for $PMTYPE'
121
        ;;
122 123 124 125
esac

}

126 127 128 129 130

epm_repocreate()
{
    epm_repoindex --init "$@"
}