-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·69 lines (55 loc) · 1.71 KB
/
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
65
66
67
68
69
#!/usr/bin/env bash
# Summary:
# Install & setup this dotfiles repo
#
# Usage:
# ./install.sh
#
# Environmenet Variables:
# DOTFILES_DIR The target directory for the dotfiles repo
# DOTFILES_DISABLE_SUDO Allow usage of sudo: 1 (no) or 0 (yes)
# DOTFILES_LOGGING Enable logging: 1 (yes) or 0 (no)
#
# Examples:
# ./install.sh
# DOTFILES_DIR="$HOME/my-dotfiles" ./install.sh
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/troponaut/dotfiles/main/install.sh)"
set -eo pipefail
export DOTFILES_DIR="${DOTFILES_DIR:-$HOME/.dotfiles}"
export DOTFILES_BIN="$DOTFILES_DIR/bin"
export DOTFILES_DISABLE_SUDO="${DOTFILES_DISABLE_SUDO:-0}"
export DOTFILES_LOGGING="${DOTFILES_LOGGING:-0}"
# Source the logging script
source "$DOTFILES_DIR/lib/logging.sh"
clone_dotfiles() {
if [ ! -d "${DOTFILES_DIR}" ]; then
git clone "https://github.com/troponaut/dotfiles.git" "$DOTFILES_DIR"
# Ensure repo is using the ssh remote
# pushd "${DOTFILES_DIR}" >/dev/null
# git remote set-url origin [email protected]:troponaut/dotfiles.git
# popd >/dev/null
fi
}
# shellcheck disable=SC2317
backup_dotfiles() {
# Rename existing dotfiles
local files=(~/.bash_profile ~/.bashrc ~/.zshenv ~/.zshrc)
# move existing files
for file in "${files[@]}"; do
if [ -f "${file}" ] && [ ! -L "${file}" ]; then
mv "${file}" "${file}.bak"
fi
done
}
main() {
# Clone and initialize dotfiles env
clone_dotfiles
source "${DOTFILES_DIR}"/lib/init.sh
# Backup existing dotfiles
backup_dotfiles
# Run OS specific setup script
case "$("$DOTFILES_BIN"/os-info --family)" in
"macos") "$DOTFILES_DIR/scripts/setup-macos.sh" ;;
esac
}
main "$@"