Add outdate detect logic for dist-<DISTRO-ID>

This commit is contained in:
clsty
2025-10-02 20:56:43 +08:00
parent 9f7a2d86cf
commit b380a77a7d
6 changed files with 68 additions and 20 deletions
+50 -10
View File
@@ -1,6 +1,32 @@
# This script is meant to be sourced.
# It's not for directly running.
function outdate_detect(){
# Shallow clone makes latest_commit_timestamp() not worky.
git_auto_unshallow
local source_path="$1"
local target_path="$2"
local source_timestamp="$(latest_commit_timestamp $source_path 2>/dev/null)"
local target_timestamp="$(latest_commit_timestamp $target_path 2>/dev/null)"
local outdate_detect_mode="$(cat ${target_path}/outdate-detect-mode)"
# Does target path have an outdate-detect-mode file which content is special?
if [[ "${outdate_detect_mode}" =~ ^(WIP|FORCE_OUTDATED|FORCE_UPDATED)$ ]]; then
echo "${outdate_detect_mode}"
# Does source path has an empty timestamp?
elif [ -z "$source_timestamp" ]; then
echo "EMPTY_SOURCE"
# Does target path has an empty timestamp?
elif [ -z "$target_timestamp" ]; then
echo "EMPTY_TARGET"
# If target path is older than source path, it's outdated.
elif [[ "$target_timestamp" -lt "$source_timestamp" ]]; then
echo "OUTDATED"
else
echo "UPDATED"
fi
}
####################
# Detect architecture
# Helpful link(s):
@@ -9,15 +35,15 @@ export MACHINE_ARCH=$(uname -m)
case $MACHINE_ARCH in
"x86_64") sleep 0;;
*)
printf "${STY_YELLOW}"
printf "===WARNING===\n"
printf "Detected machine architecture: ${MACHINE_ARCH}\n"
printf "This script only supports x86_64.\n"
printf "It is very likely to fail when installing dependencies on your machine.\n"
printf "\n"
printf "${STY_RESET}"
;;
esac
printf "${STY_YELLOW}"
printf "===WARNING===\n"
printf "Detected machine architecture: ${MACHINE_ARCH}\n"
printf "This script only supports x86_64.\n"
printf "It is very likely to fail when installing dependencies on your machine.\n"
printf "\n"
printf "${STY_RESET}"
;;
esac
####################
# Detect distro
@@ -31,7 +57,6 @@ export OS_DISTRO_ID=$(awk -F'=' '/^ID=/ { gsub("\"","",$2); print tolower($2) }'
export OS_DISTRO_ID_LIKE=$(awk -F'=' '/^ID_LIKE=/ { gsub("\"","",$2); print tolower($2) }' ${OS_RELEASE_FILE} 2> /dev/null)
if [[ "$INSTALL_VIA_NIX" == "true" ]]; then
TARGET_ID=nix
@@ -73,6 +98,21 @@ elif [[ -f "./dist-${OS_DISTRO_ID}/install-deps.sh" ]]; then
printf "\n"
printf "${STY_RESET}"
pause
tmp_update_status="$(outdate_detect dist-arch dist-${TARGET_ID})"
if [[ "${tmp_update_status}" =~ ^(OUTDATED|EMPTY_TARGET|EMPTY_SOURCE|FORCE_OUTDATED|WIP)$ ]]; then
printf "${STY_RED}"
printf "${STY_BOLD}===URGENT===${STY_RED}\n"
printf "The community provided ./dist-${TARGET_ID}/ is not updated (update status: ${tmp_update_status}),\n"
printf "which means it does not fully reflect the latest changes of ./dist-arch/ .\n"
printf "You are highly recommended to abort this script, until someone (maybe you?) has updated the ./dist-${TARGET_ID}/ to fully reflect the latest changes in ./dist-arch/ . PR is welcomed.\n"
printf "${STY_INVERT}If you are proceeding anyway, illogical-impulse will very likely not work as expected.${STY_RESET}\n"
printf "${STY_RED}Still proceed?${STY_RESET}\n"
read -p "[y/N]: " p
case "$p" in
[yY])sleep 0;;
*)echo "Aborting...";exit 1;;
esac
fi
source ./dist-${TARGET_ID}/install-deps.sh
elif [[ "$OS_DISTRO_ID_LIKE" == "arch" || "$OS_DISTRO_ID" == "cachyos" ]]; then