From 4085b4a74a4f4a206d1498b3467c61bc7f72efee Mon Sep 17 00:00:00 2001 From: clsty Date: Thu, 2 Oct 2025 01:57:20 +0800 Subject: [PATCH] Improve dependency install process --- diagnose | 12 +++ install.sh | 8 +- ...l-deps-any.sh => install-deps-fallback.sh} | 0 scriptdata/install-deps.sh | 100 ++++++++++++++++++ scriptdata/install-greeting.sh | 62 ----------- scriptdata/options.sh | 2 +- 6 files changed, 114 insertions(+), 70 deletions(-) rename scriptdata/{install-deps-any.sh => install-deps-fallback.sh} (100%) create mode 100644 scriptdata/install-deps.sh diff --git a/diagnose b/diagnose index c7008c55d..3d67cdb81 100755 --- a/diagnose +++ b/diagnose @@ -32,6 +32,17 @@ ii_exec() { "$@" err=$?;if [ ! $err -eq 0 ];then echo "[---EXIT $err---]";else echo "[---SUCCESS---]";fi } +ii_check_distro_id() { + OS_RELEASE_FILE=/etc/os-release + if [[ -f "$OS_RELEASE_FILE" ]]; then + OS_DISTRO_ID=$(awk -F'=' '/^ID=/ { gsub("\"","",$2); print tolower($2) }' ${OS_RELEASE_FILE} 2> /dev/null) + OS_DISTRO_ID_LIKE=$(awk -F'=' '/^ID_LIKE=/ { gsub("\"","",$2); print tolower($2) }' ${OS_RELEASE_FILE} 2> /dev/null) + echo "distro ID: $OS_DISTRO_ID" + echo "distro ID_LIKE: $OS_DISTRO_ID_LIKE" + else + echo "$OS_RELEASE_FILE does not exist." + fi +} ii_check_distro() { lsb_release -a || cat /etc/os-release || cat /etc/lsb-release } @@ -46,6 +57,7 @@ x git remote get-url origin x git rev-parse HEAD e "Checking distro" +x ii_check_distro_id x ii_check_distro e "Checking variables" diff --git a/install.sh b/install.sh index 664282114..ce0ce1a35 100755 --- a/install.sh +++ b/install.sh @@ -15,13 +15,7 @@ source ./scriptdata/install-greeting.sh ##################################################################################### if [[ "${SKIP_ALLDEPS}" != true ]]; then printf "${COLOR_CYAN}[$0]: 1. Install dependencies\n${COLOR_RESET}" - if [[ "${INSTALL_VIA_NIX}" == "true" ]]; then - source ./scriptdata/install-deps-nix.sh - elif [[ "${OS_DISTRO_ID}" == "arch" || "${OS_DISTRO_ID_LIKE}" == "arch" ]]; then - source ./scriptdata/install-deps-arch.sh - else - source ./scriptdata/install-deps-any.sh - fi + source ./scriptdata/install-deps.sh fi ##################################################################################### if [[ "${SKIP_ALLSETUPS}" != true ]]; then diff --git a/scriptdata/install-deps-any.sh b/scriptdata/install-deps-fallback.sh similarity index 100% rename from scriptdata/install-deps-any.sh rename to scriptdata/install-deps-fallback.sh diff --git a/scriptdata/install-deps.sh b/scriptdata/install-deps.sh new file mode 100644 index 000000000..28131c24a --- /dev/null +++ b/scriptdata/install-deps.sh @@ -0,0 +1,100 @@ +# This script is meant to be sourced. +# It's not for directly running. + +#################### +# Detect architecture +# Helpful link(s): +# http://stackoverflow.com/questions/45125516 +export MACHINE_ARCH=$(uname -m) +case $MACHINE_ARCH in + "x86_64") sleep 0;; + *) + printf "${COLOR_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 "${COLOR_RESET}" + ;; + esac + +#################### +# Detect distro +# Helpful link(s): +# http://stackoverflow.com/questions/29581754 +# https://github.com/which-distro/os-release +export OS_RELEASE_FILE=${OS_RELEASE_FILE:-/etc/os-release} +test -f ${OS_RELEASE_FILE} || \ + ( echo "${OS_RELEASE_FILE} does not exist. Aborting..." ; exit 1 ; ) +export OS_DISTRO_ID=$(awk -F'=' '/^ID=/ { 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 + + printf "${COLOR_YELLOW}" + printf "===WARNING===\n" + printf "Nix will be used to install dependencies.\n" + printf "The process is still WIP.\n" + printf "Only continue at your own risk.\n" + printf "\n" + printf "${COLOR_RESET}" + source ./scriptdata/install-deps-nix.sh + +elif [[ "$OS_DISTRO_ID" =~ ^(arch|endeavouros)$ ]]; then + + printf "${COLOR_GREEN}" + printf "===INFO===\n" + printf "Detected distro ID: ${OS_DISTRO_ID}\n" + printf "\n" + printf "${COLOR_RESET}" + source ./scriptdata/install-deps-arch.sh + +elif [[ -f "./scriptdata/install-deps-${OS_DISTRO_ID}.sh" ]]; then + + printf "${COLOR_BLUE}" + printf "===NOTICE===\n" + printf "Detected distro ID: ${OS_DISTRO_ID}\n" + printf "./scriptdata/install-deps-${OS_DISTRO_ID}.sh detected and will be used.\n" + printf "It is not officially supported by github:end-4/dots-hyprland .\n" + printf "Use it only at your own risk.\n" + printf "\n" + printf "${COLOR_RESET}" + source ./scriptdata/install-deps-${OS_DISTRO_ID}.sh + +elif [[ "$OS_DISTRO_ID_LIKE" == "arch" ]]; then + + printf "${COLOR_YELLOW}" + printf "===WARNING===\n" + printf "Detected distro ID: ${OS_DISTRO_ID}\n" + printf "Detected distro ID_LIKE: ${OS_DISTRO_ID_LIKE}\n" + printf "This script supports Arch Linux, so it should also work for your distro ideally.\n" + printf "Still, there is a chance that it not works as expected or even fails.\n" + printf "Use it only at your own risk.\n" + printf "\n" + printf "${COLOR_RESET}" + source ./scriptdata/install-deps-arch.sh + +else + + printf "${COLOR_RED}" + printf "===URGENT===\n" + printf "Detected distro ID: ${OS_DISTRO_ID}\n" + printf "Detected distro ID_LIKE: ${OS_DISTRO_ID_LIKE}\n" + printf "No suitable dependency installation script found.\n" + printf "./scriptdata/install-deps-fallback.sh will be used.\n" + printf "It may disrupt your system and will likely fail without your manual intervention.\n" + printf "Only continue at your own risk.\n" + printf "${COLOR_RESET}" + printf "${BG_COLOR_RED}" + printf "To tell you the truth, it is completely not worky at this time. The prompt here is only for testing and WIP. PLEASE JUST QUIT IMMEDIATELY.${COLOR_RESET}\n" + read -p "Still continue? [y/N] ====> " p + case $p in + [yY]) sleep 0 ;; + *) exit 1 ;; + esac + source ./scriptdata/install-deps-fallback.sh + +fi diff --git a/scriptdata/install-greeting.sh b/scriptdata/install-greeting.sh index 295fefbfb..3da9615c1 100644 --- a/scriptdata/install-greeting.sh +++ b/scriptdata/install-greeting.sh @@ -32,65 +32,3 @@ case $ask in printf "${COLOR_RESET}" ;; esac - -#################### -# Detect architecture -# Helpful link(s): -# http://stackoverflow.com/questions/45125516 -export MACHINE_ARCH=$(uname -m) -case $MACHINE_ARCH in - "x86_64") sleep 0;; - *) - printf "${COLOR_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 "${COLOR_RESET}" - ;; - esac - -#################### -# Detect distro -# Helpful link(s): -# http://stackoverflow.com/questions/29581754 -# https://github.com/which-distro/os-release -export OS_RELEASE_FILE=${OS_RELEASE_FILE:-/etc/os-release} -test -f ${OS_RELEASE_FILE} || \ - ( echo "${OS_RELEASE_FILE} does not exist. Aborting..." ; exit 1 ; ) -export OS_DISTRO_ID=$(awk -F'=' '/^ID=/ { 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) -case $OS_DISTRO_ID in - "arch"|"endeavouros"|"cachyos") sleep 0;; - *) - case $OS_DISTRO_ID_LIKE in - "arch") - printf "${COLOR_YELLOW}" - printf "===WARNING===\n" - printf "Detected distro ID: ${OS_DISTRO_ID}\n" - printf "Detected distro ID_LIKE: ${OS_DISTRO_ID_LIKE}\n" - printf "This script supports Arch Linux, so it should also work for your distro ideally.\n" - printf "Still, there is a chance that it not works as expected or even fails.\n" - printf "\n" - printf "${COLOR_RESET}" - ;; - *) - printf "${COLOR_RED}" - printf "===URGENT===\n" - printf "Detected distro ID: ${OS_DISTRO_ID}\n" - printf "Currently, only Arch(-based) distros are supported.\n" - printf "If you continue, this script will still move on and try to install some dependencies for you.\n" - printf "But it may disrupt your system and will likely fail without your manual intervention. Only continue at your own risk.\n" - printf "${COLOR_RESET}" - printf "${BG_COLOR_RED}" - printf "To tell you the truth, it is completely not worky at this time. The prompt here is only for testing and WIP. PLEASE JUST QUIT IMMEDIATELY.${COLOR_RESET}\n" - read -p "Still continue? [y/N] ====> " p - case $p in - [yY]) sleep 0 ;; - *) exit 1 ;; - esac - ;; - esac - ;; -esac diff --git a/scriptdata/options.sh b/scriptdata/options.sh index 0a4f7b49f..715b542c6 100644 --- a/scriptdata/options.sh +++ b/scriptdata/options.sh @@ -58,7 +58,7 @@ while true ; do -c|--clean) shift;; ## Ones without parameter -f|--force) ask=false;shift;; - --skip-alldeps) SKIP_PLASMAINTG=true;shift;; + --skip-alldeps) SKIP_ALLDEPS=true;shift;; --skip-allsetups) SKIP_ALLSETUPS=true;shift;; --skip-allfiles) SKIP_ALLFILES=true;shift;; -s|--skip-sysupdate) SKIP_SYSUPDATE=true;shift;;