NBash

Форк
0
151 строка · 3.4 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2015,2016  Etersoft
4
# Copyright (C) 2015,2016  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-query
21
load_helper epm-print
22

23
PAOURL="https://packages.altlinux.org"
24

25
paoapi()
26
{
27
    # http://petstore.swagger.io/?url=http://packages.altlinux.org/api/docs
28
    assure_exists curl || return 1
29
    showcmd curl "$PAOURL/api/$1"
30
    a='' curl -s --header "Accept: application/json" "$PAOURL/api/$1"
31
}
32

33
# TODO: use /home/lav/Projects/git/JSON.sh
34
get_pao_var()
35
{
36
    local FIELD="$1"
37
    #grep '"$FIELD"' | sed -e 's|.*"$FIELD":"||g' | sed -e 's|".*||g'
38
    $SHAREDIR/tools_json -b | grep -E "\[.*\"$FIELD\"\]" | sed -e 's|.*[[:space:]]"\(.*\)"|\1|g'
39
    return 0
40
}
41

42

43
run_command_if_exists()
44
{
45
    local CMD="$1"
46
    shift
47
    if is_command "$CMD" ; then
48
        docmd $CMD "$@"
49
        return 0
50
    fi
51
    return 1
52
}
53

54
# TODO: use something like xdg-browser
55
open_browser()
56
{
57
    local i
58
    for i in xdg-open firefox chromium links ; do
59
        run_command_if_exists $i "$@" && return
60
    done
61
}
62

63
__query_package_hl_url()
64
{
65
    case $DISTRNAME in
66
        ALTLinux)
67
            paoapi srpms/$1 | get_pao_var url
68
            ;;
69
    esac
70
    return 1
71
}
72

73
query_package_url()
74
{
75
    local URL
76

77
    case $PMTYPE in
78
        *-rpm)
79
            # TODO: for binary packages?
80
            query_package_field URL "$1" || __query_package_hl_url "$1"
81
            #LANG=C epm info "$1"
82
            return
83
            ;;
84
        homebrew)
85
            docmd brew "$1" | grep "^From: " | sed -e "s|^From: ||"
86
            return
87
            ;;
88
    esac
89
    fatal "rpm based distro supported only. TODO: Realize via web service?"
90
}
91

92
get_locale()
93
{
94
    local loc
95
    loc=$(a='' natspec --locale 2>/dev/null)
96
    [ -n "$loc" ] || loc=$LANG
97
    echo $loc
98
}
99

100
get_pao_url()
101
{
102
    local loc
103
    loc=$(get_locale | cut -c1-2)
104
    case $loc in
105
        en|ru|uk|br)
106
            loc=$loc
107
            ;;
108
        *)
109
            loc=en
110
    esac
111
    echo "$PAOURL/$loc/Sisyphus/srpms"
112
}
113

114
query_altlinux_url()
115
{
116
    local URL
117
    case $PMTYPE in
118
        *-rpm)
119
            local srpm=$(print_srcname "$1")
120
            [ -n "$srpm" ] || fatal "Can't get source name for $1"
121
            echo "$(get_pao_url)/$srpm"
122
            return
123
            ;;
124
    esac
125
    fatal "rpm based distro supported only. TODO: Realize via web service?"
126
}
127

128
epm_site()
129
{
130

131
[ -n "$pkg_filenames" ] || fatal "Info: package name is missed"
132

133
local PAO=""
134
for f in $pkg_names $pkg_files ; do
135
    [ "$f" = "-p" ] && PAO="$f" && continue
136
    if [ -n "$PAO" ] ; then
137
        pkg_url=$(query_altlinux_url $f)
138
    else
139
        pkg_url=$(query_package_url $f)
140
    fi
141
    [ -n "$pkg_url" ] && open_browser "$pkg_url" && continue
142
    warning "Can't get URL for $f package"
143
done
144

145
#for f in $pkg_names ; do
146
#    LANG=C epm info $f
147
#done
148

149
# TODO: -p for p.a.o (see rpmurl)
150

151
}
152

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

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

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

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