-
Notifications
You must be signed in to change notification settings - Fork 4
/
install
executable file
·174 lines (151 loc) · 4.33 KB
/
install
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
post_install_actions() {
source ~/.bashrc
}
install_home() {
local dest_dir="$HOME"
local excluded="$(basename $0) README.md install update i3-config gtk-settings.ini i3 init_tmux launch_editor vim vimrc nvim psqlrc"
local file
for file in *; do
if ! element_exists "$file" "$excluded"; then
local dest_file_name=$(basename "$file" .tpl)
local dest_file_path="$dest_dir/.$dest_file_name"
read -p "add ${dest_file_name} to home? (Y/n) " -e ADD_FILE
if [[ $ADD_FILE != "n" ]]; then
install_file "$file" "$dest_file_path"
fi
fi
done
read -p "add psqlrc config? (Y/n) " ADD_FILE
if [[ $ADD_FILE != "n" ]]; then
mkdir -p "$dest_dir/.psql"
install_file psqlrc "$dest_dir/.psqlrc"
fi
read -p "add vim config? (Y/n) " ADD_FILE
if [[ $ADD_FILE != "n" ]]; then
install_file vim "$dest_dir/.vim"
install_file vimrc "$dest_dir/.vimrc"
fi
read -p "add i3 config? (Y/n) " ADD_FILE
if [[ $ADD_FILE != "n" ]]; then
mkdir -p "$dest_dir/.config/i3"
install_file i3-config "$dest_dir/.config/i3/config"
install_file i3 "$dest_dir/.i3"
fi
if [[ -d "$dest_dir/.config/gtk-3.0" ]]; then
read -p "add gtk settings (sets system prefer dark mode for applications if system uses gtk)? (Y/n) " -e ADD_FILE
if [[ $ADD_FILE != "n" ]]; then
install_file gtk-settings.ini "$dest_dir/.config/gtk-3.0/gtk-settings.ini"
fi
fi
read -p "add tmux startup script? (Y/n) " ADD_FILE
if [[ $ADD_FILE != "n" ]]; then
install_file init_tmux "$dest_dir/init_tmux"
fi
read -p "add launch editor script? (Y/n) " ADD_FILE
if [[ $ADD_FILE != "n" ]]; then
install_file launch_editor "$dest_dir/launch_editor"
fi
read -p "add neovim? (Y/n) " ADD_FILE
if [[ $ADD_FILE != "n" ]]; then
read -p "install neovim? (y/N) " INSTALL_NIGHTLY
if [[ $INSTALL_NIGHTLY == "y" ]]; then
curl -L -o /tmp/nvim-linux64.tar.gz https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz
sudo rm -rf /opt/nvim
sudo tar -C /opt -xzf /tmp/nvim-linux64.tar.gz
rm /tmp/nvim-linux64.tar.gz
fi
if ! which node &>/dev/null; then
echo 'Node not found in path, it required to install neovim'
else
if [[ ! -d "$dest_dir/.config" ]]; then
mkdir "$dest_dir/.config"
fi
install_file nvim "$dest_dir/.nvim"
install_file nvim "$dest_dir/.config/nvim"
if ! which pnpm &>/dev/null; then
echo 'Installing pnpm'
curl -fsSL https://get.pnpm.io/install.sh | sh -
fi
if ! which prettierd &>/dev/null; then
echo 'Adding prettierd for ts/js/vue neovim formatting'
pnpm install -g @fsouza/prettierd
fi
if ! which cspell &>/dev/null; then
echo 'Adding cspell for code spelling checking'
pnpm install -g cspell
fi
if ! which shfmt &>/dev/null; then
echo 'package shfmt not found, install using local OS package manager for bash formatting'
fi
if ! which cargo &>/dev/null; then
echo 'Cargo not found, skipping rust dependencys'
else
# add rust analyzer
rustup component add rust-analyzer
fi
fi
fi
post_install_actions
}
install_file() {
local file="$1"
local dest_file_path="$2"
if [[ -e $dest_file_path ]] ||
[[ -L $dest_file_path ]]; then # Can be a broken symlink
if [[ -e $dest_file_path ]] &&
diff -q "$file" "$dest_file_path" >/dev/null; then
echo "dotfiles: identical $dest_file_path"
elif $replace_all; then
replace_file "$file" "$dest_file_path"
else
read -p "dotfiles: overwrite ${dest_file_path}? [yn] "
case $REPLY in
'y') replace_file "$file" "$dest_file_path" ;;
'n') echo "dotfiles: skipping $dest_file_path" ;;
esac
fi
else
link_file "$file" "$dest_file_path"
fi
}
replace_file() {
local file="$1"
local dest_file_path="$2"
remove "$dest_file_path"
link_file "$file" "$dest_file_path"
}
link_file() {
local file="$1"
local dest_file_path="$2"
if [[ $file =~ \.tpl$ ]]; then
echo "dotfiles: generating $dest_file_path"
bash "$file" >"$dest_file_path"
else
echo "dotfiles: linking $dest_file_path"
ln -s "$(pwd)/$file" "$dest_file_path"
fi
}
element_exists() {
local elem="$1"
shift
local arr=($@)
local i
for i in ${arr[@]}; do
if [[ $i == $elem ]]; then
return 0
fi
done
return 1
}
remove() {
local file="$1"
# Don't recursively remove symbolic links to directories,
# just real directories.
if [[ -d $file ]] && [[ ! -L $file ]]; then
rm -rf "$file"
else
rm -f "$file"
fi
}
install_home