-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·113 lines (99 loc) · 3.03 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
# Summary
# Install & setup this dotfiles repo
#
# Usage
# ./install.sh
#
# Flags
# --target | -t <dir> The target directory for the dotfiles repo
# --setup-script | -s <path> The custom setup command to run
# --no-sudo Allow usage of sudo: 1 (no) or 0 (yes)
# --verbose | -v Enable verbose logging
#
# Environmenet Variables
# DOTFILES_HOME The target directory for the dotfiles repo
# DOTFILES_NO_SUDO Allow usage of sudo: 1 (no) or 0 (yes)
# DOTFILES_SETUP_SCRIPT The custom setup command to run
#
# Examples
# ./install.sh
# curl -fsSL https://raw.githubusercontent.com/andrewthauer/dotfiles/main/install.sh | sh
# curl -fsSL https://raw.githubusercontent.com/andrewthauer/dotfiles/main/install.sh | sh -- --target "$HOME/dotfiles"
set -eo pipefail
clone_dotfiles() {
if [ ! -d "${DOTFILES_HOME}" ]; then
echo "Cloning dotfiles repo..."
git clone "https://github.com/andrewthauer/dotfiles.git" "$DOTFILES_HOME"
fi
}
# shellcheck disable=SC2317
backup_dotfiles() {
# Rename existing dotfiles
local files=(~/.bash_profile ~/.bashrc ~/.zshenv ~/.zprofile ~/.zshrc)
# move existing files that are not symlinks
for file in "${files[@]}"; do
if [ -f "${file}" ] && [ ! -L "${file}" ]; then
mv "${file}" "${file}.old"
fi
done
}
main() {
case "$1" in
--target | -t)
DOTFILES_HOME="$2"
shift 2
;;
--setup-script | -s)
DOTFILES_SETUP_SCRIPT="$2"
shift 2
;;
--no-sudo)
DOTFILES_NO_SUDO=1
shift 1
;;
--verbose | -v)
export DOTFILES_LOG_VERBOSE="true"
shift 1
;;
*) ;;
esac
# Determine if the install is being run locally of from a curl
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
DOTFILES_HOME="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
else
DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
fi
# Defaults
export DOTFILES_HOME="${DOTFILES_HOME}"
export DOTFILES_NO_SUDO="${DOTFILES_NO_SUDO:-0}"
if [ -n "$DOTFILES_LOG_VERBOSE" ]; then
echo "DOTFILES_HOME: $DOTFILES_HOME"
echo "DOTFILES_NO_SUDO: $DOTFILES_NO_SUDO"
echo "DOTFILES_SETUP_SCRIPT: $DOTFILES_SETUP_SCRIPT"
fi
# Clone and initialize dotfiles env
clone_dotfiles
# Backup existing dotfiles
backup_dotfiles
# Add bin helpers to path
PATH="$DOTFILES_HOME/bin:$PATH"
# Use xdg spec
source "${DOTFILES_HOME}/lib/xdg.sh"
# Run custom setup script if provided
if [ -n "$DOTFILES_SETUP_SCRIPT" ]; then
"$DOTFILES_SETUP_SCRIPT"
elif [ "$REMOTE_CONTAINERS" == "true" ] || [ "$DEVPOD" == "true" ]; then
# Install as a devcontainer
"$DOTFILES_HOME/scripts/setup-devcontainer.sh"
else
# Run autodetected setup script
case "$(os-info --family)" in
"macos") "$DOTFILES_HOME/scripts/setup-macos.sh" ;;
"debian") "$DOTFILES_HOME/scripts/setup-linux.sh" ;;
*) echo "No OS specific setup script" ;;
esac
fi
}
# Run the script
main "$@"