-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.zsh
65 lines (56 loc) · 1.63 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
#!/bin/zsh
#
# Start Zchat Installation.
#
# Determines the current user's shell.
if [[ "$SHELL" != */zsh ]]; then
echo "Please switch to zsh shell to continue."
exit 1
fi
# Defines the PATHs.
SOURCE="https://github.com/nicolodiamante/zchat"
TARBALL="${SOURCE}/tarball/master"
TARGET="${HOME}/zchat"
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 Zchat...'
# 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