-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.sh
executable file
·98 lines (79 loc) · 1.96 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
#!/usr/bin/env bash
set -e
DOTFILES_ROOT=$(pwd -P)
create_workspace_directory()
{
mkdir -p ~/workspace
}
install_homebrew()
{
if test ! $(which brew); then
echo "Installing Homebrew..."
/bin/bash -c $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)
else
echo "Updating Homebrew..."
brew update
fi
}
symlink_dotfiles () {
echo "Symlinking dotfiles..."
local overwrite_all=false backup_all=false skip_all=false
for source in $(find -H $DOTFILES_ROOT -maxdepth 2 -name "*.symlink")
do
local name=$(basename "${source%.*}")
local dest="$HOME/.${name//_//}"
mkdir -p $(dirname "${dest}")
if [[ -f $dest ]] || [[ -d $dest ]] || [[ -L $dest ]]; then
local overwrite=false backup=false skip=false
if [[ $overwrite_all == "false" ]] && [[ $backup_all == "false" ]] && [[ $skip_all == "false" ]]; then
local current_source=$(readlink $dest)
if [[ $current_source == $source ]]; then
skip=true;
else
echo "File already exists: $dest ($(basename "$source")) - what do you want to do? [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all, [s]kip, [S]kip all"
read -n 1 action
case $action in
o )
overwrite=true;;
O )
overwrite_all=true;;
b )
backup=true;;
B )
backup_all=true;;
s )
skip=true;;
S )
skip_all=true;;
* )
;;
esac
fi
fi
if [[ $overwrite_all == "true" ]] || [[ $overwrite == "true" ]]; then
rm -rf $dest
fi
if [[ $backup_all == "true" ]] || [[ $backup == "true" ]]; then
mv $dest "${dest}.backup"
fi
if [[ $skip_all == "false" ]] && [[ $skip == "false" ]]; then
ln -s $source $dest
fi
else
ln -s $source $dest
fi
done
}
run_installers()
{
source bin/dot | while read -r data; do echo $data; done
}
authenticate_github_cli()
{
gh auth login
}
create_workspace_directory
install_homebrew
symlink_dotfiles
run_installers
authenticate_github_cli