Integrity fixes: atomic writes, rc checks, curl

- Verified the repository backup rc in migrate.sh. `_persistent_backup_repos()` now aborts before any destructive step when the tar archive is missing or corrupt, removing the invalid backup itself.
- Verified the restore rc in migrate.sh. `_restore_backup()` now reports failure instead of printing a green "Backup restored" message, and its caller distinguishes a restored backup from a failed restore.
- Made the upgrade phases fail honestly. `apt upgrade` and `apt full-upgrade` now abort with `apt --fix-broken install` + `dpkg --configure -a` instructions instead of reporting "completed successfully" over a partially-upgraded system.
- Made repository source writes atomic. Both writers tee into a `.tmp` file and move into place, and the `/etc/apt/sources.list` removal now happens after the write.
- Corrected the SID warning text in migrate.sh to reflect that security fixes arrive via package uploads rather than a nonexistent sid-security suite.
- Added exit-path cleanup traps for the temp `.deb` files: `trap 'rm -f "$deb_path"' RETURN` in `heroic.sh`and `tools.sh`.
- Tightened Heroic download handling: the API fetch uses `curl -fsS --connect-timeout 10 --max-time 30`, the download uses `curl -fsSL --max-time 300`, and the `.deb` is validated with both `dpkg-deb --info` and `dpkg-deb --contents`; `sudo apt install` is guarded with `if !` before the temporary file is deleted.
- Tightened the OpenRGB install path: the Codeberg API fetch uses `curl -fsS --connect-timeout 10 --max-time 30` and the download `curl -fsSL --max-time 300`, with the same dual `dpkg-deb` integrity check as the Heroic fallback.
- Guarded the OpenRGB post-install side effects: the script now aborts after removing the failed `.deb` if `sudo apt install` returns non-zero, so `modprobe i2c-dev`, `/etc/modules`, the `i2c` group membership, `udevadm`, and the `setcap` step no longer run when the package is absent.
This commit is contained in:
stornic56
2026-10-04 23:39:40 -05:00
committed by GitHub
parent 454207209a
commit 21e9973c2f
22 changed files with 975 additions and 142 deletions
+17 -4
View File
@@ -4,12 +4,18 @@
install_heroic() {
local heroic_deb
heroic_deb=$(mktemp "${TMPDIR:-/tmp}/heroic-XXXXXX.deb") || return 1
# Remove the temp file on every exit path (RETURN
# traps are not inherited by called functions).
trap 'rm -f "$heroic_deb"' RETURN
local ua="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
_run_cmd "Heroic" "sudo apt install -y curl jq" "Installing dependencies..."
local json
json=$(curl -s --connect-timeout 10 -H "User-Agent: $ua" \
# -f: HTTP >= 400 must fail; --max-time bounds the
# whole transfer (connect-timeout only covers the
# connection phase).
json=$(curl -fsS --connect-timeout 10 --max-time 30 -H "User-Agent: $ua" \
"https://api.github.com/repos/Heroic-Games-Launcher/HeroicGamesLauncher/releases/latest") || {
_msg "Heroic Error" "Could not fetch release data from GitHub API." 8 60
return 1
@@ -28,16 +34,23 @@ install_heroic() {
# Strict URL validation before interpolating into a shell command (_run_cmd uses bash -c)
[[ "$deb_url" =~ ^https://[A-Za-z0-9./_-]+\.deb$ ]] || { _msg "Error" "Invalid download URL: $deb_url"; return 1; }
_run_cmd "Heroic" "curl -fsSL -H 'User-Agent: $ua' -o '$heroic_deb' '$deb_url'" "Downloading Heroic..."
_run_cmd "Heroic" "curl -fsSL --max-time 300 -H 'User-Agent: $ua' -o '$heroic_deb' '$deb_url'" "Downloading Heroic..."
if ! dpkg-deb --info "$heroic_deb" >/dev/null 2>&1; then
# --info reads only the control archive; --contents
# also walks the data archive, catching deb files
# truncated after the control section.
if ! dpkg-deb --info "$heroic_deb" >/dev/null 2>&1 || \
! dpkg-deb --contents "$heroic_deb" >/dev/null 2>&1; then
_msg "Heroic Error" "Downloaded .deb is corrupted or truncated.\n\nRemoving file." 10 60
rm -f "$heroic_deb"
return 1
fi
echo -e "${GREEN}Package integrity verified.${NC}"
_run_cmd "Heroic" "sudo apt install -y '$heroic_deb'" "Installing Heroic..."
if ! _run_cmd "Heroic" "sudo apt install -y '$heroic_deb'" "Installing Heroic..."; then
rm -f "$heroic_deb"
return 1
fi
rm -f "$heroic_deb"
echo -e "${GREEN}Heroic Games Launcher installed.${NC}"
}
+19 -4
View File
@@ -38,12 +38,16 @@ install_openrgb() {
local deb_path
deb_path=$(mktemp "${TMPDIR:-/tmp}/openrgb-XXXXXX.deb") || return 1
# Remove the temp file on every exit path.
trap 'rm -f "$deb_path"' RETURN
local ua="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
_run_cmd "OpenRGB" "sudo apt install -y curl jq" "Installing dependencies..."
local json=""
json=$(curl -s --connect-timeout 10 \
# -f: HTTP >= 400 must fail; --max-time bounds the
# whole transfer.
json=$(curl -fsS --connect-timeout 10 --max-time 30 \
"https://codeberg.org/api/v1/repos/OpenRGB/OpenRGB/releases?limit=1") || {
echo -e "${RED}Could not fetch OpenRGB releases from Codeberg API.${NC}"
return 1
@@ -66,7 +70,7 @@ install_openrgb() {
# Strict URL validation before interpolating into a shell command (_run_cmd uses bash -c)
[[ "$deb_url" =~ ^https://[A-Za-z0-9./_-]+\.deb$ ]] || { _msg "Error" "Invalid download URL: $deb_url"; return 1; }
_run_cmd "OpenRGB" "curl -fsSL -o '${deb_path}' -A '${ua}' '${deb_url}'" "Downloading OpenRGB..."
_run_cmd "OpenRGB" "curl -fsSL --max-time 300 -o '${deb_path}' -A '${ua}' '${deb_url}'" "Downloading OpenRGB..."
if [ -n "$sha256" ]; then
if ! echo "$sha256 $deb_path" | sha256sum -c --strict; then
@@ -76,7 +80,11 @@ install_openrgb() {
fi
echo -e "${GREEN}SHA256 verified.${NC}"
else
if ! dpkg-deb --info "$deb_path" >/dev/null 2>&1; then
# --contents also walks the data archive,
# catching deb files truncated after the
# control section.
if ! dpkg-deb --info "$deb_path" >/dev/null 2>&1 || \
! dpkg-deb --contents "$deb_path" >/dev/null 2>&1; then
echo -e "${RED}Downloaded .deb is corrupted. Removing.${NC}"
rm -f "$deb_path"
return 1
@@ -84,7 +92,14 @@ install_openrgb() {
echo -e "${YELLOW}No SHA256 in API, validated via dpkg-deb.${NC}"
fi
sudo apt install -y "$deb_path"
# The post-install steps (i2c group, udev rules)
# must only run if the package was actually
# installed; apt can fail on missing dependencies.
if ! sudo apt install -y "$deb_path"; then
rm -f "$deb_path"
echo -e "${RED}OpenRGB installation failed (dependency or dpkg error).${NC}"
return 1
fi
rm -f "$deb_path"
sudo modprobe i2c-dev