diff --git a/install.sh b/install.sh index a3436eeb0..664282114 100755 --- a/install.sh +++ b/install.sh @@ -13,12 +13,23 @@ set -e # 0. Before we start source ./scriptdata/install-greeting.sh ##################################################################################### -printf "${COLOR_CYAN}[$0]: 1. Install dependencies\n${COLOR_RESET}" -# TODO: if `--via-nix` is specified, source `install-deps-nix` instead. -source ./scriptdata/install-deps-arch.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 +fi ##################################################################################### -printf "${COLOR_CYAN}[$0]: 2. Setup for user groups/services etc\n${COLOR_RESET}" -source ./scriptdata/install-setups.sh +if [[ "${SKIP_ALLSETUPS}" != true ]]; then + printf "${COLOR_CYAN}[$0]: 2. Setup for user groups/services etc\n${COLOR_RESET}" + source ./scriptdata/install-setups.sh +fi ##################################################################################### -printf "${COLOR_CYAN}[$0]: 3. Copying + Configuring\n${COLOR_RESET}" -source ./scriptdata/install-files.sh +if [[ "${SKIP_ALLFILES}" != true ]]; then + printf "${COLOR_CYAN}[$0]: 3. Copying + Configuring\n${COLOR_RESET}" + source ./scriptdata/install-files.sh +fi diff --git a/scriptdata/environment-variables.sh b/scriptdata/environment-variables.sh index ef71c7d21..44057679c 100644 --- a/scriptdata/environment-variables.sh +++ b/scriptdata/environment-variables.sh @@ -17,3 +17,4 @@ COLOR_RESET='\e[00m' STYLE_UNDERLINE='\e[4m' BG_COLOR_CYAN='\e[30m\e[46m' +BG_COLOR_RED='\e[30m\e[41m' diff --git a/scriptdata/functions.sh b/scriptdata/functions.sh index 86cce1507..e5477fa0c 100644 --- a/scriptdata/functions.sh +++ b/scriptdata/functions.sh @@ -6,7 +6,7 @@ # export base="$(pwd)" function try { "$@" || sleep 0; } -function v() { +function v(){ echo -e "####################################################" echo -e "${COLOR_BLUE}[$0]: Next command:${COLOR_RESET}" echo -e "${COLOR_GREEN}$@${COLOR_RESET}" @@ -33,7 +33,7 @@ function v() { fi } # 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 while [ $cmdstatus == 1 ] ;do echo -e "${COLOR_RED}[$0]: Command \"${COLOR_GREEN}$@${COLOR_RED}\" has failed." @@ -57,7 +57,7 @@ function x() { 2) echo -e "${COLOR_RED}[$0]: Command \"${COLOR_GREEN}$@${COLOR_RED}\" has failed but ignored by user.${COLOR_RESET}";; esac } -function showfun() { +function showfun(){ echo -e "${COLOR_BLUE}[$0]: The definition of function \"$1\" is as follows:${COLOR_RESET}" printf "${COLOR_GREEN}" type -a $1 diff --git a/scriptdata/install-deps-any.sh b/scriptdata/install-deps-any.sh new file mode 100644 index 000000000..b106cfbe6 --- /dev/null +++ b/scriptdata/install-deps-any.sh @@ -0,0 +1,11 @@ +# This script is meant to be sourced. +# It's not for directly running. + +# This file is currently WIP. + +v install-Rubik +v install-Gabarito +v install-OneUI +v install-bibata +v install-MicroTeX +v install-uv diff --git a/scriptdata/install-deps-arch.sh b/scriptdata/install-deps-arch.sh index adc56760c..ecf1402ed 100644 --- a/scriptdata/install-deps-arch.sh +++ b/scriptdata/install-deps-arch.sh @@ -1,7 +1,7 @@ # This script is meant to be sourced. # It's not for directly running. -install-yay() { +install-yay(){ x sudo pacman -S --needed --noconfirm base-devel x git clone https://aur.archlinux.org/yay-bin.git /tmp/buildyay x cd /tmp/buildyay @@ -12,7 +12,7 @@ install-yay() { rm -rf /tmp/buildyay } -handle-deprecated-dependencies (){ +handle-deprecated-dependencies(){ printf "${COLOR_CYAN}[$0]: Removing deprecated dependencies:${COLOR_RESET}\n" for i in illogical-impulse-{microtex,pymyc-aur,ags,agsv1} {hyprutils,hyprpicker,hyprlang,hypridle,hyprland-qt-support,hyprland-qtutils,hyprlock,xdg-desktop-portal-hyprland,hyprcursor,hyprwayland-scanner,hyprland}-git;do try sudo pacman --noconfirm -Rdd $i;done # Convert old dependencies to non explicit dependencies so that they can be orphaned if not in meta packages diff --git a/scriptdata/install-deps-nix.sh b/scriptdata/install-deps-nix.sh new file mode 100644 index 000000000..77697e501 --- /dev/null +++ b/scriptdata/install-deps-nix.sh @@ -0,0 +1,4 @@ +# This script is meant to be sourced. +# It's not for directly running. + +# This file is currently WIP. diff --git a/scriptdata/install-files.sh b/scriptdata/install-files.sh index e49399ced..845f45c4b 100644 --- a/scriptdata/install-files.sh +++ b/scriptdata/install-files.sh @@ -2,7 +2,7 @@ # It's not for directly running. # TODO: make function backup_configs only cover the possibly overwritten ones. -function backup_configs() { +function backup_configs(){ local backup_dir="$BACKUP_DIR" mkdir -p "$backup_dir" echo "Backing up $XDG_CONFIG_HOME to $backup_dir/config_backup" @@ -12,7 +12,7 @@ function backup_configs() { rsync -av --progress "$HOME/.local/" "$backup_dir/local_backup/" } -function ask_backup_configs() { +function ask_backup_configs(){ printf "${COLOR_RED}" printf "Would you like to create a backup for \"$XDG_CONFIG_HOME\" and \"$HOME/.local/\" folders?\n[y/N]: " read -p " " backup_confirm diff --git a/scriptdata/install-greeting.sh b/scriptdata/install-greeting.sh index f49800926..295fefbfb 100644 --- a/scriptdata/install-greeting.sh +++ b/scriptdata/install-greeting.sh @@ -11,9 +11,9 @@ printf ' If you aren'\''t running on ewaste, the Quickshell version is reco printf ' If you would like the AGS version anyway, run the script in its branch instead: git checkout ii-ags && ./install.sh\n' printf '\n' printf 'This script does not handle system-level/hardware stuff like Nvidia drivers.\n' +printf "\n" printf "${COLOR_RESET}" - case $ask in false) sleep 0 ;; *) @@ -32,3 +32,65 @@ 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/installers.sh b/scriptdata/installers.sh index 52b74173a..ffbf2bc53 100644 --- a/scriptdata/installers.sh +++ b/scriptdata/installers.sh @@ -8,7 +8,7 @@ # cd "$(dirname "$0")" # export base="$(pwd)" -install-agsv1 (){ +install-agsv1(){ x mkdir -p $base/cache/agsv1 x cd $base/cache/agsv1 try git init -b main @@ -23,7 +23,7 @@ install-agsv1 (){ x cd $base } -install-Rubik (){ +install-Rubik(){ x mkdir -p $base/cache/Rubik x cd $base/cache/Rubik try git init -b main @@ -38,7 +38,7 @@ install-Rubik (){ x cd $base } -install-Gabarito (){ +install-Gabarito(){ x mkdir -p $base/cache/Gabarito x cd $base/cache/Gabarito try git init -b main @@ -52,7 +52,7 @@ install-Gabarito (){ x cd $base } -install-OneUI (){ +install-OneUI(){ x mkdir -p $base/cache/OneUI4-Icons x cd $base/cache/OneUI4-Icons try git init -b main @@ -66,7 +66,7 @@ install-OneUI (){ x cd $base } -install-bibata (){ +install-bibata(){ x mkdir -p $base/cache/bibata-cursor x cd $base/cache/bibata-cursor name="Bibata-Modern-Classic" @@ -79,7 +79,7 @@ install-bibata (){ x cd $base } -install-MicroTeX (){ +install-MicroTeX(){ x mkdir -p $base/cache/MicroTeX x cd $base/cache/MicroTeX try git init -b master @@ -95,11 +95,11 @@ install-MicroTeX (){ x cd $base } -install-uv (){ +install-uv(){ x bash <(curl -LJs "https://astral.sh/uv/install.sh") } -install-python-packages (){ +install-python-packages(){ UV_NO_MODIFY_PATH=1 ILLOGICAL_IMPULSE_VIRTUAL_ENV=$XDG_STATE_HOME/quickshell/.venv x mkdir -p $(eval echo $ILLOGICAL_IMPULSE_VIRTUAL_ENV) diff --git a/scriptdata/options.sh b/scriptdata/options.sh index 300bd2b15..0a4f7b49f 100644 --- a/scriptdata/options.sh +++ b/scriptdata/options.sh @@ -12,15 +12,17 @@ If no option is specified, run default install process. -h, --help Print this help message and exit -f, --force (Dangerous) Force mode without any confirm -c, --clean Clean the build cache first + --skip-alldeps Skip the whole process installing dependency + --skip-allsetups Skip the whole process setting up user groups/services etc + --skip-allfiles Skip the whole process copying configuration files -s, --skip-sysupdate Skip system package upgrade e.g. \"sudo pacman -Syu\" --skip-hyprland Skip installing the config for Hyprland --skip-fish Skip installing the config for Fish --skip-plasmaintg Skip installing plasma-browser-integration --skip-miscconf Skip copying the dirs and files to \".configs\" except for AGS, Fish and Hyprland - --deplistfile Specify a dependency list file. By default - \"./scriptdata/dependencies.conf\" --fontset (Unavailable yet) Use a set of pre-defined font and config + --via-nix (Unavailable yet) Use Nix to install dependencies " } @@ -31,7 +33,7 @@ cleancache(){ # `man getopt` to see more para=$(getopt \ -o hfk:cs \ - -l help,force,fontset:,deplistfile:,clean,skip-sysupdate,skip-fish,skip-hyprland,skip-plasmaintg,skip-miscconf \ + -l help,force,fontset:,clean,skip-alldeps,skip-allsetups,skip-allfiles,skip-sysupdate,skip-fish,skip-hyprland,skip-plasmaintg,skip-miscconf,via-nix \ -n "$0" -- "$@") [ $? != 0 ] && echo "$0: Error when getopt, please recheck parameters." && exit 1 ##################################################################################### @@ -48,7 +50,6 @@ while true ; do done ##################################################################################### ## getopt Phase 2 -DEPLISTFILE=./scriptdata/dependencies.conf eval set -- "$para" while true ; do @@ -57,21 +58,17 @@ while true ; do -c|--clean) shift;; ## Ones without parameter -f|--force) ask=false;shift;; + --skip-alldeps) SKIP_PLASMAINTG=true;shift;; + --skip-allsetups) SKIP_ALLSETUPS=true;shift;; + --skip-allfiles) SKIP_ALLFILES=true;shift;; -s|--skip-sysupdate) SKIP_SYSUPDATE=true;shift;; --skip-hyprland) SKIP_HYPRLAND=true;shift;; --skip-fish) SKIP_FISH=true;shift;; --skip-miscconf) SKIP_MISCCONF=true;shift;; --skip-plasmaintg) SKIP_PLASMAINTG=true;shift;; + --via-nix) INSTALL_VIA_NIX=true;shift;; ## Ones with parameter - --deplistfile) - if [ -f "$2" ];then - DEPLISTFILE="$2" - else - echo -e "Deplist file \"$2\" does not exist.";exit 1 - fi - shift 2 ;; - --fontset) case $2 in "default"|"zh-CN"|"vi") fontset="$2";;