-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·113 lines (93 loc) · 2.22 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
108
109
110
111
112
113
#!/usr/bin/env bash
# install.sh: Install or reinstall scripts.
# This script aims to be nearly idempotent and should be safe to run multiple times.
set -o errexit -o pipefail -o nounset
cd
PATH=$PATH:~/dotfiles/bin
DOTLINKS=(
bashrc
gitconfig
profile
tmux.conf
tmux.conf.user
zshenv
zshrc
zshrc.local
)
STOW=(
nvim-lua
)
DOTDIR_ABSOLUTE=~/dotfiles
DOTDIR=dotfiles
READLINK=readlink
DISTRO=
if [[ $OSTYPE = darwin* ]]; then
READLINK=greadlink
DISTRO=macos
elif [[ $OSTYPE = linux* ]]; then
DISTRO=$(lsb_release -si)
fi
backup_mv() {
local target
target="$1.backup$(date +%s)"
echo "NOTICE: $1 will be renamed to $target"
mv -n "$1" "$target"
}
dotlink() {
local source link
source=$1
if [[ $# -eq 2 ]]; then
link=$2
else
link=~/.${source#.}
fi
source=$DOTDIR/$source
echo "INFO: Linking $link -> $source"
if [[ -L "$link" ]]; then
local expected_target target
expected_target="$($READLINK -e "$source")"
target="$($READLINK -e "$link")"
if [[ $target = "$expected_target" ]]; then
return 0
fi
echo "NOTICE: $link points to $target. Retargeting"
backup_mv "$link"
elif [[ -e "$link" ]]; then
echo "NOTICE: $link exists. Retargeting"
backup_mv "$link"
fi
ln -s "$source" "$link"
}
stow_check_installed() {
type stow &>/dev/null && return
echo "NOTICE: stow not installed. Trying to install."
case "$DISTRO" in
Debian|Ubuntu)
sudo apt install stow
;;
macos)
brew install stow
;;
*)
echo "ERROR: Don't know how to install stow for current system: OSTYPE=$OSTYPE, DISTRO=$DISTRO"
exit 2
;;
esac
}
# Initialize dotfiles from Dropbox (could be another source)
if [[ ! -d ~/dotfiles ]]; then
echo "INFO: Creating dotfiles link"
ln -s Dropbox/dotfiles ~/
fi
# Stow: helps with complex directory structures
stow_check_installed
echo "INFO: Creating stow links"
stow -v -d ~/dotfiles/stow -t ~ -S ${STOW[@]} || {
echo "ERROR: errors encountered while running stow; continuing"
}
for item in ${DOTLINKS[@]}; do
dotlink "$item"
done
echo "INFO: Installing Python scripts"
~/dotfiles/python/deps-install
[[ -f $DOTDIR/antigen.zsh ]] || curl -L git.io/antigen > $DOTDIR/antigen.zsh