-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.zsh
executable file
·80 lines (69 loc) · 2.1 KB
/
bootstrap.zsh
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
#!/bin/zsh
#
# Start dotfiles Installation.
#
# Validate OS.
if [[ "$OSTYPE" != "darwin"* ]]; then
echo "This script is only compatible with macOS" >&2
exit 1
fi
# Determines the current user's shell.
if [[ "$SHELL" != */zsh ]]; then
echo "Please switch to zsh shell to continue."
exit 1
fi
# Path to iCloud Drive (from OS X 10.12 Sierra or later).
SW_VERS=$(sw_vers -buildVersion)
OS_VERS=$(sed -E -e 's/([0-9]{2}).*/\1/' <<< "$SW_VERS")
if [[ "$OS_VERS" -ge 16 ]]; then
export CLOUD_DOCS="${HOME}/Library/Mobile Documents/com~apple~CloudDocs"
fi
# Defines the PATHs.
ZSH_CONFIG_PATH="${ZDOTDIR:-$CLOUD_DOCS}"
DOTFILES_ROOT="${ZSH_CONFIG_PATH:-$HOME}/dotfiles"
SOURCE="https://github.com/nicolodiamante/dotfiles"
TARBALL="${SOURCE}/tarball/master"
TARGET="${DOTFILES_ROOT}"
TAR_CMD="tar -xzv -C \"${TARGET}\" --strip-components 1 --exclude .gitignore"
INSTALL="${TARGET}/utils/install.zsh"
# Check if a command is executable.
is_executable() {
command -v "$1" &> /dev/null
}
# Ensure TARGET directory doesn't already exist.
if [[ -d "$TARGET" ]]; then
echo "Target directory $TARGET already exists. Please remove or rename it and try again."
exit 1
fi
# Checks which executable is available then downloads and installs.
if is_executable "git"; then
CMD="git clone ${SOURCE} ${TARGET}"
elif is_executable "curl"; then
CMD="curl -L ${TARBALL} | ${TAR_CMD}"
elif is_executable "wget"; then
CMD="wget --no-check-certificate -O - ${TARBALL} | ${TAR_CMD}"
else
echo 'No git, curl, or wget available. Aborting!'
exit 1
fi
echo 'Installing Dotfiles...'
# Create the target directory and proceed with the chosen download method.
if ! mkdir -p "${TARGET}"; then
echo "Error: Failed to create target directory. Aborting!" >&2
exit 1
fi
# Execute the download command and run the installation script.
if eval "${CMD}"; then
if cd "${TARGET}"; then
if ! source "${INSTALL}"; then
echo "Error: Failed to run the install script. Aborting!" >&2
exit 1
fi
else
echo "Error: Failed to navigate to ${TARGET}. Aborting!" >&2
exit 1
fi
else
echo "Download failed. Aborting!" >&2
exit 1
fi