-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·107 lines (94 loc) · 2.42 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
# usage information
usage() {
cat >&2 <<USAGE
usage: $ install.sh [-h] [-B] [-a] [-b] [-g] [-t] [-v] [-f]
-h : display usage information (this)
-B : create backups when overwriting during linking
-a : link ansible.cfg
-b : link bashrc
-g : link gitconfig
-t : link tmux.conf
-v : link vimrc
-f : link fish
example: quickly install fish, tmux, git, and vim links
./install.sh -ftgv
USAGE
}
# try to detect distribution
detect-os() {
if [[ -f /etc/os-release ]]; then
. /etc/os-release
case " $ID $ID_LIKE " in
*fedora*) echo FEDORA;;
*debian*) echo DEBIAN;;
*suse*) echo SUSE;;
*arch*) echo ARCH;;
*gentoo*) echo GENTOO;;
*) echo UNKNOWN;;
esac
else
echo UNKNOWN
fi
}
OS=$(detect-os)
echo "detected distribution: ${OS,,}"
# parse commandline options
while getopts 'hBabgtvf' flag; do
case "$flag" in
h) usage; exit 0;;
B) LNBACKUP=yes;;
a) ANSIBLE=yes;;
b) BASHRC=yes;;
g) GITCONFIG=yes;;
t) TMUX=yes;;
v) VIMRC=yes;;
f) FISH=yes;;
\?) usage; exit 1;;
esac
done
# complain if nothing given
if [[ $OPTIND -eq 1 ]]; then
echo "err: no flags given" >&2
usage
exit 1
fi
# find absolute path to this dotfiles directory
DOTFILES=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
# ---------------------------------------- #
lnargs=(-s -f -v)
if [[ $LNBACKUP == yes ]]; then lnargs+=(-b); fi
link() { ln "${lnargs[@]}" "$@"; }
if [[ $ANSIBLE == yes ]]; then
link "$DOTFILES/ansible/ansible.cfg" /etc/ansible/ansible.cfg
fi
if [[ $BASHRC == yes ]]; then
BASHRC="$DOTFILES/bash/bashrc"
case $OS in
DEBIAN|SUSE|ARCH) link "$BASHRC" /etc/bash.bashrc;;
GENTOO) link "$BASHRC" /etc/bash/bashrc;;
*) link "$BASHRC" /etc/bashrc;;
esac
link "$DOTFILES/bash/dot-bashrc" /etc/skel/.bashrc
fi
if [[ $FISH == yes ]]; then
for dir in completions conf.d functions; do
if [[ -d /etc/fish/$dir ]] && ! [[ -L /etc/fish/$dir ]]; then
rmdir -v "/etc/fish/$dir"
link "$DOTFILES/fish/$dir/" /etc/fish/$dir
fi
done
fi
if [[ $GITCONFIG == yes ]]; then
link "$DOTFILES/git/gitconfig" /etc/gitconfig
fi
if [[ $TMUX == yes ]]; then
link "$DOTFILES/tmux/tmux.conf" /etc/tmux.conf
fi
if [[ $VIMRC == yes ]]; then
VIMRC="$DOTFILES/vim/vimrc"
case $OS in
DEBIAN|GENTOO) link "$VIMRC" /etc/vim/vimrc;;
*) link "$VIMRC" /etc/vimrc;;
esac
fi