-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall
More file actions
executable file
·91 lines (74 loc) · 2.75 KB
/
install
File metadata and controls
executable file
·91 lines (74 loc) · 2.75 KB
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
#!/usr/bin/env bash
set -e
# Define variables
PROFILE=${1:-default}
ENV_FILE=".env"
CUSTOM_ENV_FILE=".env.${PROFILE}"
CONFIG_FILE="install.conf.yaml"
TEMPLATE_FILE="install.conf.template.yaml"
DIR_DOTBOT="dotbot"
DIR_COMPLETE_ALIAS="complete-alias"
DOTBOT_BIN="bin/dotbot"
BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Load default (minimal) environment
if [[ -f "$ENV_FILE" ]]; then
echo "Loading default environment"
export $(grep -v '^#' "$ENV_FILE" | xargs)
fi
# Load profile-specific environment
if [[ -f "$CUSTOM_ENV_FILE" ]]; then
echo "Loading profile: $PROFILE"
export $(grep -v '^#' "$CUSTOM_ENV_FILE" | xargs)
else
echo "No profile-specific environment found for $PROFILE. Proceeding with default."
fi
# Ensure the GITCONFIG_FILE variable is defined
GITCONFIG_FILE=".gitconfig.${PROFILE}"
if [[ ! -f "$GITCONFIG_FILE" ]]; then
echo "Profile-specific .gitconfig not found. Using default."
GITCONFIG_FILE=".gitconfig.default"
fi
export GITCONFIG_FILE="${GITCONFIG_FILE}"
# Preprocess the YAML file to include or exclude Starship.toml dynamically
if [[ "$USE_NERD_FONT" == "true" ]]; then
echo "Nerd Fonts enabled. Including Starship configuration."
envsubst < "$TEMPLATE_FILE" > "$CONFIG_FILE"
else
echo "Nerd Fonts disabled. Excluding Starship configuration."
sed '/~\/\.config\/starship\.toml/d' "$TEMPLATE_FILE" | envsubst > "$CONFIG_FILE"
fi
# Install custom aliases
echo "Installing custom aliases..."
cd "${BASEDIR}"
git -C "${DIR_COMPLETE_ALIAS}" submodule sync --quiet --recursive
git submodule update --init --recursive "${DIR_COMPLETE_ALIAS}"
# Combine aliases into a single completion file
cat "${DIR_COMPLETE_ALIAS}/complete_alias" my-complete-alias > .bash_completion
# Function to remove a regular file if it exists and is not a symlink
remove_regular_file() {
local file="$1"
if [[ -f "$file" && ! -L "$file" ]]; then
echo "Removing regular file: $file"
rm -f "$file"
fi
}
# List of files to check
files_to_remove=("$HOME/.bashrc" "$HOME/.profile" "$HOME/.bash_logout" "$HOME/.ssh/config")
# Loop through each file and call the function
for file in "${files_to_remove[@]}"; do
remove_regular_file "$file"
done
# Initialize Dotbot submodule
echo "Initializing Dotbot submodule..."
cd "${BASEDIR}"
git -C "${DIR_DOTBOT}" submodule sync --quiet --recursive
git submodule update --init --recursive "${DIR_DOTBOT}"
# Run Dotbot
echo "Running Dotbot..."
"${BASEDIR}/${DIR_DOTBOT}/${DOTBOT_BIN}" -d "${BASEDIR}" -c "${CONFIG_FILE}"
# Install Starship if necessary
if [[ "$USE_NERD_FONT" == "true" && ! -x "$HOME/.local/bin/starship" ]]; then
echo "Installing Starship..."
curl -fsSL https://starship.rs/install.sh | sh -s -- --bin-dir ~/.local/bin -y
fi
echo "Dotfiles setup complete!"