-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdeploy-aur.sh
More file actions
executable file
·375 lines (310 loc) · 10.9 KB
/
deploy-aur.sh
File metadata and controls
executable file
·375 lines (310 loc) · 10.9 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#!/usr/bin/env bash
# Script to automate AUR package deployment for term39
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Directories
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
AUR_SOURCE_DIR="${SCRIPT_DIR}/../aur-term39"
AUR_BIN_DIR="${SCRIPT_DIR}/../aur-term39-bin"
# Container settings
USE_CONTAINER=false
CONTAINER_CMD=""
BUILDER_IMAGE="term39-aur-builder"
PACMAN_CACHE_VOLUME="term39-pacman-cache"
# Function to print colored messages
info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to extract version from Cargo.toml
get_version() {
grep '^version = ' "${SCRIPT_DIR}/Cargo.toml" | head -n1 | sed 's/version = "\(.*\)"/\1/'
}
# Function to update PKGBUILD version
update_pkgbuild_version() {
local pkgbuild_file="$1"
local new_version="$2"
sed -i.bak "s/^pkgver=.*/pkgver=${new_version}/" "$pkgbuild_file"
sed -i.bak "s/^pkgrel=.*/pkgrel=1/" "$pkgbuild_file"
rm "${pkgbuild_file}.bak"
}
# Function to update checksums in PKGBUILD
update_checksum() {
local pkgbuild_file="$1"
local checksum_var="$2"
local new_checksum="$3"
sed -i.bak "s|^${checksum_var}=.*|${checksum_var}=('${new_checksum}')|" "$pkgbuild_file"
rm "${pkgbuild_file}.bak"
}
# Function to download file and calculate SHA256
download_and_hash() {
local url="$1"
local output_file="$2"
info "Downloading: $url" >&2
if curl -L -f -o "$output_file" "$url" 2>&1 | grep -v "^ " >&2; then
# Use shasum on macOS, sha256sum on Linux
if command -v sha256sum &> /dev/null; then
sha256sum "$output_file" | awk '{print $1}'
else
shasum -a 256 "$output_file" | awk '{print $1}'
fi
else
error "Failed to download $url" >&2
return 1
fi
}
# Function to detect container runtime
detect_container_runtime() {
if command -v podman &> /dev/null; then
echo "podman"
elif command -v docker &> /dev/null; then
echo "docker"
else
echo ""
fi
}
# Function to create or verify pacman cache volume
ensure_pacman_cache_volume() {
if ! $CONTAINER_CMD volume inspect "$PACMAN_CACHE_VOLUME" &> /dev/null; then
info "Creating pacman cache volume: $PACMAN_CACHE_VOLUME"
$CONTAINER_CMD volume create "$PACMAN_CACHE_VOLUME"
success "Pacman cache volume created"
else
info "Using existing pacman cache volume: $PACMAN_CACHE_VOLUME"
fi
}
# Function to build or verify builder image exists
ensure_builder_image() {
if ! $CONTAINER_CMD image inspect "$BUILDER_IMAGE" &> /dev/null; then
info "Building AUR builder image: $BUILDER_IMAGE"
info "This will take a moment but only happens once..."
# Create a temporary Containerfile/Dockerfile
local tmp_containerfile=$(mktemp)
cat > "$tmp_containerfile" <<'EOF'
FROM archlinux:latest
# Update system and install build dependencies
RUN pacman -Syu --noconfirm && \
pacman -S --noconfirm base-devel namcap && \
pacman -Scc --noconfirm
# Create builder user
RUN useradd -m -G wheel builder && \
echo "builder ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
# Set up builder user environment
USER builder
WORKDIR /home/builder
EOF
$CONTAINER_CMD build --platform linux/amd64 -t "$BUILDER_IMAGE" -f "$tmp_containerfile" . > /dev/null 2>&1
rm "$tmp_containerfile"
success "Builder image created: $BUILDER_IMAGE"
else
info "Using existing builder image: $BUILDER_IMAGE"
fi
}
# Function to run container with cache volume
run_with_cache() {
local cmd="$1"
# First fix permissions as root
$CONTAINER_CMD run --rm --platform linux/amd64 \
-v "$(pwd):/build" \
-v "${PACMAN_CACHE_VOLUME}:/var/cache/pacman/pkg" \
-w /build \
"$BUILDER_IMAGE" \
bash -c "chown -R builder:builder /build"
# Then run the actual command as builder user
$CONTAINER_CMD run --rm --platform linux/amd64 \
-v "$(pwd):/build" \
-v "${PACMAN_CACHE_VOLUME}:/var/cache/pacman/pkg" \
-w /build \
--user builder \
"$BUILDER_IMAGE" \
bash -c "$cmd"
}
# Function to test PKGBUILD validity
test_pkgbuild() {
local dir="$1"
local pkg_name=$(basename "$dir")
cd "$dir"
info "Testing PKGBUILD in $pkg_name"
if [[ "$USE_CONTAINER" == "true" ]]; then
info "Using container ($CONTAINER_CMD) to test PKGBUILD"
if run_with_cache 'namcap PKGBUILD'; then
success "PKGBUILD validation passed for $pkg_name"
return 0
else
warning "PKGBUILD validation had warnings for $pkg_name (may be okay)"
return 0
fi
else
if command -v namcap &> /dev/null; then
namcap PKGBUILD || warning "PKGBUILD validation had warnings (may be okay)"
else
warning "namcap not found - skipping PKGBUILD validation"
fi
fi
}
# Function to generate .SRCINFO
generate_srcinfo() {
local dir="$1"
local pkg_name=$(basename "$dir")
cd "$dir"
info "Generating .SRCINFO in $pkg_name"
if [[ "$USE_CONTAINER" == "true" ]]; then
info "Using container ($CONTAINER_CMD) to generate .SRCINFO"
run_with_cache 'makepkg --printsrcinfo' > .SRCINFO
else
makepkg --printsrcinfo > .SRCINFO
fi
}
# Function to commit and push AUR package
commit_and_push() {
local dir="$1"
local version="$2"
local pkg_name=$(basename "$dir")
cd "$dir"
info "Committing changes for $pkg_name"
git add PKGBUILD .SRCINFO
git commit -m "Update to version ${version}"
info "Pushing to AUR for $pkg_name"
git push
success "$pkg_name updated to version ${version}"
}
# Main script
main() {
info "Starting AUR deployment process"
# Detect if makepkg is available
if ! command -v makepkg &> /dev/null; then
warning "makepkg not found - attempting to use container runtime"
CONTAINER_CMD=$(detect_container_runtime)
if [[ -z "$CONTAINER_CMD" ]]; then
error "Neither makepkg nor container runtime (podman/docker) found!"
error "Please install podman or docker to continue."
exit 1
fi
USE_CONTAINER=true
success "Using $CONTAINER_CMD for makepkg operations"
# Set up container infrastructure
ensure_pacman_cache_volume
ensure_builder_image
else
info "Using native makepkg"
fi
# Check if directories exist
if [[ ! -d "$AUR_SOURCE_DIR" ]]; then
error "AUR source directory not found: $AUR_SOURCE_DIR"
exit 1
fi
if [[ ! -d "$AUR_BIN_DIR" ]]; then
error "AUR binary directory not found: $AUR_BIN_DIR"
exit 1
fi
# Get current version
VERSION=$(get_version)
info "Detected version: $VERSION"
# Confirm with user
echo ""
warning "This will update both AUR packages to version $VERSION"
read -p "Do you want to continue? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
info "Deployment cancelled"
exit 0
fi
# Create temporary directory for downloads
TMP_DIR=$(mktemp -d)
trap "rm -rf $TMP_DIR" EXIT
info "Using temporary directory: $TMP_DIR"
# ============================================================
# Update term39 (source package)
# ============================================================
info "Updating term39 (source package)..."
SOURCE_URL="https://github.com/alejandroqh/term39/archive/v${VERSION}.tar.gz"
SOURCE_FILE="${TMP_DIR}/term39-${VERSION}.tar.gz"
SOURCE_SHA=$(download_and_hash "$SOURCE_URL" "$SOURCE_FILE")
if [[ $? -ne 0 ]]; then
error "Failed to download source tarball. Make sure the GitHub release exists."
exit 1
fi
success "Source SHA256: $SOURCE_SHA" >&2
# Update PKGBUILD
update_pkgbuild_version "${AUR_SOURCE_DIR}/PKGBUILD" "$VERSION"
update_checksum "${AUR_SOURCE_DIR}/PKGBUILD" "sha256sums" "$SOURCE_SHA"
# Generate .SRCINFO (skipping validation for speed)
# test_pkgbuild "$AUR_SOURCE_DIR"
generate_srcinfo "$AUR_SOURCE_DIR"
# ============================================================
# Update term39-bin (binary package)
# ============================================================
info "Updating term39-bin (binary package)..."
# x86_64 binary
BIN_X64_URL="https://github.com/alejandroqh/term39/releases/download/v${VERSION}/term39-${VERSION}-linux-64bit-x86-binary.tar.gz"
BIN_X64_FILE="${TMP_DIR}/term39-x86_64.tar.gz"
BIN_X64_SHA=$(download_and_hash "$BIN_X64_URL" "$BIN_X64_FILE")
if [[ $? -ne 0 ]]; then
error "Failed to download x86_64 binary. Make sure the GitHub release exists."
exit 1
fi
success "x86_64 SHA256: $BIN_X64_SHA" >&2
# aarch64 binary
BIN_ARM64_URL="https://github.com/alejandroqh/term39/releases/download/v${VERSION}/term39-${VERSION}-linux-64bit-arm-binary.tar.gz"
BIN_ARM64_FILE="${TMP_DIR}/term39-arm64.tar.gz"
BIN_ARM64_SHA=$(download_and_hash "$BIN_ARM64_URL" "$BIN_ARM64_FILE")
if [[ $? -ne 0 ]]; then
error "Failed to download aarch64 binary. Make sure the GitHub release exists."
exit 1
fi
success "aarch64 SHA256: $BIN_ARM64_SHA" >&2
# Update PKGBUILD
update_pkgbuild_version "${AUR_BIN_DIR}/PKGBUILD" "$VERSION"
update_checksum "${AUR_BIN_DIR}/PKGBUILD" "sha256sums_x86_64" "$BIN_X64_SHA"
update_checksum "${AUR_BIN_DIR}/PKGBUILD" "sha256sums_aarch64" "$BIN_ARM64_SHA"
# Generate .SRCINFO (skipping validation for speed)
# test_pkgbuild "$AUR_BIN_DIR"
generate_srcinfo "$AUR_BIN_DIR"
# ============================================================
# Show changes and confirm push
# ============================================================
echo ""
info "Changes to be committed:"
echo ""
echo "=== term39 (source) ==="
cd "$AUR_SOURCE_DIR"
git diff PKGBUILD
echo ""
echo "=== term39-bin (binary) ==="
cd "$AUR_BIN_DIR"
git diff PKGBUILD
echo ""
warning "Ready to commit and push to AUR"
read -p "Do you want to commit and push? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
info "Changes made but not pushed. You can manually commit from the AUR directories."
exit 0
fi
# Commit and push
commit_and_push "$AUR_SOURCE_DIR" "$VERSION"
commit_and_push "$AUR_BIN_DIR" "$VERSION"
# ============================================================
# Done!
# ============================================================
echo ""
success "AUR deployment completed successfully!"
info "Packages updated:"
echo " - term39: https://aur.archlinux.org/packages/term39"
echo " - term39-bin: https://aur.archlinux.org/packages/term39-bin"
}
# Run main function
main "$@"