-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.sh
executable file
·112 lines (86 loc) · 2.41 KB
/
bootstrap.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
#!/usr/bin/env bash
#
# Thanks to Gianni Chiappetta (https://github.com/gf3/dotfiles)
#-----------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------
# Notice title
notice() { echo -e "\033[1;32m=> $1\033[0m"; }
# Error title
error() { echo -e "\033[1;31m=> Error: $1\033[0m"; }
# List item
c_list() { echo -e " \033[1;32m✔\033[0m $1"; }
# Error list item
e_list() { echo -e " \033[1;31m✖\033[0m $1"; }
# Check for dependency
dep() {
type -p $1 &> /dev/null
local installed=$?
if [ $installed -eq 0 ]; then
c_list $1
else
e_list $1
fi
return $installed
}
backup() {
mkdir -p $backupdir
rsync -az --exclude-from=EXCLUDE $HOME/ $backupdir/
}
install() {
rsync -az --exclude-from=EXCLUDE . $HOME
}
#-----------------------------------------------------------------------------
# Initialize
#-----------------------------------------------------------------------------
backupdir="$HOME/.dotfiles-bak/$(date "+%Y%m%d%H%M.%S")"
dependencies=(git zsh rsync)
#-----------------------------------------------------------------------------
# Dependencies
#-----------------------------------------------------------------------------
notice "Checking dependencies"
not_met=0
for need in "${dependencies[@]}"; do
dep $need
met=$?
not_met=$(echo "$not_met + $met" | bc)
done
if [ $not_met -gt 0 ]; then
error "$not_met dependencies not met!"
exit 1
fi
#-----------------------------------------------------------------------------
# Install
#-----------------------------------------------------------------------------
# Assumes $HOME/.dotfiles is *ours*
if [ -d $HOME/.dotfiles ]; then
pushd $HOME/.dotfiles
# Update Repo
notice "Updating"
git pull origin facelift
git submodule init
git submodule update
# Backup
notice "Backup up old files ($backupdir)"
backup
# Install
notice "Installing"
install
else
# Clone Repo
notice "Downloading"
git clone -b facelift --recursive git://github.com/augustash/serverdots.git $HOME/.dotfiles
pushd $HOME/.dotfiles
# Backup
notice "Backup up old files ($backupdir)"
backup
# Install
notice "Installing"
install
fi
#-----------------------------------------------------------------------------
# Finished
#-----------------------------------------------------------------------------
popd
notice "Done"
exec $SHELL -l