-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap
executable file
·74 lines (59 loc) · 2.04 KB
/
bootstrap
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
#!/bin/bash
set -eEuo pipefail
#
# Combination of bare repositories and sparse checkouts
#
# - https://github.com/diegoferigo/dotfiles/blob/main/bootstrap
# - https://www.atlassian.com/git/tutorials/dotfiles
# - https://github.blog/2020-01-17-bring-your-monorepo-down-to-size-with-sparse-checkout/
#
[[ -z $(type -p git) ]] && echo "==> git command not found" && exit 1
[[ -z $(type -p curl) ]] && echo "==> curl command not found" && exit 1
function dotfiles {
git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME $@
}
function backup {
echo "==> Backing up pre-existing dotfiles into '$1'"
dotfiles checkout 2>&1 | grep "^[[:blank:]]" | awk {'print $1'} |
xargs -i echo "dirname {}" | xargs -i bash -c "{}" | xargs -i mkdir -p $1/{}
dotfiles checkout 2>&1 | grep "^[[:blank:]]" | awk {'print $1'} |
xargs -i mv --backup=numbered $HOME/{} $1/{}
return 0
}
# Get the folder containing this script
SCRIPT=""
if [[ "$OSTYPE" == "darwin"* ]]; then
SCRIPT=$(greadlink -f $0)
else
SCRIPT=$(readlink -f $0)
fi
BOOTSTRAP_SCRIPT_DIR=$(dirname ${SCRIPT})
DOTFILES=${DOTFILES:-$HOME/.dotfiles}
GITHUB_USER=${GITHUB_USER:-ricochet}
echo "==> Cloning dotfiles bare repo"
git clone --quiet --bare --no-checkout https://github.com/${GITHUB_USER}/dotfiles.git ${DOTFILES}
echo "==> Configuring dotfiles repo"
dotfiles config status.showUntrackedFiles no
echo "==> Configuring dotfiles repo"
dotfiles config status.showUntrackedFiles no
dotfiles config --local core.sparsecheckout true
cat <<EOF >>$DOTFILES/info/sparse-checkout
/*
!.devcontainer
!.github
!bootstrap
!install.sh
!README.md
!LICENSE
!img
EOF
echo "==> Initializing dotfiles"
BACKUP_DIR=${BACKUP_DIR:-$HOME/.dotfiles_backup}
(dotfiles checkout &>/dev/null || (backup ${BACKUP_DIR} && dotfiles checkout)) || (echo "==> failed" && exit 1)
echo "==> Bootstrapping tools"
if [ -f "${BOOTSTRAP_SCRIPT_DIR}/install.sh" ]; then
bash ${BOOTSTRAP_SCRIPT_DIR}/install.sh
else
curl -fsSL https://raw.githubusercontent.com/${GITHUB_USER}/dotfiles/main/install.sh | bash
fi
echo "==> Success"