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
+1
View File
@@ -0,0 +1 @@
AUTO
+1
View File
@@ -0,0 +1 @@
WIP
+1
View File
@@ -0,0 +1 @@
WIP
+50 -10
View File
@@ -1,6 +1,32 @@
# This script is meant to be sourced. # This script is meant to be sourced.
# It's not for directly running. # 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 # Detect architecture
# Helpful link(s): # Helpful link(s):
@@ -9,15 +35,15 @@ export MACHINE_ARCH=$(uname -m)
case $MACHINE_ARCH in case $MACHINE_ARCH in
"x86_64") sleep 0;; "x86_64") sleep 0;;
*) *)
printf "${STY_YELLOW}" printf "${STY_YELLOW}"
printf "===WARNING===\n" printf "===WARNING===\n"
printf "Detected machine architecture: ${MACHINE_ARCH}\n" printf "Detected machine architecture: ${MACHINE_ARCH}\n"
printf "This script only supports x86_64.\n" printf "This script only supports x86_64.\n"
printf "It is very likely to fail when installing dependencies on your machine.\n" printf "It is very likely to fail when installing dependencies on your machine.\n"
printf "\n" printf "\n"
printf "${STY_RESET}" printf "${STY_RESET}"
;; ;;
esac esac
#################### ####################
# Detect distro # 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) 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 if [[ "$INSTALL_VIA_NIX" == "true" ]]; then
TARGET_ID=nix TARGET_ID=nix
@@ -73,6 +98,21 @@ elif [[ -f "./dist-${OS_DISTRO_ID}/install-deps.sh" ]]; then
printf "\n" printf "\n"
printf "${STY_RESET}" printf "${STY_RESET}"
pause 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 source ./dist-${TARGET_ID}/install-deps.sh
elif [[ "$OS_DISTRO_ID_LIKE" == "arch" || "$OS_DISTRO_ID" == "cachyos" ]]; then elif [[ "$OS_DISTRO_ID_LIKE" == "arch" || "$OS_DISTRO_ID" == "cachyos" ]]; then
+14 -9
View File
@@ -10,7 +10,7 @@ function v(){
echo -e "####################################################" echo -e "####################################################"
echo -e "${STY_BLUE}[$0]: Next command:${STY_RESET}" echo -e "${STY_BLUE}[$0]: Next command:${STY_RESET}"
echo -e "${STY_GREEN}$@${STY_RESET}" echo -e "${STY_GREEN}$@${STY_RESET}"
execute=true local execute=true
if $ask;then if $ask;then
while true;do while true;do
echo -e "${STY_BLUE}Execute? ${STY_RESET}" echo -e "${STY_BLUE}Execute? ${STY_RESET}"
@@ -18,7 +18,7 @@ function v(){
echo " e = Exit now" echo " e = Exit now"
echo " s = Skip this command (NOT recommended - your setup might not work correctly)" echo " s = Skip this command (NOT recommended - your setup might not work correctly)"
echo " yesforall = Yes and don't ask again; NOT recommended unless you really sure" echo " yesforall = Yes and don't ask again; NOT recommended unless you really sure"
read -p "====> " p local p; read -p "====> " p
case $p in case $p in
[yY]) echo -e "${STY_BLUE}OK, executing...${STY_RESET}" ;break ;; [yY]) echo -e "${STY_BLUE}OK, executing...${STY_RESET}" ;break ;;
[eE]) echo -e "${STY_BLUE}Exiting...${STY_RESET}" ;exit ;break ;; [eE]) echo -e "${STY_BLUE}Exiting...${STY_RESET}" ;exit ;break ;;
@@ -34,7 +34,7 @@ function v(){
} }
# When use v() for a defined function, use x() INSIDE its definition to catch errors. # When use v() for a defined function, use x() INSIDE its definition to catch errors.
function x(){ function x(){
if "$@";then cmdstatus=0;else cmdstatus=1;fi # 0=normal; 1=failed; 2=failed but ignored if "$@";then local cmdstatus=0;else local cmdstatus=1;fi # 0=normal; 1=failed; 2=failed but ignored
while [ $cmdstatus == 1 ] ;do while [ $cmdstatus == 1 ] ;do
echo -e "${STY_RED}[$0]: Command \"${STY_GREEN}$@${STY_RED}\" has failed." echo -e "${STY_RED}[$0]: Command \"${STY_GREEN}$@${STY_RED}\" has failed."
echo -e "You may need to resolve the problem manually BEFORE repeating this command." echo -e "You may need to resolve the problem manually BEFORE repeating this command."
@@ -42,7 +42,7 @@ function x(){
echo " r = Repeat this command (DEFAULT)" echo " r = Repeat this command (DEFAULT)"
echo " e = Exit now" echo " e = Exit now"
echo " i = Ignore this error and continue (your setup might not work correctly)" echo " i = Ignore this error and continue (your setup might not work correctly)"
read -p " [R/e/i]: " p local p; read -p " [R/e/i]: " p
case $p in case $p in
[iI]) echo -e "${STY_BLUE}Alright, ignore and continue...${STY_RESET}";cmdstatus=2;; [iI]) echo -e "${STY_BLUE}Alright, ignore and continue...${STY_RESET}";cmdstatus=2;;
[eE]) echo -e "${STY_BLUE}Alright, will exit.${STY_RESET}";break;; [eE]) echo -e "${STY_BLUE}Alright, will exit.${STY_RESET}";break;;
@@ -64,7 +64,11 @@ function showfun(){
printf "${STY_RESET}" printf "${STY_RESET}"
} }
function pause(){ function pause(){
if [ ! "$ask" == "false" ];then printf "${STY_FAINT}${STY_SLANT}";read -p "(Ctrl-C to abort, others to proceed)" p;printf "${STY_RESET}";fi if [ ! "$ask" == "false" ];then
printf "${STY_FAINT}${STY_SLANT}"
local p; read -p "(Ctrl-C to abort, others to proceed)" p
printf "${STY_RESET}"
fi
} }
function remove_bashcomments_emptylines(){ function remove_bashcomments_emptylines(){
mkdir -p $(dirname $2) mkdir -p $(dirname $2)
@@ -75,7 +79,7 @@ function prevent_sudo_or_root(){
root) echo -e "${STY_RED}[$0]: This script is NOT to be executed with sudo or as root. Aborting...${STY_RESET}";exit 1;; root) echo -e "${STY_RED}[$0]: This script is NOT to be executed with sudo or as root. Aborting...${STY_RESET}";exit 1;;
esac esac
} }
function git_unshallow(){ function git_auto_unshallow(){
# We need this function for latest_commit_hash to work properly # We need this function for latest_commit_hash to work properly
if [[ -f "$(git rev-parse --git-dir)/shallow" ]]; then if [[ -f "$(git rev-parse --git-dir)/shallow" ]]; then
echo "Shallow clone detected. Unshallowing..." echo "Shallow clone detected. Unshallowing..."
@@ -84,9 +88,10 @@ function git_unshallow(){
} }
function latest_commit_timestamp(){ function latest_commit_timestamp(){
local target_path="$1" local target_path="$1"
if [[ ! -e "$target_path" ]]; then local result=$(git log -1 --format="%ct" -- "$target_path" 2>/dev/null)
echo "[latest_commit_timestamp] '$target_path' does not exist. Aborting..." if [[ -z "$result" ]]; then
echo "[latest_commit_timestamp] The timestamp of \"$target_path\" is empty. Aborting..." >&2
return 1 return 1
fi fi
echo $(git log -1 --format="%ct" -- "$target_path" 2>/dev/null) echo $result
} }
+1 -1
View File
@@ -52,7 +52,7 @@ v sudo rm /etc/modules-load.d/i2c-dev.conf
############################################################################################################################## ##############################################################################################################################
read -p "Do you want to uninstall the illogical-impulse-* meta packages (Arch Linux only)? read -p "Do you want to uninstall the illogical-impulse-* meta packages (Arch Linux only)?
Ctrl+C to exit, or press Enter to proceed" Ctrl+C to exit, or press Enter to proceed" p
# Removing installed yay packages and dependencies # Removing installed yay packages and dependencies
v yay -Rns illogical-impulse-{agsv1,audio,backlight,basic,bibata-modern-classic-bin,fonts-themes,gnome,gtk,hyprland,microtex-git,oneui4-icons-git,portal,python,screencapture,widgets} plasma-browser-integration v yay -Rns illogical-impulse-{agsv1,audio,backlight,basic,bibata-modern-classic-bin,fonts-themes,gnome,gtk,hyprland,microtex-git,oneui4-icons-git,portal,python,screencapture,widgets} plasma-browser-integration