-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·86 lines (69 loc) · 2.76 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
#!/usr/bin/env bash
# install.sh
# This script sets up a development environment by configuring Bash, cloning a GitHub repository,
# adding custom scripts to the user's PATH, and preparing the environment specifically for GitHub Codespaces.
# It also ensures that .bashrc sources all files in .bashrc.d.
# Function to configure .bashrc.d directory and ensure sourcing in .bashrc
config_bashrc_d() {
echo "Configuring bashrc.d and ensuring it's sourced in .bashrc"
if [ ! -e "$HOME/.bashrc" ]; then
touch "$HOME/.bashrc"
fi
if ! grep -Fq ".bashrc.d" "$HOME/.bashrc"; then
echo 'for i in $HOME/.bashrc.d/*; do [ -r "$i" ] && source "$i"; done' >> "$HOME/.bashrc"
echo ".bashrc.d sourcing added to .bashrc."
else
echo ".bashrc.d is already sourced in .bashrc."
fi
# Create the .bashrc.d directory if it doesn't exist
mkdir -p "$HOME/.bashrc.d"
echo "Completed configuring bashrc.d"
}
# Function to clone a GitHub repository
clone_repo() {
echo "Cloning GitHub repository"
# Clone the specified GitHub repository into a temporary directory
TMP_DIR=$(mktemp -d)
git clone https://github.com/SATVILab/dotfiles.git "$TMP_DIR"
echo "Successfully cloned GitHub repository SATVILab/dotfiles"
echo "Copying scripts to ~/.local/bin..."
cp -r "$TMP_DIR/scripts/"* "$HOME/.local/bin/"
rm -rf "$TMP_DIR" # Remove the temporary directory after use
echo "Scripts copied to ~/.local/bin"
}
# Function to configure the user's bin directories and update PATH
config_home_bin() {
echo "Configuring ~/bin and ~/.local/bin directories"
# Create directories if they don't exist
mkdir -p "$HOME/bin" "$HOME/.local/bin"
# Add directories to PATH if not already included
if ! [[ "$PATH" =~ (^|:)"$HOME/bin"(:|$) ]]; then
echo 'export PATH="$HOME/bin:$PATH"' >> "$HOME/.bashrc"
echo "Added '~/bin' to your PATH."
fi
if ! [[ "$PATH" =~ (^|:)"$HOME/.local/bin"(:|$) ]]; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$HOME/.bashrc"
echo "Added '~/.local/bin' to your PATH."
fi
# Source the .bashrc file to apply the changes immediately
source "$HOME/.bashrc"
echo "PATH configuration complete."
}
# Function to check for GitHub Codespaces and run additional setups
codespaces_setup() {
if [[ "$CODESPACES" == "true" ]]; then
echo "Running in a GitHub Codespace"
# Example: Replace this line with any additional script you want to run in Codespaces
# install-jetbrains-font
fi
}
# Main script execution
set -e
echo "Starting installation process..."
config_home_bin
clone_repo
config_bashrc_d
codespaces_setup
# Ensure all scripts in ~/.local/bin are executable
chmod -R 755 "$HOME/.local/bin/"
echo "Installation complete."