-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall
More file actions
executable file
·114 lines (90 loc) · 2.49 KB
/
install
File metadata and controls
executable file
·114 lines (90 loc) · 2.49 KB
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
113
114
#!/usr/bin/env bash
#
# Install and setup dotfiles.
#
# Copyright (C) 2022 Rafael Cavalcanti <https://rafaelc.org/dev>
# Licensed under GPLv3
set -euo pipefail
declare -ar deps=(git rsync)
readonly remote_repo="https://github.com/rc2dev/dotfiles.git"
readonly local_repo="$HOME/.local/share/dotfiles/repo.git"
printf '
_ _ __ _ _
__| | ___ | |_ / _(_) | ___ ___
/ _` |/ _ \| __| |_| | |/ _ \/ __|
| (_| | (_) | |_| _| | | __/\__ \
\__,_|\___/ \__|_| |_|_|\___||___/
This will install the dotfiles to the user.
Remote URL: %s
--------------------------------------------
' "$remote_repo"
dotfiles() {
git --git-dir="$local_repo" --work-tree="$HOME" "$@"
}
log() {
printf "%s\n" "$*" 1>&2
}
main() {
cd "$HOME"
check_deps
clone_repo
config_repo
setup_sparse_checkout
setup_submodules
enable_services
}
check_deps() {
for dep in "${deps[@]}"; do
if ! command -v "$dep" > /dev/null; then
log "Please install the dependency before proceeding: $dep"
exit 1
fi
done
}
clone_repo() {
if [[ -d "$local_repo" ]]; then
log "Repo is already cloned: $local_repo"
return
fi
log "Cloning repo..."
local -r tmp_dest="$(mktemp -d)"
trap 'rm -rf "$tmp_dest"' EXIT
mkdir -p "$(dirname "$local_repo")"
# Clone first to a temporary dir, or git will fail on a non-empty home.
git clone --separate-git-dir="$local_repo" "$remote_repo" "$tmp_dest"
rsync --recursive --links --exclude '.git' "$tmp_dest/" "$HOME/"
}
config_repo() {
log "Setting worktree..."
dotfiles config core.worktree "$HOME"
log "Setting path for repository config..."
local -r config_path="$HOME/.config/dotfiles/config"
if [[ ! -e "$config_path" ]]; then
log "Config not found at $config_path. Exiting..."
exit 1
fi
dotfiles config include.path "$config_path"
}
setup_sparse_checkout() {
# Hide README and LICENSE
log "Setting sparse checkout..."
dotfiles config core.sparseCheckout true
printf "/*\n!README.md\n!LICENSE\n" > "$local_repo/info/sparse-checkout"
dotfiles read-tree -mu HEAD
}
setup_submodules() {
# Necessary if submodule remote url changes
log "Syncing submodules if already present..."
dotfiles submodule sync
log "Initializing submodules..."
dotfiles submodule update --init --recursive
}
enable_services() {
case $(hostname) in
rd|x220)
log "Enabling system user units for rd or x220..."
systemctl --user enable ssh-agent.service
;;
esac
}
main "$@"