mirror of
https://github.com/danielmiessler/fabric
synced 2024-11-08 07:11:06 +00:00
6dff639969
- README.md - added instructions to make sure the setup.sh script was executable as this was not explicitly stated - setup.sh - updated sed to use `sed -i` to be compatible with Linux, MacOSX and other OS versions and added a check in the local directory taht setup.sh executes in for a pyproject.toml file because the script was looking for the .toml file in the user's home directory and throwing an error
72 lines
2.3 KiB
Bash
Executable File
72 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Check if pyproject.toml exists in the current directory
|
|
if [ ! -f "pyproject.toml" ]; then
|
|
echo "Poetry could not find a pyproject.toml file in the current directory or its parents."
|
|
echo "Please navigate to the project directory where pyproject.toml is located and rerun this script."
|
|
exit 1
|
|
fi
|
|
|
|
# Installs poetry-based python dependencies
|
|
echo "Installing python dependencies"
|
|
poetry install
|
|
|
|
# List of commands to check and add or update alias for
|
|
commands=("fabric" "fabric-api" "fabric-webui")
|
|
|
|
# List of shell configuration files to update
|
|
config_files=("$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.bash_profile")
|
|
|
|
# Initialize an array to hold the paths of the sourced files
|
|
source_commands=()
|
|
|
|
for config_file in "${config_files[@]}"; do
|
|
# Check if the configuration file exists
|
|
if [ -f "$config_file" ]; then
|
|
echo "Updating $config_file"
|
|
for cmd in "${commands[@]}"; do
|
|
# Get the path of the command
|
|
CMD_PATH=$(poetry run which $cmd 2>/dev/null)
|
|
|
|
# Check if CMD_PATH is empty
|
|
if [ -z "$CMD_PATH" ]; then
|
|
echo "Command $cmd not found in the current Poetry environment."
|
|
continue
|
|
fi
|
|
|
|
# Check if the config file contains an alias for the command
|
|
if grep -qE "alias $cmd=|alias $cmd =" "$config_file"; then
|
|
# Compatibility with GNU and BSD sed: Check for operating system and apply appropriate sed syntax
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
# BSD sed (macOS)
|
|
sed -i '' "/alias $cmd=/c\\
|
|
alias $cmd='$CMD_PATH'" "$config_file"
|
|
else
|
|
# GNU sed (Linux and others)
|
|
sed -i "/alias $cmd=/c\alias $cmd='$CMD_PATH'" "$config_file"
|
|
fi
|
|
echo "Updated alias for $cmd in $config_file."
|
|
else
|
|
# If not, add the alias to the config file
|
|
echo -e "\nalias $cmd='$CMD_PATH'" >>"$config_file"
|
|
echo "Added alias for $cmd to $config_file."
|
|
fi
|
|
done
|
|
# Add to source_commands array
|
|
source_commands+=("$config_file")
|
|
else
|
|
echo "$config_file does not exist."
|
|
fi
|
|
done
|
|
|
|
# Provide instruction to source the updated files
|
|
if [ ${#source_commands[@]} -ne 0 ]; then
|
|
echo "To apply the changes, please run the following command(s) in your terminal:"
|
|
for file in "${source_commands[@]}"; do
|
|
echo "source $file"
|
|
done
|
|
else
|
|
echo "No configuration files were updated. No need to source."
|
|
fi
|
|
|