mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
fix(onboarding): a smoother first run, from the child-process setting to the Steam sign-in (#3114)
The child-process fix always uses the guided pairing flow, Finish setup opens the setting directly and queues the Steam launch, the Play button carries the first-run progress, the setup bar weighs each download by its real size, and the Steam client packages download over four connections and unpack one at a time under a flock.
This commit is contained in:
1 parent
46ec222fa5
commit
39debda0b0
67 files changed
+1151
-2078
No files matched your search
@@ -132,6 +132,138 @@ fetch() {
|
||||
done
|
||||
}
|
||||
|
||||
# The same decisions as fetch for the parallel workers, with curl in the foreground and a plain sleep between tries:
|
||||
# the shell here cannot open /dev/fd for process substitution from a background job.
|
||||
fetch_one() {
|
||||
local url=$1 dest=$2 size=$3 sum=$4 part=$5 failures=0 bad=0 finished=0 before rc http wait
|
||||
while :; do
|
||||
if [ -f "$dest" ] && { [ "$finished" = 1 ] || { [ "$size" -gt 0 ] && [ "$(size_of "$dest")" -ge "$size" ]; }; }; then
|
||||
echo "$sum $dest" | sha256sum -c --quiet 2>/dev/null && return 0
|
||||
rm -f "$dest"
|
||||
finished=0 bad=$((bad + 1))
|
||||
[ "$bad" -lt 3 ] || { echo "droiddeck-steam-install: $part does not match its checksum" >&2; return 1; }
|
||||
fi
|
||||
before=$(size_of "$dest")
|
||||
http=$(curl -fsSL "${limits[@]}" -w '%{http_code}' -C - -o "$dest" "$url") && rc=0 || rc=$?
|
||||
if [ "$rc" = 0 ]; then finished=1; continue; fi
|
||||
case "$rc:${http:-}" in
|
||||
22:416 | 33:*) rm -f "$dest" ;;
|
||||
22:4??)
|
||||
echo "droiddeck-steam-install: $part: HTTP $http from ${url%/*}" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
if [ "$(size_of "$dest")" -gt "$before" ]; then failures=0; else failures=$((failures + 1)); fi
|
||||
if [ "$failures" -gt "${#delays[@]}" ]; then
|
||||
echo "droiddeck-steam-install: could not download $part (curl exit $rc); what arrived is kept for the next try" >&2
|
||||
return 1
|
||||
fi
|
||||
wait=${delays[$((failures > 0 ? failures - 1 : 0))]}
|
||||
step "downloading Steam: $part - interrupted (curl exit $rc), trying again in ${wait} s"
|
||||
sleep "$wait"
|
||||
done
|
||||
}
|
||||
|
||||
parallel=${DD_STEAM_PARALLEL:-4}
|
||||
case $parallel in ''|*[!0-9]*|0) parallel=1 ;; esac
|
||||
flock_command=${DD_STEAM_FLOCK:-flock}
|
||||
command -v "$flock_command" > /dev/null 2>&1 || parallel=1
|
||||
|
||||
# unzip creates parent directories without guarding against another unzip doing the same, so two packages unpacked into
|
||||
# one tree at once fail now and then. Unpacking is quick next to downloading, so the workers take turns on a flock: the
|
||||
# kernel hands it on when its holder ends, however it ends, so there is no stale lock to recover.
|
||||
unzip_alone() {
|
||||
local rc
|
||||
( "$flock_command" 9 && unzip -qo "$1" -d "$steam_root" ) 9> "$state/unzip.lock" && rc=0 || rc=$?
|
||||
return $rc
|
||||
}
|
||||
|
||||
# Fetches every line of a list ("block file sum size") into $dir with up to $parallel connections. With a third
|
||||
# argument each package is also unpacked into the client as it lands. One connection tops out near half of what a
|
||||
# Wi-Fi link carries, so the packages arrive about twice as fast. Workers take the next unclaimed line themselves
|
||||
# (mkdir is atomic) and only plain background jobs and wait on a pid are used, so nothing depends on job control.
|
||||
run_parallel() {
|
||||
local list=$1 dir=$2 unpack=${3:-} state index=0 block file sum size
|
||||
local -a blocks=() files=() sums=() sizes=() pids=()
|
||||
state=$work/parallel
|
||||
rm -rf "$state"
|
||||
mkdir -p "$state"
|
||||
while read -r block file sum size; do
|
||||
index=$((index + 1))
|
||||
blocks[index]=$block files[index]=$file sums[index]=$sum sizes[index]=$size
|
||||
if [ -n "$unpack" ] && [ -f "$dir/$file.unpacked" ]; then
|
||||
: > "$state/$index.done"
|
||||
: > "$state/claim.$index"
|
||||
fi
|
||||
done < "$list"
|
||||
local count=$index total_bytes=0
|
||||
for index in $(seq 1 "$count"); do total_bytes=$((total_bytes + sizes[index])); done
|
||||
local slot
|
||||
for slot in $(seq 1 "$parallel"); do
|
||||
(
|
||||
trap ': > "$state/exit.$slot"' EXIT
|
||||
while [ ! -e "$state/failed" ]; do
|
||||
index=0
|
||||
for n in $(seq 1 "$count"); do
|
||||
if mkdir "$state/claim.$n" 2>/dev/null; then index=$n; break; fi
|
||||
done
|
||||
[ "$index" -gt 0 ] || exit 0
|
||||
file=${files[index]}
|
||||
fetched=""
|
||||
for host in "${cdn_order[@]}"; do
|
||||
if fetch_one "$host/$file" "$dir/$file" "${sizes[index]}" "${sums[index]}" "${blocks[index]}"; then
|
||||
fetched=$host
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z "$fetched" ]; then
|
||||
echo "droiddeck-steam-install: $file failed on every CDN" >&2
|
||||
: > "$state/failed"
|
||||
exit 1
|
||||
fi
|
||||
if [ -n "$unpack" ]; then
|
||||
unzip_alone "$dir/$file" || { : > "$state/failed"; exit 1; }
|
||||
: > "$dir/$file.unpacked"
|
||||
rm -f "$dir/$file"
|
||||
fi
|
||||
: > "$state/$index.done"
|
||||
done
|
||||
) &
|
||||
pids+=($!)
|
||||
done
|
||||
local shown="" got n alive mark current last="" since=$SECONDS stall=${DD_STEAM_STALL:-90}
|
||||
while :; do
|
||||
alive=0
|
||||
for slot in $(seq 1 "$parallel"); do [ -e "$state/exit.$slot" ] || alive=1; done
|
||||
got=0 n=0 current=""
|
||||
for index in $(seq 1 "$count"); do
|
||||
if [ -e "$state/$index.done" ]; then
|
||||
got=$((got + sizes[index])) n=$((n + 1))
|
||||
elif [ -e "$state/claim.$index" ]; then
|
||||
current=$index
|
||||
[ -f "$dir/${files[index]}" ] && got=$((got + $(size_of "$dir/${files[index]}")))
|
||||
fi
|
||||
done
|
||||
mark=$((got / 1000000))
|
||||
if [ -n "$current" ] && [ "$mark" != "$shown" ]; then
|
||||
shown=$mark
|
||||
step "downloading Steam: ${blocks[current]} ($((n + 1))/$count), $mark of $((total_bytes / 1000000)) MB"
|
||||
fi
|
||||
[ "$n" -lt "$count" ] || alive=0
|
||||
if [ "$got" != "$last" ]; then last=$got since=$SECONDS; fi
|
||||
# A worker killed from outside never writes its exit marker. Stop reporting once nothing has moved for a while
|
||||
# and wait on the workers: wait returns the killed one's status, so the install fails instead of hanging.
|
||||
[ $((SECONDS - since)) -lt "$stall" ] || alive=0
|
||||
[ "$alive" = 1 ] || break
|
||||
sleep 1
|
||||
done
|
||||
local failed=""
|
||||
for slot in "${pids[@]}"; do wait "$slot" || failed=1; done
|
||||
[ ! -e "$state/failed" ] || failed=1
|
||||
rm -rf "$state"
|
||||
[ -z "$failed" ]
|
||||
}
|
||||
|
||||
fetch_manifest() {
|
||||
cdn=""
|
||||
for candidate in $cdn_list; do
|
||||
@@ -193,6 +325,9 @@ if [ -n "$cache_only" ]; then
|
||||
total_bytes=$(awk '{ n += $4 } END { print n + 0 }' "$work/cache")
|
||||
done_bytes=0
|
||||
i=0
|
||||
if [ "$parallel" -gt 1 ]; then
|
||||
run_parallel "$work/cache" "$cache" || exit 1
|
||||
else
|
||||
while read -r block file sum size; do
|
||||
i=$((i + 1))
|
||||
progress "$cache/$file" "$block"
|
||||
@@ -206,6 +341,7 @@ if [ -n "$cache_only" ]; then
|
||||
[ -n "$fetched" ] || { echo "droiddeck-steam-install: $file failed on every CDN" >&2; exit 1; }
|
||||
done_bytes=$((done_bytes + size))
|
||||
done < "$work/cache"
|
||||
fi
|
||||
echo "$version" > "$cached"
|
||||
exit 0
|
||||
fi
|
||||
@@ -228,6 +364,9 @@ for left in "$parts"/*; do
|
||||
grep -qF " $name " "$work/parts" || rm -rf "$left"
|
||||
done
|
||||
done_bytes=0
|
||||
if [ "$parallel" -gt 1 ]; then
|
||||
run_parallel "$work/parts" "$parts" unpack || exit 1
|
||||
else
|
||||
while read -r block file sum size; do
|
||||
i=$((${i:-0} + 1))
|
||||
if [ -f "$parts/$file.unpacked" ]; then
|
||||
@@ -248,6 +387,7 @@ while read -r block file sum size; do
|
||||
rm -f "$parts/$file"
|
||||
done_bytes=$((done_bytes + size))
|
||||
done < "$work/parts"
|
||||
fi
|
||||
find "$steam_root" -depth -name '*\\*' | while read -r odd; do
|
||||
fixed=${odd//\\//}
|
||||
mkdir -p "$(dirname "$fixed")"
|
||||
|
||||
Reference in new issue
Block a user