Free, open-source screen sharing for private live streams with friends. Watch together in a browser or self-host Piik. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。
#!/bin/bash
set -euo pipefail
repo_root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
release_script="$repo_root/deploy/release-server.sh"
extract_function() {
awk -v name="$1" '
$0 == name "() {" { capture = 1 }
capture { print }
capture && $0 == "}" { exit }
' "$release_script"
}
eval "$(extract_function cleanup_stage)"
if grep -q '^cleanup_release() {' "$release_script"; then
eval "$(extract_function cleanup_release)"
fi
eval "$(extract_function wait_for_health)"
eval "$(extract_function recover)"
eval "$(extract_function validate_artifact_names)"
# Reject the other architecture before any deployment state is touched.
(
release_id='abcdef0'
uname() { printf '%s\n' "$architecture"; }
for architecture in x86_64 aarch64 arm64; do
for suffix in '' '-linux-arm64'; do
artifact_name="piik-${release_id}${suffix}-runtime.tar.gz"
manifest_name="piik-${release_id}${suffix}.manifest.tsv"
if { [ "$architecture" = x86_64 ] && [ -z "$suffix" ]; } ||
{ [ "$architecture" != x86_64 ] && [ -n "$suffix" ]; }; then
validate_artifact_names
elif validate_artifact_names; then
printf 'accepted the wrong Server architecture\n' >&2; exit 1
fi
done
done
architecture='riscv64'
if validate_artifact_names; then exit 1; fi
)
test_root="$(mktemp -d)"
trap 'command rm -rf -- "$test_root"' EXIT
# macOS temporary paths may contain symlinks; compare physical paths below.
test_root="$(cd -- "$test_root" && pwd -P)"
release_root="$test_root/releases"
current="$test_root/current"
release_id='abcdef0'
old_release="$release_root/old"
release="$release_root/$release_id"
stage=''
mkdir -p "$old_release"
systemctl_start_fails=0
rm_release_fails=0
systemctl() {
if [ "${1:-}" = 'start' ] && [ "$systemctl_start_fails" -eq 1 ]; then
return 1
fi
if [ "${1:-}" = 'show' ]; then
printf 'active\n'
fi
return 0
}
wait_for_health() { return 0; }
rm() {
local path="${!#}"
if [ "$rm_release_fails" -eq 1 ] && [ "$path" = "$release" ]; then
return 1
fi
# The fixture owns only temporary files, with no nested mounts. Keep the
# production GNU safety flag in release-server.sh, not in the host's rm.
local arg
local args=()
for arg in "$@"; do
if [ "$arg" != '--one-file-system' ]; then args+=("$arg"); fi
done
command rm "${args[@]}"
}
realpath() {
# Recovery resolves existing directories here; BSD realpath has no -m.
(cd -- "${!#}" && pwd -P)
}
readlink() {
local path="${!#}"
if [ "$path" = "$current" ] && [ -f "$current" ]; then
cat "$current"
return
fi
command readlink "$@"
}
ln() {
if [ "${1:-}" = '-s' ]; then
printf '%s\n' "$2" > "$3"
return
fi
command ln "$@"
}
mv() {
if [ "${1:-}" = '-Tf' ]; then
command mv -f -- "$2" "$3"
return
fi
command mv "$@"
}
set_current() {
printf '%s\n' "$1" > "$current"
}
reset_release() {
rm -rf -- "$release"
rm -rf -- "$current"
mkdir -p "$release"
set_current "$old_release"
stage=''
cutover_started=0
systemctl_start_fails=0
}
run_recover() {
local expected="$1" code
set +e
(recover 37) >/dev/null 2>&1
code=$?
set -e
test "$code" -eq "$expected"
}
reset_release
release_owned=1
ln -s "$release" "${current}.${release_id}-$$"
run_recover 37
test ! -e "$release"
test ! -e "${current}.${release_id}-$$"
reset_release
release_owned=0
run_recover 37
test -d "$release"
reset_release
release_owned=1
rm_release_fails=1
run_recover 90
test -d "$release"
rm_release_fails=0
reset_release
release_owned=1
cutover_started=1
set_current "$release"
run_recover 37
test "$(readlink -f -- "$current")" = "$old_release"
test ! -e "$release"
reset_release
release_owned=1
cutover_started=1
systemctl_start_fails=1
set_current "$release"
run_recover 90
test -d "$release"