-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·38 lines (32 loc) · 1.12 KB
/
install.sh
File metadata and controls
executable file
·38 lines (32 loc) · 1.12 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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_URL="${REPO_URL:-${CHEZMOI_REPO_URL:-}}"
if [ -z "$REPO_URL" ] && command -v git >/dev/null 2>&1; then
REPO_URL="$(git -C "$SCRIPT_DIR" remote get-url origin 2>/dev/null || true)"
fi
if [ -z "$REPO_URL" ]; then
printf '%s\n' "Unable to determine dotfiles repo URL." >&2
printf '%s\n' "Set REPO_URL (or CHEZMOI_REPO_URL) and rerun." >&2
printf '%s\n' "Example SSH: REPO_URL='git@github.com:<user>/dotfiles.git' ./install.sh" >&2
printf '%s\n' "Example HTTPS: REPO_URL='https://github.com/<user>/dotfiles.git' ./install.sh" >&2
exit 1
fi
BRANCH="${BRANCH:-}"
if ! command -v chezmoi >/dev/null 2>&1; then
if command -v brew >/dev/null 2>&1; then
brew install chezmoi
else
if [ -n "$BRANCH" ]; then
sh -c "$(curl -fsLS get.chezmoi.io)" -- init --apply "$REPO_URL" --branch "$BRANCH"
else
sh -c "$(curl -fsLS get.chezmoi.io)" -- init --apply "$REPO_URL"
fi
exit 0
fi
fi
if [ -n "$BRANCH" ]; then
chezmoi init --apply "$REPO_URL" --branch "$BRANCH"
else
chezmoi init --apply "$REPO_URL"
fi