-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·81 lines (71 loc) · 1.85 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
#!/usr/bin/env bash
get_os() {
local -r os="$(sed -n 's,^NAME=['\'\"']\(.*\)['\'\"'],\1,p' /etc/os-release)"
if [ -z "$os" ]; then
echo >&2 "Error: OS type not found"
exit 1
fi
echo "$os"
}
configure() {
CONF_USER=(
['home/.vim/colors/xoria256.vim']="$HOME/.vim/colors/xoria256.vim"
['home/.bash_logout']="$HOME/.bash_logout"
['home/.bash_profile']="$HOME/.bash_profile"
['home/.bashrc']="$HOME/.bashrc"
['home/.profile']="$HOME/.profile"
['home/.tmux.conf']="$HOME/.tmux.conf"
['home/.vimrc']="$HOME/.vimrc"
)
case "$OS" in
'Gentoo')
CONF_ROOT+=(
['etc/bashrc.d/aliases.sh']='/etc/bash/bashrc.d/aliases.sh'
['etc/bashrc.d/env.sh']='/etc/bash/bashrc.d/env.sh'
['etc/bashrc.d/functions.sh']='/etc/bash/bashrc.d/functions.sh'
['etc/bashrc.d/prompt.sh']='/etc/bash/bashrc.d/prompt.sh'
)
;;
'Fedora'|'Ubuntu'|'Linux Mint')
CONF_ROOT+=(
['etc/bashrc.d/aliases.sh']='/etc/profile.d/Z99-aliases.sh'
['etc/bashrc.d/env.sh']='/etc/profile.d/Z99-env.sh'
['etc/bashrc.d/functions.sh']='/etc/profile.d/Z99-functions.sh'
['etc/bashrc.d/prompt.sh']='/etc/profile.d/Z99-prompt.sh'
)
;;
*)
echo >&2 "Error: OS '$OS' unknown"
exit 1
;;
esac
}
copy_dotfiles() {
cd "$(dirname "$0")"
echo 'Home:'
echo '-----'
for i in "${!CONF_USER[@]}"; do
if ! cmp --quiet "$i" "${CONF_USER[$i]}"; then
mkdir -p "$(dirname "${CONF_USER[$i]}")"
cp -riv --preserve=timestamps -- "$i" "${CONF_USER[$i]}"
fi
done
echo
echo 'Root:'
echo '-----'
if sudo true; then
for i in "${!CONF_ROOT[@]}"; do
if ! cmp --quiet "$i" "${CONF_ROOT[$i]}"; then
sudo mkdir -p "$(dirname "${CONF_ROOT[$i]}")"
sudo cp -riv --preserve=timestamps -- "$i" "${CONF_ROOT[$i]}"
fi
done
else
echo >&2 "Error: Couldn't sudo"
exit 1
fi
}
declare -r OS="$(get_os)"
declare -A CONF_USER CONF_ROOT
configure
copy_dotfiles