Rearrange for tidier structure (#2212)

This commit is contained in:
clsty
2025-10-16 07:19:55 +08:00
parent 13065d7e5a
commit 8b493e091d
529 changed files with 165 additions and 138 deletions
+31
View File
@@ -0,0 +1,31 @@
# This is NOT a script for execution, but for loading functions, so NOT need execution permission or shebang.
XDG_BIN_HOME=${XDG_BIN_HOME:-$HOME/.local/bin}
XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
XDG_STATE_HOME=${XDG_STATE_HOME:-$HOME/.local/state}
BACKUP_DIR=${BACKUP_DIR:-$HOME/backup}
# Note that all color styles contains a STY_RESET before it.
STY_RED='\e[00m\e[31m'
STY_GREEN='\e[00m\e[32m'
STY_YELLOW='\e[00m\e[33m'
STY_BLUE='\e[00m\e[34m'
STY_PURPLE='\e[00m\e[35m'
STY_CYAN='\e[00m\e[36m'
STY_BG_RED='\e[30m\e[41m'
STY_BG_GREEN='\e[30m\e[42m'
STY_BG_YELLOW='\e[30m\e[43m'
STY_BG_BLUE='\e[30m\e[44m'
STY_BG_PURPLE='\e[30m\e[45m'
STY_BG_CYAN='\e[30m\e[46m'
STY_BOLD='\e[1m'
STY_FAINT='\e[2m'
STY_SLANT='\e[3m'
STY_UNDERLINE='\e[4m'
STY_BLINK='\e[5m'
STY_INVERT='\e[7m'
STY_RESET='\e[00m'
+97
View File
@@ -0,0 +1,97 @@
# This is NOT a script for execution, but for loading functions, so NOT need execution permission or shebang.
# NOTE that you NOT need to `cd ..' because the `$0' is NOT this file, but the script file which will source this file.
# The script that use this file should have two lines on its top as follows:
# cd "$(dirname "$0")"
# export base="$(pwd)"
function try { "$@" || sleep 0; }
function v(){
echo -e "####################################################"
echo -e "${STY_BLUE}[$0]: Next command:${STY_RESET}"
echo -e "${STY_GREEN}$@${STY_RESET}"
local execute=true
if $ask;then
while true;do
echo -e "${STY_BLUE}Execute? ${STY_RESET}"
echo " y = Yes"
echo " e = Exit now"
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"
local p; read -p "====> " p
case $p in
[yY]) echo -e "${STY_BLUE}OK, executing...${STY_RESET}" ;break ;;
[eE]) echo -e "${STY_BLUE}Exiting...${STY_RESET}" ;exit ;break ;;
[sS]) echo -e "${STY_BLUE}Alright, skipping this one...${STY_RESET}" ;execute=false ;break ;;
"yesforall") echo -e "${STY_BLUE}Alright, won't ask again. Executing...${STY_RESET}"; ask=false ;break ;;
*) echo -e "${STY_RED}Please enter [y/e/s/yesforall].${STY_RESET}";;
esac
done
fi
if $execute;then x "$@";else
echo -e "${STY_YELLOW}[$0]: Skipped \"$@\"${STY_RESET}"
fi
}
# When use v() for a defined function, use x() INSIDE its definition to catch errors.
function x(){
if "$@";then local cmdstatus=0;else local cmdstatus=1;fi # 0=normal; 1=failed; 2=failed but ignored
while [ $cmdstatus == 1 ] ;do
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 "[Tip] If a certain package is failing to install, try installing it separately in another terminal.${STY_RESET}"
echo " r = Repeat this command (DEFAULT)"
echo " e = Exit now"
echo " i = Ignore this error and continue (your setup might not work correctly)"
local p; read -p " [R/e/i]: " p
case $p in
[iI]) echo -e "${STY_BLUE}Alright, ignore and continue...${STY_RESET}";cmdstatus=2;;
[eE]) echo -e "${STY_BLUE}Alright, will exit.${STY_RESET}";break;;
*) echo -e "${STY_BLUE}OK, repeating...${STY_RESET}"
if "$@";then cmdstatus=0;else cmdstatus=1;fi
;;
esac
done
case $cmdstatus in
0) echo -e "${STY_BLUE}[$0]: Command \"${STY_GREEN}$@${STY_BLUE}\" finished.${STY_RESET}";;
1) echo -e "${STY_RED}[$0]: Command \"${STY_GREEN}$@${STY_RED}\" has failed. Exiting...${STY_RESET}";exit 1;;
2) echo -e "${STY_RED}[$0]: Command \"${STY_GREEN}$@${STY_RED}\" has failed but ignored by user.${STY_RESET}";;
esac
}
function showfun(){
echo -e "${STY_BLUE}[$0]: The definition of function \"$1\" is as follows:${STY_RESET}"
printf "${STY_GREEN}"
type -a $1
printf "${STY_RESET}"
}
function pause(){
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(){
mkdir -p $(dirname $2)
cat $1 | sed -e '/^[[:blank:]]*#/d;s/#.*//' -e '/^[[:space:]]*$/d' > $2
}
function prevent_sudo_or_root(){
case $(whoami) in
root) echo -e "${STY_RED}[$0]: This script is NOT to be executed with sudo or as root. Aborting...${STY_RESET}";exit 1;;
esac
}
function git_auto_unshallow(){
# We need this function for latest_commit_hash to work properly
if [[ -f "$(git rev-parse --git-dir)/shallow" ]]; then
echo "Shallow clone detected. Unshallowing..."
git fetch --unshallow
fi
}
function latest_commit_timestamp(){
local target_path="$1"
local result=$(git log -1 --format="%ct" -- "$target_path" 2>/dev/null)
if [[ -z "$result" ]]; then
echo "[latest_commit_timestamp] The timestamp of \"$target_path\" is empty. Aborting..." >&2
return 1
fi
echo $result
}
+88
View File
@@ -0,0 +1,88 @@
# This is NOT a script for execution, but for loading functions, so NOT need execution permission or shebang.
# NOTE that you NOT need to `cd ..' because the `$0' is NOT this file, but the script file which will source this file.
# The script that use this file should have two lines on its top as follows:
# cd "$(dirname "$0")" export base="$(pwd)"
showhelp(){
echo -e "Syntax: $0 [Options]...
Idempotent installation script for dotfiles.
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-allgreeting Skip the whole process greeting
--skip-alldeps Skip the whole process installing dependency
--skip-allsetups Skip the whole process setting up permissions/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
--exp-files Use experimental script for the third step copying files
--fontset <set> (Unavailable yet) Use a set of pre-defined font and config
--via-nix (Unavailable yet) Use Nix to install dependencies
--exp-uninstall Use experimental uninstall script
"
}
cleancache(){
rm -rf "$base/cache"
}
# `man getopt` to see more
para=$(getopt \
-o hfk:cs \
-l help,force,fontset:,clean,skip-allgreeting,skip-alldeps,skip-allsetups,skip-allfiles,skip-sysupdate,skip-fish,skip-hyprland,skip-plasmaintg,skip-miscconf,exp-files,via-nix,exp-uninstall \
-n "$0" -- "$@")
[ $? != 0 ] && echo "$0: Error when getopt, please recheck parameters." && exit 1
#####################################################################################
## getopt Phase 1
# ignore parameter's order, execute options below first
eval set -- "$para"
while true ; do
case "$1" in
-h|--help) showhelp;exit;;
-c|--clean) cleancache;shift;;
--) break ;;
*) shift ;;
esac
done
#####################################################################################
## getopt Phase 2
eval set -- "$para"
while true ; do
case "$1" in
## Already processed in phase 1, but not exited
-c|--clean) shift;;
## Ones without parameter
-f|--force) ask=false;shift;;
--skip-allgreeting) SKIP_ALLGREETING=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;;
--skip-hyprland) SKIP_HYPRLAND=true;shift;;
--skip-fish) SKIP_FISH=true;shift;;
--skip-miscconf) SKIP_MISCCONF=true;shift;;
--skip-plasmaintg) SKIP_PLASMAINTG=true;shift;;
--exp-files) EXPERIMENTAL_FILES_SCRIPT=true;shift;;
--via-nix) INSTALL_VIA_NIX=true;shift;;
--exp-uninstall) EXPERIMENTAL_UNINSTALL_SCRIPT=true;shift;;
## Ones with parameter
--fontset)
case $2 in
"default"|"zh-CN"|"vi") fontset="$2";;
*) echo -e "Wrong argument for $1.";exit 1;;
esac;echo "The fontset is ${fontset}.";shift 2;;
## Ending
--) break ;;
*) echo -e "$0: Wrong parameters.";exit 1;;
esac
done
+111
View File
@@ -0,0 +1,111 @@
# This script depends on `functions.sh' .
# This is NOT a script for execution, but for loading functions, so NOT need execution permission or shebang.
# NOTE that you NOT need to `cd ..' because the `$0' is NOT this file, but the script file which will source this file.
# This file is provided for any distros, mainly non-Arch(based) distros.
# The script that use this file should have two lines on its top as follows:
# cd "$(dirname "$0")"
# export base="$(pwd)"
install-agsv1(){
x mkdir -p $base/cache/agsv1
x cd $base/cache/agsv1
try git init -b main
try git remote add origin https://github.com/Aylur/ags.git
x git pull origin main && git submodule update --init --recursive
x git fetch --tags
x git checkout v1.9.0
x npm install
x meson setup build # --reconfigure
x meson install -C build
x sudo mv /usr/local/bin/ags{,v1}
x cd $base
}
install-Rubik(){
x mkdir -p $base/cache/Rubik
x cd $base/cache/Rubik
try git init -b main
try git remote add origin https://github.com/googlefonts/rubik.git
x git pull origin main && git submodule update --init --recursive
x sudo mkdir -p /usr/local/share/fonts/TTF/
x sudo cp fonts/variable/Rubik*.ttf /usr/local/share/fonts/TTF/
x sudo mkdir -p /usr/local/share/licenses/ttf-rubik/
x sudo cp OFL.txt /usr/local/share/licenses/ttf-rubik/LICENSE
x fc-cache -fv
x gsettings set org.gnome.desktop.interface font-name 'Rubik 11'
x cd $base
}
install-Gabarito(){
x mkdir -p $base/cache/Gabarito
x cd $base/cache/Gabarito
try git init -b main
try git remote add origin https://github.com/naipefoundry/gabarito.git
x git pull origin main && git submodule update --init --recursive
x sudo mkdir -p /usr/local/share/fonts/TTF/
x sudo cp fonts/ttf/Gabarito*.ttf /usr/local/share/fonts/TTF/
x sudo mkdir -p /usr/local/share/licenses/ttf-gabarito/
x sudo cp OFL.txt /usr/local/share/licenses/ttf-gabarito/LICENSE
x fc-cache -fv
x cd $base
}
install-OneUI(){
x mkdir -p $base/cache/OneUI4-Icons
x cd $base/cache/OneUI4-Icons
try git init -b main
try git remote add origin https://github.com/end-4/OneUI4-Icons.git
# try git remote add origin https://github.com/mjkim0727/OneUI4-Icons.git
x git pull origin main && git submodule update --init --recursive
x sudo mkdir -p /usr/local/share/icons
x sudo cp -r OneUI /usr/local/share/icons
x sudo cp -r OneUI-dark /usr/local/share/icons
x sudo cp -r OneUI-light /usr/local/share/icons
x cd $base
}
install-bibata(){
x mkdir -p $base/cache/bibata-cursor
x cd $base/cache/bibata-cursor
name="Bibata-Modern-Classic"
file="$name.tar.xz"
# Use axel because `curl -O` always downloads a file with 0 byte size, idk why
x axel https://github.com/ful1e5/Bibata_Cursor/releases/latest/download/$file
tar -xf $file
x sudo mkdir -p /usr/local/share/icons
x sudo cp -r $name /usr/local/share/icons
x cd $base
}
install-MicroTeX(){
x mkdir -p $base/cache/MicroTeX
x cd $base/cache/MicroTeX
try git init -b master
try git remote add origin https://github.com/NanoMichael/MicroTeX.git
x git pull origin master && git submodule update --init --recursive
x mkdir -p build
x cd build
x cmake ..
x make -j32
x sudo mkdir -p /opt/MicroTeX
x sudo cp ./LaTeX /opt/MicroTeX/
x sudo cp -r ./res /opt/MicroTeX/
x cd $base
}
install-uv(){
x bash <(curl -LJs "https://astral.sh/uv/install.sh")
}
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)
# we need python 3.12 https://github.com/python-pillow/Pillow/issues/8089
x uv venv --prompt .venv $(eval echo $ILLOGICAL_IMPULSE_VIRTUAL_ENV) -p 3.12
x source $(eval echo $ILLOGICAL_IMPULSE_VIRTUAL_ENV)/bin/activate
x uv pip install -r sdata/uv/requirements.txt
x deactivate # We don't need the virtual environment anymore
}