-
Notifications
You must be signed in to change notification settings - Fork 5
/
bootstrap.sh
executable file
·88 lines (71 loc) · 1.54 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
#! /bin/sh
set -e
DOTFILES_URL='https://github.com/Julian/dotfiles.git'
DOTFILES_DEST=$HOME/.dotfiles
if [ -z "$DOTFILES_DEBUG" ]; then
verbosity='--quiet'
fi
main()
{
clone_dotfiles
continue_with_install
}
clone_dotfiles()
{
echo 'Setting up the dotfiles repo.'
if [ ! -d $DOTFILES_DEST ]; then
setup
echo "Cloning $DOTFILES_URL into $DOTFILES_DEST..."
ensure_installed git
(
git clone $verbosity $DOTFILES_URL $DOTFILES_DEST
cd $DOTFILES_DEST
git submodule $verbosity init
git submodule $verbosity update
)
else
echo "Existing dotfiles found in $DOTFILES_DEST."
fi
}
setup()
{
if [ "$OSTYPE" = darwin* ]; then
ensure_has_homebrew
fi
}
ensure_has_homebrew()
{
printf 'Checking for homebrew... '
bin_exists brew && printf 'found\n' || {
printf 'installing\n'
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
}
}
bin_exists()
{
command -v $1 >/dev/null 2>&1
}
check_installed()
{
if bin_exists brew; then
brew list | grep "\b$1\b" >/dev/null
elif bin_exists dpkg-query; then
[ "`dpkg-query -W -f='${Status}\n' $1`" = 'install ok installed' ]
fi
}
ensure_installed()
{
for package; do
check_installed $package || install $package
done
}
install()
{
printf "Installing $@..."
sudo apt-get install $verbosity --yes --force-yes $@
printf 'done\n'
}
continue_with_install()
{
exec $DOTFILES_DEST/install
}