Repository navigation
Expand file tree
/
Copy pathupdate-pkgver
More file actions
executable file
·99 lines (86 loc) · 5.11 KB
/
Copy pathupdate-pkgver
File metadata and controls
executable file
·99 lines (86 loc) · 5.11 KB
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
94
95
96
97
98
99
#!/usr/bin/env bash
# Copyright (C) 2026 CharOfString <root@charofstring.cc>
#
# 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 <https://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
# 本脚本从debian/changelog中读取版本并且更新PKGBUILD的版本
# This script reads version from debian/changelog and update the version of
# PKGBUILD.
set -euo pipefail
cd arch
# 引用/Works Cited: https://patorjk.com/software/taag/#p=display&f=Linguaholic+Shadow+3D
echo ' ██████╗██╗ ██╗██████╗ ████████╗ ████╗ '
echo '██╔═════╝╚═██╗ ██╔═╝██╔═══██╗██╔═════╝ ██╔═══╝ ████╗ ██╗ ████╗ '
echo '██║ ████╗ ╚═██╔═╝ ██║ ██║██████╗ ██████╗ ██╔═══██╗████╔═══╝ '
echo '██║ ╚═██║ ██╔═██╗ ██║ ██║██╔═══╝ ╚═██╔═╝ ██║ ██║██╔═╝ '
echo '╚═██████║██╔═╝ ╚═██╗██████╔═╝████████╗ ██║ ╚═████╔═╝██║ '
echo ' ╚═════╝╚═╝ ╚═╝╚═════╝ ╚═══════╝ ╚═╝ ╚═══╝ ╚═╝ '
echo ' '
echo ' '
echo ' ████╗ ██╗ ██╗ ██╗ '
echo '██╔═══██╗██╗ ████╗ ██████╗██████╗ ██║ ╚═╝██████╗ ██╗ ██╗██╗ ██╗'
echo '████████║████╔═══╝██╔═════╝██╔═══██╗██║ ██╗██╔═══██╗██║ ██║╚═████╔═╝'
echo '██╔═══██║██╔═╝ ██║ ██║ ██║██║ ██║██║ ██║██║ ██║ ████║ '
echo '██║ ██║██║ ╚═██████╗██║ ██║████████╗██║██║ ██║╚═██████║██╔═══██╗'
echo '╚═╝ ╚═╝╚═╝ ╚═════╝╚═╝ ╚═╝╚═══════╝╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝'
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
repo_dir=$(dirname "$script_dir")
pkgbuild="$script_dir/PKGBUILD"
changelog="$repo_dir/debian/changelog"
usage() {
sed -n '2,8p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'
exit "${1:-0}"
}
pkgrel=
version=
while (($#)); do
case "$1" in
-r|--pkgrel) pkgrel=${2:?missing value for $1}; shift 2 ;;
-h|--help) usage ;;
-*) echo "unknown option: $1" >&2; usage 1 ;;
*) version=$1; shift ;;
esac
done
if [[ -z $version ]]; then
# First line of debian/changelog: "dtkcommon (5.7.16-2) unstable; urgency=medium"
version=$(sed -nE '1s/^[^ ]+ \(([^)]+)\).*/\1/p' "$changelog")
[[ -n $version ]] || { echo "cannot parse version from $changelog" >&2; exit 1; }
echo "version from debian/changelog: $version"
fi
# Debian "epoch:upstream-revision" -> Arch pkgver/pkgrel
version=${version#*:}
if [[ $version == *-* ]]; then
upstream=${version%-*}
revision=${version##*-}
else
upstream=$version
revision=
fi
# pkgver must not contain ':', '/', '-' or whitespace
pkgver=$(tr '~+:/ -' '......' <<<"$upstream")
if [[ -z $pkgrel ]]; then
# Debian revisions like "2deepin1" -> keep the leading number only
pkgrel=$(grep -oE '^[0-9]+' <<<"$revision" || true)
pkgrel=${pkgrel:-1}
fi
[[ $pkgver =~ ^[0-9][0-9A-Za-z._]*$ ]] || { echo "invalid pkgver: $pkgver" >&2; exit 1; }
[[ $pkgrel =~ ^[1-9][0-9]*(\.[1-9][0-9]*)?$ ]] || { echo "invalid pkgrel: $pkgrel" >&2; exit 1; }
old=$(grep -E '^pkg(ver|rel)=' "$pkgbuild" | paste -sd' ')
sed -i -E "s/^pkgver=.*/pkgver=$pkgver/; s/^pkgrel=.*/pkgrel=$pkgrel/" "$pkgbuild"
echo "$old -> pkgver=$pkgver pkgrel=$pkgrel"
bash -n "$pkgbuild"
if command -v makepkg >/dev/null; then
(cd "$script_dir" && makepkg --printsrcinfo >/dev/null)
echo "PKGBUILD OK"
fi