Files
snigdhaos-pkgbuilds/common/snigdhaos-updater/core-script

80 lines
3.1 KiB
Bash

#!/bin/bash
set -e
init_logging(){
if [ ! -d /var/log/snigdhaos/ ]; then
mkdir -p -m 755 /var/log/snigdhaos/
fi
echo -e "\n>-<->-< snigdhaos-updater at $(date +"%Y-%m-%d %R %Z(%:::z)")\n" >>/var/log/snigdhaos/snigdhaos-updater
exec &> >(stdbuf -i0 -o0 -e0 tee >(sed '')) #incshx002
}
parse_pacman_log(){
sed -i -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g" "$AUTOPACMAN_LOG"
local reason
reason="$(tac "$AUTOPACMAN_LOG" | grep -oP -m 1 '(?<=error: failed to commit transaction \().*(?=\))')"
case "$reason" in
"invalid or corrupted package"*)
RETRY="Snigdha OS Updater Found Corrupted Packages😑. Retying..."
CUSTOM_PACMAN_CONFIG="$(mktemp)"
sed 's|Include = /etc/pacman.d/chaotic-mirrorlist|Server = https://cdn-mirror.chaotic.cx/$repo/$arch|g' /etc/pacman.conf > "$CUSTOM_PACMAN_CONFIG"
pacman_args+=("--config" "$CUSTOM_PACMAN_CONFIG")
;;
"download library error")
RETRY="Snigdha OS Updater Found Corrupted Packages😑. Retying..."
CUSTOM_PACMAN_CONFIG="$(mktemp)"
sed '/^ParallelDownloads.*/d' /etc/pacman.conf >"$CUSTOM_PACMAN_CONFIG"
pacman_args+=("--config" "$CUSTOM_PACMAN_CONFIG")
;;
"conflicting files")
tac "$AUTOPACMAN_LOG" | gawk 'BEGIN { exitcode=1 }
/error: failed to commit transaction \(conflicting files\)/ { exit exitcode }
/\S+: (.*) exists in filesystem/ { if ($0 ~ /\S+:\/usr\/lib\/python[^\/]+\/site-packages\/[^/]+\/__pycache__\/.+\.pyc exists in filesystem/) { exitcode=0 } else { exit 1 } }
ENDFILE {exit 1}' && pacman_args+=("--overwrite" "/usr/lib/python*/site-packages/*/__pycache__/*.pyc") && RETRY="Overwriting Pycache file conflicts..." || true
;;
esac
}
update_mirrorlist(){
if [[ -v SKIP_MIRRORLIST ]]; then
return
fi
local MIRRORLIST_TEMP MINLINES=0
MIRRORLIST_TEMP="$(mktemp)"
# Rate-Mirrors
if command -v rate-mirrors >/dev/null; then
MINLINES=10
echo -e "\n\033[0;96m=>\033[0;96m [Rate-Mirrors]Refreshing Mirrorlist...🛸\033[0m"
rate-mirrors --allow-root --save="$MIRRORLIST_TEMP" arch --max-delay=21600 >/dev/null || { rm "$MIRRORLIST_TEMP"; }
$INT
# Reflector
elif command -v reflector >/dev/null; then
MINLINES=5
echo -e "\n\033[0;96m=>\033[0;96m [Reflector]Refreshing Mirrorlist...🛸\033[0m"
reflector --latest 10 --age 2 --fastest 10 --protocol https --sort rate --save "$MIRRORLIST_TEMP" || { rm "$MIRRORLIST_TEMP"; }
$INT
else
return
fi
# What if we are not using rate-mirrors and reflector?
if [ ! -f "$MIRRORLIST_TEMP" ]; then
echo -e "\033[0;91mMirrorlist Update Failed!\033[0m"
return
fi
if COUNT="$(grep -Ec "^Server *=" "$MIRRORLIST_TEMP")" && [ "$COUNT" -ge "$MINLINES" ]; then
install -m644 "$MIRRORLIST_TEMP" /etc/pacman.d/mirrorlist
DATABASE_UPDATED="force"
else
echo -e "\033[0;31Mirror Count Not Satisfied!\033[0m"
fi
echo
rm "$MIRRORLIST_TEMP"
}
do_update(){
}