-
Notifications
You must be signed in to change notification settings - Fork 5
/
felixbuild
executable file
·116 lines (103 loc) · 3.61 KB
/
felixbuild
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
source /usr/share/makepkg/util/message.sh
colorize
# === Handle server & multiple logins ===
_buildserver=$1
# BUILDHOST shall not contain any numbers
BUILDHOST=${_buildserver//[0-9]/}
_login=${_buildserver//[a-zA-Z.@]/}
msg "Building on ${BUILDHOST##*@}"
shift
# === Deal with multiple logins (for parallel building) ===
if [[ -z "$_login" ]]; then
_cmd="$@"
else
_cmd=
_login="-l $USER$_login"
_mark=
for _part in "$@"; do
_cmd="$_cmd $_part"
if [[ -z "$_mark" && "$_part" == "--" ]]; then
_cmd="$_cmd $_login"
_mark=1
fi
done
if [[ -z "$_mark" ]]; then
_cmd="$_cmd -- $_login"
fi
fi
# === Sync package to remote host ===
# Prefer to use rsync here because it's much faster than source packages
# makepkg -Sf --skipchecksums --skippgpcheck || exit 1
# SRCPKG=$(ls *.src.tar.gz)
PKGNAME=$(source PKGBUILD; [[ -z $pkgbase ]] && echo $pkgname || echo $pkgbase)
ARCH=$(source PKGBUILD; echo $arch)
msg "Checking for remote environment..."
ssh $BUILDHOST "mkdir -p packages; test -e .makepkg.conf" || exit 1
msg "Syncing package to remote host..."
rsync -avzzP ./ $BUILDHOST:packages/$PKGNAME/ --exclude=*.src.tar* --exclude=*.pkg.tar* --exclude=src/ --exclude=pkg/ --exclude=.git/ || exit 1
# === Handle validpgpkeys ===
if [[ -n "$(. PKGBUILD; echo $validpgpkeys)" && ! "$_cmd" == *"--skippgpcheck"* ]]; then
msg "Ensuring required PGP keys are present..."
for _key in $(source PKGBUILD; echo "${validpgpkeys[@]}" 2>/dev/null); do
msg2 "Checking for $_key..."
if ! ssh $BUILDHOST "gpg --recv-keys $_key || gpg --fingerprint $_key"; then
if [[ -f keys/pgp/$_key.asc ]]; then
msg2 "Importing key from local..."
ssh $BUILDHOST "gpg --import packages/$PKGNAME/keys/pgp/$_key.asc"
else
error "Failed to locate key $_key"
exit 1
fi
fi
done
fi
# Try to fetch logs
fetch_logs() {
PKGPREFIX=$(source PKGBUILD; echo $PKGNAME-$epoch${epoch:+:}$pkgver-$pkgrel)
rsync -avzz $BUILDHOST:packages/$PKGNAME/$PKGPREFIX-*.log ./
}
trap fetch_logs EXIT
# === Handle riscv64 patches ===
if [[ "$1" =~ riscv ]]; then
. /usr/local/bin/riscvenv
if [[ -d "$RVPATCHREPO/$PKGNAME" ]]; then
msg "Applying RISC-V patches..."
rsync -avzzP $RVPATCHREPO/$PKGNAME/ $BUILDHOST:packages/$PKGNAME/ --exclude=*.src.tar* --exclude=*.pkg.tar* --exclude=src/ --exclude=pkg/ --exclude=.git/
if [[ -e "$RVPATCHREPO/$PKGNAME/riscv64.patch" ]]; then
ssh $BUILDHOST "cd packages/$PKGNAME && patch -p0 -i riscv64.patch" || exit 1
ARCH=$(ssh $BUILDHOST "cd packages/$PKGNAME; source PKGBUILD; echo \$arch")
fi
fi
if [[ ! "$ARCH" =~ any ]]; then
msg 'Patching arch to riscv64...'
ssh $BUILDHOST "echo -e '\narch=(riscv64)' >> packages/$PKGNAME/PKGBUILD" || exit 1
fi
# Handle cachedir
_HOME="$(ssh $BUILDHOST 'mkdir -p $HOME/packages/riscv64-pkg-cache; echo $HOME')"
_oldcmd="$_cmd"
_cmd=
_cachedir="-d $_HOME/packages/riscv64-pkg-cache:/var/cache/pacman/pkg"
_mark=
for _part in $_oldcmd; do
_cmd="$_cmd $_part"
if [[ -z "$_mark" && "$_part" == "--" ]]; then
_cmd="$_cmd $_cachedir"
_mark=1
fi
done
if [[ -z "$_mark" ]]; then
_cmd="$_cmd -- $_cachedir"
fi
fi
# === Build the package ===
msg "Running $_cmd on remote host..."
ssh -tt $BUILDHOST "cd packages/$PKGNAME && rm -f *.pkg.tar.*; $_cmd" || exit 1
# === Sync back artifacts ===
msg "Syncing back built packages..."
rsync -avzzP $BUILDHOST:packages/$PKGNAME/*.pkg.tar.* ./ || exit 1
# === Sync back PKGBUILD ===
if [[ -n "$SYNCBACKPKGBUILD" ]]; then
msg "Syncing back PKGBUILD..."
rsync -avzzP $BUILDHOST:packages/$PKGNAME/PKGBUILD ./ || exit 1
fi