mirror of
https://github.com/stornic56/debianito-post-install.git
synced 2026-10-31 21:18:08 +00:00
9a96dff6ea
- 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.
191 lines
5.8 KiB
Bash
191 lines
5.8 KiB
Bash
#!/usr/bin/env bash
|
|
# zram.sh — ZRAM submenu: view, create/reconfigure, remove
|
|
|
|
zram_menu() {
|
|
# Hardware state is detected on demand; RAM_KB
|
|
# and RAM_SUMMARY are populated by the battery.
|
|
_ensure_state_detected
|
|
|
|
while true; do
|
|
local choice
|
|
choice=$(_menu "ZRAM Configuration" \
|
|
"Select an operation:" $TUI_ALTO $TUI_ANCHO 4 \
|
|
"1" "View ZRAM status" \
|
|
"2" "Create / Reconfigure ZRAM" \
|
|
"3" "Remove ZRAM" \
|
|
"4" "Back to main menu")
|
|
|
|
[ -z "$choice" ] && break
|
|
clear
|
|
|
|
case "$choice" in
|
|
1) _zram_view ;;
|
|
2) _zram_create ;;
|
|
3) _zram_remove ;;
|
|
4) break ;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
_zram_view() {
|
|
if ! is_installed "zram-tools"; then
|
|
_msg "ZRAM Status" "ZRAM is not installed.\n\nUse option 2 (Create / Reconfigure ZRAM)\nto set it up." 10 55
|
|
return
|
|
fi
|
|
|
|
local algo="" size="" priority=""
|
|
if [ -f /etc/default/zramswap ]; then
|
|
while IFS='=' read -r key val; do
|
|
case "$key" in
|
|
ALGO) algo=$val ;;
|
|
SIZE) size=$val ;;
|
|
PRIORITY) priority=$val ;;
|
|
esac
|
|
done </etc/default/zramswap
|
|
fi
|
|
|
|
local info="ZRAM Configuration:\n"
|
|
info+=" Algorithm: ${algo:-not set}\n"
|
|
info+=" Size: ${size:-not set} MB\n"
|
|
info+=" Priority: ${priority:-not set}\n\n"
|
|
info+="Active ZRAM devices:\n"
|
|
|
|
local zram_out
|
|
zram_out=$(sudo zramctl 2>/dev/null || true)
|
|
if [ -n "$zram_out" ]; then
|
|
info+="$zram_out"
|
|
else
|
|
info+=" (none — service may be stopped)"
|
|
fi
|
|
|
|
_msg "ZRAM Status" "$info" 16 70
|
|
}
|
|
|
|
_zram_create() {
|
|
if [ -z "$RAM_KB" ] || [ "$RAM_KB" -eq 0 ]; then
|
|
echo -e "${RED}Could not determine RAM size. Aborting.${NC}"
|
|
return 1
|
|
fi
|
|
|
|
if is_installed "zram-tools"; then
|
|
local cur_algo="" cur_size="" cur_prio=""
|
|
if [ -f /etc/default/zramswap ]; then
|
|
while IFS='=' read -r key val; do
|
|
case "$key" in
|
|
ALGO) cur_algo=$val ;;
|
|
SIZE) cur_size=$val ;;
|
|
PRIORITY) cur_prio=$val ;;
|
|
esac
|
|
done </etc/default/zramswap
|
|
fi
|
|
local cur="ZRAM is already configured:\n"
|
|
cur+=" Algorithm: ${cur_algo:-not set}\n"
|
|
cur+=" Size: ${cur_size:-not set} MB\n"
|
|
cur+=" Priority: ${cur_prio:-not set}\n\n"
|
|
cur+="Continuing will overwrite this configuration."
|
|
if ! _confirm "ZRAM — Reconfigure" "$cur"; then
|
|
echo "ZRAM reconfiguration cancelled."
|
|
return
|
|
fi
|
|
fi
|
|
|
|
local ram_gb=$((RAM_KB / 1024 / 1024))
|
|
if [ "$ram_gb" -gt 8 ]; then
|
|
recommended_mb=4096
|
|
else
|
|
recommended_mb=$((((RAM_KB / 1024 / 1024 + 1) / 2) * 1024))
|
|
fi
|
|
|
|
local algo
|
|
algo=$(_menu "ZRAM Configuration" \
|
|
"ZRAM creates a compressed swap device in RAM to reduce disk I/O and boost speed. Data is stored compressed in memory. Choose an algorithm below to balance CPU usage and compression ratio:" \
|
|
$TUI_ALTO $TUI_ANCHO $TUI_ALTO_LISTA \
|
|
"lz4" "Fastest compression. Lowest CPU overhead. (Default)" \
|
|
"zstd" "Higher compression ratio. Saves more RAM, uses more CPU.")
|
|
|
|
if [ -z "$algo" ]; then
|
|
echo "ZRAM configuration cancelled."
|
|
return
|
|
fi
|
|
|
|
local zram_size
|
|
if _confirm "ZRAM Size" "Use recommended size for ZRAM? (${recommended_mb} MB out of ${RAM_SUMMARY})"; then
|
|
zram_size=$recommended_mb
|
|
else
|
|
zram_size=$(_inputbox "ZRAM Size" "Enter ZRAM size in MB:" 8 60 "$recommended_mb")
|
|
if [ -z "$zram_size" ] || ! [[ "$zram_size" =~ ^[0-9]+$ ]] || [ "$zram_size" -eq 0 ]; then
|
|
echo "ZRAM configuration cancelled."
|
|
return
|
|
fi
|
|
fi
|
|
|
|
if ! _confirm "ZRAM Summary" "Algorithm: ${algo}\nSize: ${zram_size} MB\nPriority: 100\n\nApply?"; then
|
|
echo "ZRAM configuration cancelled."
|
|
return
|
|
fi
|
|
|
|
_run_cmd "ZRAM" "sudo apt install -y zram-tools" "Installing zram-tools..."
|
|
|
|
echo "Resetting existing ZRAM device..."
|
|
sudo swapoff /dev/zram0 2>/dev/null || true
|
|
sudo modprobe -r zram 2>/dev/null || true
|
|
|
|
echo "Writing configuration..."
|
|
# SECURITY: Validate algo and size before writing to system file.
|
|
[[ "$algo" =~ ^(lz4|zstd)$ ]] || {
|
|
echo "Invalid ZRAM algorithm" >&2
|
|
return 1
|
|
}
|
|
[[ "$zram_size" =~ ^[0-9]+$ ]] || {
|
|
echo "Invalid ZRAM size" >&2
|
|
return 1
|
|
}
|
|
sudo tee /etc/default/zramswap >/dev/null <<EOF
|
|
ALGO=$algo
|
|
SIZE=$zram_size
|
|
PRIORITY=100
|
|
EOF
|
|
|
|
echo "Restarting zramswap service..."
|
|
sudo systemctl restart zramswap
|
|
|
|
if ! grep -q "\[${algo}\]" /sys/block/zram0/comp_algorithm 2>/dev/null; then
|
|
echo -e "${YELLOW}Warning: ZRAM algorithm not applied yet. Reboot to finalize.${NC}"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${GREEN}ZRAM configured successfully.${NC}"
|
|
echo ""
|
|
sudo zramctl
|
|
echo ""
|
|
echo -e "${GREEN}You can verify with: sudo zramctl${NC}"
|
|
_pause
|
|
}
|
|
|
|
_zram_remove() {
|
|
if ! is_installed "zram-tools"; then
|
|
_msg "ZRAM Remove" "ZRAM is not installed.\n\nNothing to remove." 10 50
|
|
return
|
|
fi
|
|
|
|
if ! _confirm "Remove ZRAM" \
|
|
"This will:\n - Stop the zramswap service\n - Purge zram-tools\n - Remove /etc/default/zramswap\n\nProceed?"; then
|
|
echo "ZRAM removal cancelled."
|
|
return
|
|
fi
|
|
|
|
echo "Stopping zramswap service..."
|
|
sudo systemctl stop zramswap || true
|
|
|
|
echo "Releasing ZRAM device..."
|
|
sudo swapoff /dev/zram0 2>/dev/null || true
|
|
sudo modprobe -r zram 2>/dev/null || true
|
|
|
|
_run_cmd "ZRAM" "sudo apt purge -y zram-tools" "Purging zram-tools..."
|
|
|
|
echo "Removing configuration..."
|
|
sudo rm -f /etc/default/zramswap
|
|
|
|
_msg "ZRAM Removed" "ZRAM has been removed successfully.\n\nThe zramswap service is stopped and disabled." 10 55
|
|
}
|