summaryrefslogtreecommitdiff
path: root/src/shared/upstream.sh
blob: d310be7364e955e33cca43379c281d18eb57387f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
 ##############################################################################
 #                      parabola-riscv64-bootstrap                            #
 #                                                                            #
 #    Copyright (C) 2018  Andreas Grapentin                                   #
 #                                                                            #
 #    This program is free software: you can redistribute it and/or modify    #
 #    it under the terms of the GNU 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 General Public License for more details.                            #
 #                                                                            #
 #    You should have received a copy of the GNU General Public License       #
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.   #
 ##############################################################################

package_get_upstream_repo() {
  local repo url response target=
  for repo in core extra community; do
    url=https://www.archlinux.org/packages/$repo/x86_64/$1/
    response=$(retry -n 5 -s 60 curl -sL "$url") || die "failed to retrieve url $url"
    grep -iq "Arch Linux - $1" <<< "$response" || continue

    target=$repo
    break
  done
  [ -z "$target" ] || target=libre
  echo $target
}

package_fetch_upstream_pkgfiles() {
  # fetch upstream pkgbuilds from arch
  local repo repoinfo pkgbase
  repoinfo=$(asp list-repos "$1") || repoinfo=""
  repo=$(grep -P '^(core|extra|community)' <<< "$repoinfo" | head -n1)
  pkgbase=$(grep -o 'part of package .*' <<< "$repoinfo" | awk '{print $4}')

  [ -z "$repo" ] && repo=libre
  [ -z "$pkgbase" ] && pkgbase="$1"

  mkdir -p .arch
  asp export "$repo/$1" >/dev/null
  mv "$pkgbase"/* .arch/
  rm -rf "$pkgbase"

  # fetch upstream pkgbuilds from parabola
  mkdir -p .parabola
  local src url=https://www.parabola.nu/packages/libre/x86_64/$1/
  if ! curl -sL "$url" | grep -iq 'not found'; then
    src=$(curl -sL "$url" | grep -i 'source files' | cut -d'"' -f2 | sed 's#/tree/#/plain/#')
    for link in $(curl -sL "$src" | grep '^  <li><a href' | cut -d"'" -f2 \
        | sed "s#^#$(echo "$src" | awk -F/ '{print $3}')#"); do
      wget -q "$link" -O .parabola/"$(basename "${link%\?*}")";
    done
  fi

  if [ -f .parabola/PKGBUILD ]; then
    cp -v .parabola/* .
  elif [ -f .arch/PKGBUILD ]; then
    cp -v .arch/* .
  else
    return "$ERROR_MISSING"
  fi
}

#package_fetch_upstream_pkgfiles() {
#  FIXME
#  # acquire the pkgbuild and auxiliary files
#  local url=https://www.parabola.nu/packages/libre/x86_64/$1/
#  _fetch_pkgfiles_from $url && echo "libre" > .REPO && return
#
#  local repo
#  for repo in core extra community; do
#    url=https://www.archlinux.org/packages/$repo/x86_64/$1/
#    _fetch_pkgfiles_from $url && echo "$repo" > .REPO && return
#  done
#  die "$1: failed to fetch pkgfiles"
#}
#
#_fetch_pkgfiles_from() {
#  curl -sL $url | grep -iq 'not found' && return 1
#  local src=$(curl -sL $url | grep -i 'source files' | cut -d'"' -f2 | sed 's#/tree/#/plain/#')
#  for link in $(curl -sL $src | grep '^  <li><a href' | cut -d"'" -f2 \
#      | sed "s#^#$(echo $src | awk -F/ '{print $3}')#"); do
#    wget -q $link -O $(basename ${link%\?*});
#  done
#  [ -f PKGBUILD ] || return 1
#}