-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_minimal.sh
executable file
·139 lines (121 loc) · 3.46 KB
/
install_minimal.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
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
#!/usr/bin/env bash
# call with a prompt string or use a default
confirm()
{
read -r -p "${1:-Are you sure?} [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
# Interactively create symlinks to prevent potential damage
# $1 src, $2 dest
link_file()
{
local src="$1"
local dest="$2"
# Ensure we are linking to a existing file.
if ! [ -f $src ]
then
echo $src 'is not a file!'
exit 1
fi
if [ $src -ef $dest ]
then
# Symlink is pointing to the same file, nothing to do.
echo $dest 'is up-to-date.'
elif [ -L $dest ]
then
# Symlink exists but does not point to the same thing,
# force it to the new destination.
ln -svfT "$src" "$dest"
echo $dest 'updated.'
elif [ -e $dest ]
then
# File exists but is not a symlink, ask if we want to overwrite it.
if confirm "$dest is not a symlink, try to overwrite it anyway?"
then
ln -svfT "$src" "$dest"
fi
else
# Symlink does not exist at all, create it.
ln -svT "$src" "$dest"
fi
}
# Same function for folders
link_folder()
{
local src="$1"
local dest_dir="$2"
# Ensure we are linking to a existing folder.
if ! [ -d $src ]
then
echo $src 'is not a file!'
exit 1
fi
local dest_full="$dest_dir/`basename $src`"
if [ $src -ef $dest_full ]
then
# Symlink is pointing to the same file, nothing to do.
echo $dest_full 'is up-to-date.'
elif [ -L $dest_full ]
then
# Symlink exists but does not point to the same thing,
# force it to the new destination.
ln -svf -t "$dest_dir" "$src"
echo $dest_full 'updated.'
elif [ -e $dest_full ]
then
# File exists but is not a symlink, ask if we want to overwrite it.
if confirm "$dest_full is not a symlink, try to overwrite it anyway?"
then
ln -svf -t "$dest_dir" "$src"
fi
else
# Symlink does not exist at all, create it.
ln -sv -t "$dest_dir" "$src"
fi
}
# https://stackoverflow.com/questions/59895/how-do-i-get-the-directory-where-a-bash-script-is-located-from-within-the-script
REPO=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
echo 'Installing from' $REPO
link_file {$REPO,$HOME}/.profile
link_file {$REPO,$HOME}/.dircolors
link_file {$REPO,$HOME}/.config/user-dirs.dirs
link_file {$REPO,$HOME}/.aliases
link_file {$REPO,$HOME}/.gitconfig
if confirm "Install bash cfg?"
then
link_file {$REPO,$HOME}/.bashrc
link_file {$REPO,$HOME}/.bash_profile
fi
if confirm "Install zsh cfg?"
then
link_file {$REPO,$HOME}/.zshrc
wget -O $HOME/.zshrc_grml http://git.grml.org/f/grml-etc-core/etc/zsh/zshrc
fi
if confirm "Install vim cfg?"
then
link_folder $REPO/.vim $HOME
link_file {$REPO,$HOME}/.vimrc
mkdir -p $HOME/.vim/{backup,swap,undo,cache,autoload}
cp $REPO/{external/vim-plug/plug.vim,.vim/autoload}
vim +PlugInstall +qall
# Install powerline patched fonts
$HOME/.vim/plugged/powerline-fonts/install.sh
fi
if confirm "Install tmux cfg?"
then
link_file {$REPO,$HOME}/.tmux.conf
link_folder $REPO/.tmux $HOME
fi
if confirm "Install ranger cfg?"
then
mkdir -p $HOME/.config/ranger
link_folder $REPO/.config/ranger/colorschemes $HOME/.config/ranger
link_file {$REPO,$HOME}/.config/ranger/rc.conf
fi