Skip to content

Instantly share code, notes, and snippets.

@Bonveio
Last active August 9, 2026 13:07
Show Gist options
  • Select an option

  • Save Bonveio/99f7e54c99ee640ec898e66f601266c7 to your computer and use it in GitHub Desktop.

Select an option

Save Bonveio/99f7e54c99ee640ec898e66f601266c7 to your computer and use it in GitHub Desktop.
xray-bin AUR package PKGBUILD and .SRCINFO updater script to test latest Xray-core upstream releases early
#!/bin/bash
# Automatically update xray-bin PKGBUILD and .SRCINFO to the latest upstream release
# To use:
# $ rm -rf xray-bin # optional cmd
# $ git clone --branch xray-bin --single-branch --depth 1 https://github.com/archlinux/aur.git xray-bin
# $ cd xray-bin
# $ curl -kLO https://gist.githubusercontent.com/Bonveio/99f7e54c99ee640ec898e66f601266c7/raw/xray-bin-updater.sh
# $ bash xray-bin-updater.sh
# $ makepkg -si --noconfirm
set -euo pipefail
declare -A _archmap=(
['i686']='32'
['x86_64']='64'
['arm']='arm32-v7a'
['armv7h']='arm32-v7a'
['aarch64']='arm64-v8a'
['mips']='mips32'
['mipsel']='mips32le'
['mips64']='mips64'
['mips64el']='mips64le'
['ppc64']='ppc64'
['ppc64le']='ppc64le'
['riscv64']='riscv64'
['s390x']='s390x'
)
[[ ! -f PKGBUILD ]] && echo "ERROR: PKGBUILD not found. Run this script inside the xray-bin directory." >&2 && exit 1
for cmd in curl jq sed grep makepkg; do
if ! command -v "$cmd" >/dev/null; then
echo "ERROR: Required command '$cmd' is not installed." >&2
exit 1
fi
done
current_pkgver=$(grep -oP '^pkgver=\K.*' PKGBUILD)
echo "Current version: ${current_pkgver}"
block=$(sed -n '/^sha256sums_x86_64=/,/)/p' PKGBUILD)
config_sha256=$(echo "$block" | sed -n "2s/^[[:space:]]*'\([a-f0-9]\+\)'.*/\1/p")
service_sha256=$(echo "$block" | sed -n "3s/^[[:space:]]*'\([a-f0-9]\+\)'.*/\1/p")
sysusers_sha256=$(echo "$block" | sed -n "4s/^[[:space:]]*'\([a-f0-9]\+\)'.*/\1/p")
if [[ -z $config_sha256 || -z $service_sha256 || -z $sysusers_sha256 ]]; then
echo "ERROR: Could not extract fixed checksums from PKGBUILD." >&2
exit 1
fi
api_url="https://api.github.com/repos/XTLS/Xray-core/releases" # use github-based repo/forks
echo "Fetching latest release info from GitHub..."
# https://docs.github.com/en/rest/about-the-rest-api/api-versions
response=$(curl -sH "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2026-03-10" \
"$api_url")
latest_tag=$(echo "$response" | jq -r '.[0].tag_name')
latest_name=$(echo "$response" | jq -r '.[0].name')
prerelease=$(echo "$response" | jq -r '.[0].prerelease')
echo "Latest release: ${latest_tag} (${latest_name}) Prerelease: ${prerelease}"
new_pkgver="${latest_tag#v}"
if [[ "$new_pkgver" == "$current_pkgver" ]]; then
echo "Already up-to-date (version $current_pkgver). Nothing to do."
exit 0
fi
echo "Updating to version: ${new_pkgver}"
declare -A new_digest
allowed_src=("${_archmap[@]}")
allowed_json=$(printf '%s\n' "${allowed_src[@]}" | jq -R . | jq -s .)
# Parse assets: only Linux zip files for now, extract architecture and sha256 digest
while IFS='|' read -r download_url digest_hash; do
filename=$(basename "$download_url" .zip)
srcarch="${filename#Xray-linux-}"
# Set digest for ALL Arch Linux archs that map to this srcarch (no break)
for arch in "${!_archmap[@]}"; do
if [[ "${_archmap[$arch]}" == "$srcarch" ]]; then
new_digest[$arch]="$digest_hash"
fi
done
done < <(echo "$response" | jq --argjson allowed "$allowed_json" -r '
.[0].assets[]
| select(.name | endswith(".zip"))
| .name as $fname
| ($fname | ltrimstr("Xray-") | rtrimstr(".zip") | split("-")) as $parts
| select($parts[0] == "linux")
| ($parts[1:] | join("-")) as $arch
| select(any($allowed[]; . == $arch))
| select(.digest)
| [ .browser_download_url, (.digest | split(":")[1]) ]
| join("|")
')
# Verify we have digests for every architecture
missing=""
for arch in "${!_archmap[@]}"; do
if [[ -z ${new_digest[$arch]:-} ]]; then
missing+="$arch "
fi
done
if [[ -n $missing ]]; then
echo "ERROR: Missing binary digests for architectures: $missing" >&2
exit 1
fi
echo "Updating PKGBUILD..."
sed -i "s/^pkgver=.*/pkgver=${new_pkgver}/; s/^pkgrel=.*/pkgrel=1/" PKGBUILD
for arch in "${!_archmap[@]}"; do
new_sum="${new_digest[$arch]}"
sed -i "s/^\(sha256sums_${arch}=('\)[a-f0-9]\+/\1${new_sum}/" PKGBUILD
done
echo "PKGBUILD updated successfully."
echo "Regenerating .SRCINFO..."
makepkg --printsrcinfo >.SRCINFO
echo ".SRCINFO regenerated."
echo "Done. xray-bin is ready for version ${new_pkgver}."
echo "For casual users: run `makepkg -si --noconfirm`"
echo "For maintainer/s: Review the changes from PKGBUILD and .SRCINFO, then commit and push to AUR."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment