summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 43aa8dd21bddf2791b2e04e040596a2d3b35b572 (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
# Maintainer: insmtr <insmtr@insmtr.cn>

pkgname=openlist-git
pkgver=dev
pkgrel=2
pkgdesc="A new AList Fork to Anti Trust Crisis"
arch=('x86_64' 'aarch64')
url="https://github.com/OpenListTeam/OpenList"
license=('AGPL-3.0-only')
depends=('glibc')
makedepends=('git' 'go' 'curl' 'jq' 'tar')
provides=('openlist')
backup=('etc/openlist/config.json')
optdepends=('aria2: download by aria2.')
source=("$pkgname::git+https://github.com/OpenListTeam/OpenList.git"
        "config.json"
        "openlist.service"
        "openlist.sysusers"
        "openlist.tmpfiles"
        "openlist.install")
install=openlist.install
options=(!debug)
sha256sums=('SKIP'
            '9259caae294aebb88e0e25f83074e090f3581556c05548544739edf88c028537'
            '4bc1ccc08f17f5c9ce0fe7fc600ea9d5e1b034d52a776244c627bc13a3fa401d'
            'fe9c68aa8a6a27477049c839cb5818ba3ddbd88c6813dd2eacea73da70807905'
            'e4f341a876f43b551b67b730aa93dc3a8d2e5f6863ca234852a4389aa64c0aca'
            'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')

pkgver() {
    cd "$pkgname"
    printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

build() {
    cd "$pkgname"
    rm -rf public/dist && mkdir -p public/dist
    echo "Downloading frontend assets..."
    frontend_url=$(curl -fsSL --max-time 10 -H "Accept: application/vnd.github.v3+json" \
        "https://api.github.com/repos/OpenListTeam/OpenList-Frontend/releases" | \
        jq -r 'map(select(.prerelease)) | first | .tag_name')
    if [ "$frontend_url" != "null" ] && [ -n "$frontend_url" ]; then
        asset_url=$(curl -fsSL --max-time 10 -H "Accept: application/vnd.github.v3+json" \
            "https://api.github.com/repos/OpenListTeam/OpenList-Frontend/releases/tags/$frontend_url" | \
            jq -r '.assets[].browser_download_url' | \
            grep "openlist-frontend-dist" | \
            grep "\.tar\.gz$" | head -1)
        if [ -n "$asset_url" ]; then
            curl -fsSL "$asset_url" | tar zxvf - -C public/dist
        else
            echo "Error: Could not find frontend assets package"
            exit 1
        fi
    else
        echo "Error: Could not get frontend version info"
        exit 1
    fi
    echo "Building OpenList..."
    go build -o ../openlist \
        -ldflags="--extldflags '-static -fpic' -w -s \
        -X 'github.com/OpenListTeam/OpenList/internal/conf.BuiltAt=$(date +'%F %T %z')' \
        -X 'github.com/OpenListTeam/OpenList/internal/conf.GitAuthor=The OpenList Projects Contributors <noreply@openlist.team>' \
        -X 'github.com/OpenListTeam/OpenList/internal/conf.GitCommit=$(git log --pretty=format:"%h" -1)' \
        -X 'github.com/OpenListTeam/OpenList/internal/conf.Version=git-$(git rev-parse --short HEAD)' \
        -X 'github.com/OpenListTeam/OpenList/internal/conf.WebVersion=git-$(git rev-parse --short HEAD)'" \
        -tags=jsoniter .
}

package() {
    install -Dm755 openlist ${pkgdir}/usr/bin/openlist
    install -Dm644 openlist.service -t ${pkgdir}/usr/lib/systemd/system/
    install -Dm644 config.json -t ${pkgdir}/etc/openlist/
    install -Dm644 openlist.sysusers ${pkgdir}/usr/lib/sysusers.d/openlist.conf
    install -Dm644 openlist.tmpfiles ${pkgdir}/usr/lib/tmpfiles.d/openlist.conf
}