-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote-install.sh
executable file
·64 lines (51 loc) · 1.41 KB
/
remote-install.sh
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
#!/usr/bin/env bash
SOURCE="https://github.com/ceiphr/dotfiles.git"
TARGET="/tmp/dotfiles"
if [[ "$CI" ]]; then
TARGET="$HOME/.dotfiles"
fi
# For echo -e color support.
TXT_DEFAULT='\033[0m'
TXT_GREEN='\033[0;32m'
TXT_RED='\033[0;31m'
# https://no-color.org/
if [[ -n "${NO_COLOR}" ]]; then
TXT_DEFAULT='\033[0m'
TXT_GREEN='\033[0m'
TXT_RED='\033[0m'
fi
# Clean up after ourselves.
function install_reset() {
unset -f handle_sigint error install_reset
}
# In case the user quits the program in the critical section, we can
# simply unlock the section before exiting.
function handle_sigint() {
install_reset
exit 1
}
trap 'handle_sigint' INT
# Error handling and cleanup.
# Usage: echo "Hello world!" || error "Error message"
function error() {
echo -e "${TXT_RED}!${TXT_DEFAULT} $1"
echo -e "${TXT_RED}!${TXT_DEFAULT} Exiting."
install_reset
exit 1
}
if [[ -x "$(command -v "git")" ]]; then
echo -e "${TXT_GREEN}>${TXT_DEFAULT} Installing dotfiles..."
CURRENT_DIR=$(pwd)
# Clone repository
rm -rf "$TARGET"
git clone $SOURCE "$TARGET"
# Run bootstrap script
cd "$TARGET" || error "Error changing directory to $TARGET"
chmod +x bootstrap.sh
sh bootstrap.sh "$@"
# Cleanup
cd "$CURRENT_DIR" || error "Error changing directory to $CURRENT_DIR"
else
error "Required dependency 'git' not found. Please install git and try again."
fi
exit 0