Skip to content

Commit 9fd83a2

Browse files
committed
Let 3.files.sh logs installed files
1 parent e830dc9 commit 9fd83a2

File tree

5 files changed

+94
-37
lines changed

5 files changed

+94
-37
lines changed

sdata/lib/environment-variables.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
55
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
66
XDG_STATE_HOME=${XDG_STATE_HOME:-$HOME/.local/state}
77
BACKUP_DIR=${BACKUP_DIR:-$HOME/ii-original-dots-backup}
8+
INSTALLED_LISTFILE=${INSTALLED_LISTFILE:-$XDG_CONFIG_HOME/illogical-impulse/installed_listfile}
89

910

1011
STY_RED='\e[31m'

sdata/lib/functions.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,13 @@ function ensure_cmds(){
415415
install_cmds "${not_found_cmds[@]}"
416416
fi
417417
}
418+
419+
function dedup_and_sort_listfile(){
420+
if test -f "$1"; then
421+
echo "File not found: $1" >&2; return 2
422+
else
423+
temp="$(mktemp)"
424+
sort -u -- "$1" > "$temp"
425+
mv -f -- "$temp" "$2"
426+
fi
427+
}

sdata/subcmd-install/3.files-exp.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,16 @@ for pattern in "${patterns[@]}"; do
217217
case "$mode" in
218218
"sync")
219219
if [[ -d "$from" ]]; then
220-
warning_rsync_delete
220+
warning_overwrite
221221
v rsync -av --delete "${excludes[@]}" "$from/" "$to/"
222222
else
223-
warning_rsync_normal
223+
warning_overwrite
224224
# For files, don't use trailing slash and don't use --delete
225225
v rsync -av "${excludes[@]}" "$from" "$to"
226226
fi
227227
;;
228228
"soft")
229-
warning_rsync_normal
229+
warning_overwrite
230230
if [[ -d "$from" ]]; then
231231
v rsync -av "${excludes[@]}" "$from/" "$to/"
232232
else

sdata/subcmd-install/3.files-legacy.sh

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,94 @@
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

3995
case "${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
;;
69125
esac
70126

71127
case "${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
;;
77133
esac
78134

79135
case "${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
;;
84140
esac
85141

86142
case "${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;;
93149
esac
94150

95151
# For Hyprland
96152
case "${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
;;
117172
esac
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

sdata/subcmd-install/3.files.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@ printf "${STY_CYAN}[$0]: 3. Copying config files\n${STY_RST}"
44

55
# shellcheck shell=bash
66

7-
function warning_rsync_delete(){
7+
function warning_overwrite(){
88
printf "${STY_YELLOW}"
9-
printf "The command below uses --delete for rsync which overwrites the destination folder.\n"
10-
printf "${STY_RST}"
11-
}
12-
13-
function warning_rsync_normal(){
14-
printf "${STY_YELLOW}"
15-
printf "The command below uses rsync which overwrites the destination.\n"
9+
printf "The command below overwrites the destination.\n"
1610
printf "${STY_RST}"
1711
}
1812

0 commit comments

Comments
 (0)