-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·93 lines (76 loc) · 2.15 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
export XDG_CONFIG_HOME="$HOME/.config"
section_prefix="=> "
run_confirm() {
read -p "$section_prefix$1? (y/n): " run_confirm_result
if [[ $run_confirm_result == 'y' || $run_confirm_result == 'Y' ]]; then
return 0
else
echo " Skip $1."
echo ""
return 1
fi
}
append_to_file() {
if ! grep -q $1 $3 ; then
echo $2 >> $3
fi
}
# OS Init.
# -----------------------------------------------------------------------------
if run_confirm "Execute OS setup scripts"; then
$PWD/os/setup.sh
fi
# Customized bin.
# -----------------------------------------------------------------------------
if run_confirm "Copy customized bins to ~/.local/bin"; then
[ ! -d ~/.local/bin ] && mkdir ~/.local/bin
for f in `ls -a $PWD/bin/`;
do
ln -s $PWD/bin/$f ~/.local/bin/$f > /dev/null 2>&1
done
fi
# Configs
# ----------------------------------------------------------------------------
# backup
backup_file=$HOME/.config.bak-$(date '+%Y-%m-%d_%H:%M:%S')
if [ -d $XDG_CONFIG_HOME ]; then
echo $section_prefix"Backuping..."
find ~/.config -maxdepth 1 \
-not -name 'nvm' \
| grep -Ev "$HOME/.config$" \
| xargs -I{} cp -r {} $backup_file/
echo " Backuped, dir: $backup_file"
echo ""
fi
# copy cfgs to ~/.config
if run_confirm "Copy cfgs to ~/.config"; then
for cfg in `ls cfg | awk '{print $1}'`;
do
xdg_cfg=$XDG_CONFIG_HOME/$cfg
rm -rf $xdg_cfg
cfg_dir=$PWD/cfg/$cfg
cfg_init="$cfg_dir/.init.sh"
if [ -f $cfg_init ]; then
chmod +x $cfg_init
$cfg_init
else
ln -sfv $cfg_dir $xdg_cfg
fi
done
fi
# Profiles
# -----------------------------------------------------------------------------
if run_confirm "Update profiles.d"; then
rm -r $XDG_CONFIG_HOME/profiles.d
ln -sfv $PWD/profiles.d $XDG_CONFIG_HOME/profiles.d
fi
if [ -f ~/.zshrc ]; then
append_to_file "^source.*profiles.d/main$" "source ~/.config/profiles.d/main" ~/.zshrc
append_to_file "source.*fzf.zsh$" "[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh" ~/.zshrc
else
echo "~/.zshrc not found."
fi
if [ -f ~/.zlogin ]; then
append_to_file "^source.*profiles.d/main$" "source ~/.config/profiles.d/main" ~/.zlogin
fi