-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
108 lines (98 loc) · 3.11 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
#!/bin/sh
scriptdir="$(dirname "$(readlink -f "$0")")"
do_mkdir() {
local dirname="$1"
# dirname 'foo' -> '.'
if [ ! "$dirname" = '.' ]; then
mkdir -p "$HOME/$dirname"
fi
}
do_symlink() {
local filename="$1"
local linkname="$HOME/$filename"
local targetname="$scriptdir/$filename"
local reltarget="$(realpath --relative-to="$(dirname "$linkname")" "$targetname")"
#echo "Symlinking ~/$filename to $targetname ($reltarget)"
echo "Symlinking ~/$filename"
if [ -f "$linkname" ]; then
if ! diff "$targetname" "$linkname" >/dev/null; then
echo "\e[33mWarning: Overwriting ~/$filename!\e[m"
echo "Creating backup as ~/$filename.save"
# TODO: Find usable name if save file already exists.
mv "$linkname" "$linkname.save"
fi
fi
ln -sf "$reltarget" "$linkname"
}
link_file() {
local filename="$1"
local mode="$2"
local dirname="$(dirname "$filename")"
# Make sure the directory exists.
do_mkdir "$dirname"
# Symlink the file.
do_symlink "$filename"
if [ ! -z "$mode" ]; then
chmod "$mode" "$filename"
fi
}
link_files() {
local dirname="$1"
local mode="$2"
# Make sure the directory exists.
do_mkdir "$dirname"
# Symlink all files.
for f in "$dirname"/*; do
[ -f "$f" ] || continue
do_symlink "$f"
if [ ! -z "$mode" ]; then
chmod "$mode" "$f"
fi
done
}
main() {
cd "$scriptdir"
local dist_id="$(lsb_release -si)"
local dist_name="$(lsb_release -sc)"
# Install only the bare minimum. Other stuff like ansible and terraform is
# only used if available.
local prereq_no_tmux='zsh git neovim jq'
local prereq="$prereq_no_tmux tmux"
if [ "$dist_id" = 'Debian' ] && [ "$dist_name" = 'bullseye' ]; then
echo "Installing prerequisites: $prereq"
sudo apt install -y $prereq # no quotes!
elif [ "$dist_id" = 'Debian' ] && [ "$dist_name" = 'buster' ]; then
echo "Installing prerequisites: $prereq"
sudo apt install -y $prereq_no_tmux # no quotes!
# tmux from buster repos is too old, install from backports.
sudo apt install -y -t "$(lsb_release -sc)-backports" tmux
else
>&2 echo '\e[33mWarning: Your distro is untested.\e[m'
read -p 'Continue anyway? [yes/no] ' reply
if [ "$reply" != 'yes' ]; then
return 1
fi
fi
link_files '.config/coreutils'
link_files '.config/git'
link_files '.config/htop'
link_files '.config/nvim'
link_files '.config/nvim/init.vim.d'
link_files '.config/postgresql'
link_files '.config/tmux'
link_files '.config/wget'
link_files '.config/zsh'
link_file '.config/zsh/.zlogin'
link_file '.config/zsh/.zlogout'
link_file '.config/zsh/.zprofile'
link_file '.config/zsh/.zshenv'
link_file '.config/zsh/.zshrc'
link_files '.config/zsh/zlogin.d'
link_files '.config/zsh/zlogout.d'
link_files '.config/zsh/zprofile.d'
link_files '.config/zsh/zshenv.d'
link_files '.config/zsh/zshrc.d'
link_file '.zshenv'
link_files '.local/bin' '+x'
}
main