-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·74 lines (61 loc) · 1.92 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
70
71
72
73
74
#!/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)
#
# Examples:
# ./install.sh
# DOTFILES_DIR="$HOME/my-dotfiles" ./install.sh
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/andrewthauer/dotfiles/main/install.sh)"
set -eo pipefail
export DOTFILES_DIR="${DOTFILES_DIR:-$HOME/.dotfiles}"
export DOTFILES_DISABLE_SUDO="${DOTFILES_DISABLE_SUDO:-0}"
clone_dotfiles() {
if [ ! -d "${DOTFILES_DIR}" ]; then
echo "Cloning dotfiles repo..."
git clone "https://github.com/andrewthauer/dotfiles.git" "$DOTFILES_DIR"
# Ensure repo is using the ssh remote
# pushd "${DOTFILES_DIR}" >/dev/null
# git remote set-url origin [email protected]:andrewthauer/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() {
echo "DOTFILES_DIR: $DOTFILES_DIR"
echo "DOTFILES_DISABLE_SUDO: $DOTFILES_DISABLE_SUDO"
# Clone and initialize dotfiles env
clone_dotfiles
# TODO: determine if we need to source this file still
# shellcheck source=lib/init.sh disable=SC1091
source "${DOTFILES_DIR}"/lib/init.sh
# Backup existing dotfiles
backup_dotfiles
# Run OS specific setup script
case "$("$DOTFILES_DIR"/bin/os-info --family)" in
"macos") "$DOTFILES_DIR/scripts/setup-macos.sh" ;;
"debian") "$DOTFILES_DIR/scripts/setup-linux.sh" ;;
*) echo "No OS specific setup script" ;;
esac
# Set default shells
"$DOTFILES_DIR/scripts/set-default-shells.sh"
}
# Run the script
main "$@"
exit 0