33
44# shellcheck shell=bash
55
6- function copy_file_s_t(){
6+ function gen_firstrun(){
7+ x mkdir -p " $( dirname ${FIRSTRUN_FILE} ) "
8+ x mkdir -p " $( dirname ${INSTALLED_LISTFILE} ) "
9+ x touch " ${FIRSTRUN_FILE} "
10+ realpath -se " ${FIRSTRUN_FILE} " >> " ${INSTALLED_LISTFILE} "
11+ }
12+ cp_file (){
13+ # NOTE: This function is only for using in other functions
14+ x mkdir -p " $( dirname $2 ) "
15+ x mkdir -p " $( dirname ${INSTALLED_LISTFILE} ) "
16+ x cp -f " $1 " " $2 "
17+ realpath -se " $2 " >> " ${INSTALLED_LISTFILE} "
18+ }
19+ rsync_dir (){
20+ # NOTE: This function is only for using in other functions
21+ x mkdir -p " $2 "
22+ x mkdir -p " $( dirname ${INSTALLED_LISTFILE} ) "
23+ local dest=" $( realpath -se $2 ) "
24+ rsync -a --out-format=' %i %n' " $1 " / " $2 " / | awk -v d=" $dest " ' $1 ~ /^>/{ sub(/^[^ ]+ /,""); printf d "/" $0 "\n" }' >> " ${INSTALLED_LISTFILE} "
25+ }
26+ rsync_dir__sync (){
27+ # NOTE: This function is only for using in other functions
28+ x mkdir -p " $2 "
29+ x mkdir -p " $( dirname ${INSTALLED_LISTFILE} ) "
30+ local dest=" $( realpath -se $2 ) "
31+ rsync -a --delete --out-format=' %i %n' " $1 " / " $2 " / | awk -v d=" $dest " ' $1 ~ /^>/{ sub(/^[^ ]+ /,""); printf d "/" $0 "\n" }' >> " ${INSTALLED_LISTFILE} "
32+ }
33+ function install_file(){
34+ # NOTE: Do not add prefix `v` or `x` when using this function
35+ local s=$1
36+ local t=$2
37+ if [ -f $t ]; then
38+ warning_overwrite
39+ fi
40+ v cp_file $s $t
41+ }
42+ function install_file__auto_backup(){
43+ # NOTE: Do not add prefix `v` or `x` when using this function
744 local s=$1
845 local t=$2
946 if [ -f $t ]; then
1047 echo -e " ${STY_YELLOW} [$0 ]: \" $t \" already exists.${STY_RST} "
1148 if ${INSTALL_FIRSTRUN} ; then
1249 echo -e " ${STY_BLUE} [$0 ]: It seems to be the firstrun.${STY_RST} "
1350 v mv $t $t .old
14- v cp -f $s $t
51+ v cp_file $s $t
1552 else
1653 echo -e " ${STY_BLUE} [$0 ]: It seems not a firstrun.${STY_RST} "
17- v cp -f $s $t .new
54+ v cp_file $s $t .new
1855 fi
1956 else
2057 echo -e " ${STY_GREEN} [$0 ]: \" $t \" does not exist yet.${STY_RST} "
21- v cp $s $t
58+ v cp_file $s $t
59+ fi
60+ }
61+ function install_dir(){
62+ # NOTE: Do not add prefix `v` or `x` when using this function
63+ local s=$1
64+ local t=$2
65+ if [ -d $t ]; then
66+ warning_overwrite
67+ fi
68+ rsync_dir $s $t
69+ }
70+ function install_dir__sync(){
71+ # NOTE: Do not add prefix `v` or `x` when using this function
72+ local s=$1
73+ local t=$2
74+ if [ -d $t ]; then
75+ warning_overwrite
2276 fi
77+ rsync_dir__sync $s $t
2378}
24- function copy_dir_s_t(){
79+ function install_dir__skip_existed(){
80+ # NOTE: Do not add prefix `v` or `x` when using this function
2581 local s=$1
2682 local t=$2
2783 if [ -d $t ]; then
2884 echo -e " ${STY_BLUE} [$0 ]: \" $t \" already exists, will not do anything.${STY_RST} "
2985 else
3086 echo -e " ${STY_YELLOW} [$0 ]: \" $t \" does not exist yet.${STY_RST} "
31- v rsync -av --delete $s / $t /
87+ v rsync_dir $s $t
3288 fi
3389}
3490
3591# ####################################################################################
3692# In case some dirs does not exists
37- v mkdir -p $XDG_BIN_HOME $XDG_CACHE_HOME $XDG_CONFIG_HOME $XDG_DATA_HOME /icons
93+ v mkdir -p $XDG_BIN_HOME $XDG_CACHE_HOME $XDG_CONFIG_HOME $XDG_DATA_HOME
3894
3995case " ${INSTALL_FIRSTRUN} " in
4096 # When specify --firstrun
@@ -60,66 +116,62 @@ case "${SKIP_MISCCONF}" in
60116 for i in $( find dots/.config/ -mindepth 1 -maxdepth 1 ! -name ' quickshell' ! -name ' fish' ! -name ' hypr' ! -name ' fontconfig' -exec basename {} \; ) ; do
61117# i="dots/.config/$i"
62118 echo " [$0 ]: Found target: dots/.config/$i "
63- if [ -d " dots/.config/$i " ]; then warning_rsync_delete ; v rsync -av --delete " dots/.config/$i / " " $XDG_CONFIG_HOME /$i / "
64- elif [ -f " dots/.config/$i " ]; then warning_rsync_normal ; v rsync -av " dots/.config/$i " " $XDG_CONFIG_HOME /$i "
119+ if [ -d " dots/.config/$i " ]; then install_dir__sync " dots/.config/$i " " $XDG_CONFIG_HOME /$i "
120+ elif [ -f " dots/.config/$i " ]; then install_file " dots/.config/$i " " $XDG_CONFIG_HOME /$i "
65121 fi
66122 done
67- warning_rsync_delete ; v rsync -av " dots/.local/share/konsole/ " " ${XDG_DATA_HOME:- $HOME / .local/ share} " /konsole/
123+ install_dir " dots/.local/share/konsole" " ${XDG_DATA_HOME:- $HOME / .local/ share} " /konsole
68124 ;;
69125esac
70126
71127case " ${SKIP_QUICKSHELL} " in
72128 true) sleep 0;;
73129 * )
74130 # Should overwriting the whole directory not only ~/.config/quickshell/ii/ cuz https://github.com/end-4/dots-hyprland/issues/2294#issuecomment-3448671064
75- warning_rsync_delete ; v rsync -av --delete dots/.config/quickshell/ " $XDG_CONFIG_HOME " /quickshell/
131+ install_dir__sync dots/.config/quickshell " $XDG_CONFIG_HOME " /quickshell
76132 ;;
77133esac
78134
79135case " ${SKIP_FISH} " in
80136 true) sleep 0;;
81137 * )
82- warning_rsync_delete ; v rsync -av --delete dots/.config/fish/ " $XDG_CONFIG_HOME " /fish/
138+ install_dir__sync dots/.config/fish " $XDG_CONFIG_HOME " /fish
83139 ;;
84140esac
85141
86142case " ${SKIP_FONTCONFIG} " in
87143 true) sleep 0;;
88144 * )
89145 case " $FONTSET_DIR_NAME " in
90- " " ) warning_rsync_delete ; v rsync -av --delete dots/.config/fontconfig/ " $XDG_CONFIG_HOME " /fontconfig/ ;;
91- * ) warning_rsync_delete ; v rsync -av --delete dots-extra/fontsets/$FONTSET_DIR_NAME / " $XDG_CONFIG_HOME " /fontconfig/ ;;
146+ " " ) install_dir__sync dots/.config/fontconfig " $XDG_CONFIG_HOME " /fontconfig ;;
147+ * ) install_dir__sync dots-extra/fontsets/$FONTSET_DIR_NAME " $XDG_CONFIG_HOME " /fontconfig ;;
92148 esac ;;
93149esac
94150
95151# For Hyprland
96152case " ${SKIP_HYPRLAND} " in
97153 true) sleep 0;;
98154 * )
99- if ! [ -d " $XDG_CONFIG_HOME " /hypr ]; then v mkdir -p " $XDG_CONFIG_HOME " /hypr ; fi
100- warning_rsync_delete; v rsync -av --delete dots/.config/hypr/hyprland/ " $XDG_CONFIG_HOME " /hypr/hyprland/
155+ install_dir__sync dots/.config/hypr/hyprland " $XDG_CONFIG_HOME " /hypr/hyprland
101156 for i in hypr{land,lock}.conf {monitors,workspaces}.conf ; do
102- copy_file_s_t " dots/.config/hypr/$i " " ${XDG_CONFIG_HOME} /hypr/$i "
157+ install_file__auto_backup " dots/.config/hypr/$i " " ${XDG_CONFIG_HOME} /hypr/$i "
103158 done
104159 for i in hypridle.conf ; do
105160 if [[ " ${INSTALL_VIA_NIX} " == true ]]; then
106- copy_file_s_t " dots-extra/via-nix/$i " " ${XDG_CONFIG_HOME} /hypr/$i "
161+ install_file__auto_backup " dots-extra/via-nix/$i " " ${XDG_CONFIG_HOME} /hypr/$i "
107162 else
108- copy_file_s_t " dots/.config/hypr/$i " " ${XDG_CONFIG_HOME} /hypr/$i "
163+ install_file__auto_backup " dots/.config/hypr/$i " " ${XDG_CONFIG_HOME} /hypr/$i "
109164 fi
110165 done
111166 if [ " $OS_GROUP_ID " = " fedora" ]; then
112167 v bash -c " printf \" # For fedora to setup polkit\nexec-once = /usr/libexec/kf6/polkit-kde-authentication-agent-1\n\" >> ${XDG_CONFIG_HOME} /hypr/hyprland/execs.conf"
113168 fi
114169
115- copy_dir_s_t " dots/.config/hypr/custom" " ${XDG_CONFIG_HOME} /hypr/custom"
170+ install_dir__skip_existed " dots/.config/hypr/custom" " ${XDG_CONFIG_HOME} /hypr/custom"
116171 ;;
117172esac
118- declare -a arg_excludes=()
119173
120- # some foldes (eg. .local/bin) should be processed separately to avoid `--delete' for rsync,
121- # since the files here come from different places, not only about one program.
122- # v rsync -av "dots/.local/bin/" "$XDG_BIN_HOME" # No longer needed since scripts are no longer in ~/.local/bin
123- v cp -f " dots/.local/share/icons/illogical-impulse.svg" " ${XDG_DATA_HOME} " /icons/illogical-impulse.svg
174+ install_file " dots/.local/share/icons/illogical-impulse.svg" " ${XDG_DATA_HOME} " /icons/illogical-impulse.svg
124175
125- v touch " ${FIRSTRUN_FILE} "
176+ v dedup_and_sort_listfile " ${INSTALLED_LISTFILE} " " ${INSTALLED_LISTFILE} "
177+ v gen_firstrun
0 commit comments