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