Merge pull request #118 from mikeprivette/main

Enhanced Setup Script Compatibility and Reliability Improvements
This commit is contained in:
Daniel Miessler 2024-02-20 09:22:28 -08:00 committed by GitHub
commit 373d362d35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 19 deletions

View File

@ -146,7 +146,13 @@ git clone https://github.com/danielmiessler/fabric.git
cd fabric cd fabric
``` ```
4. Install poetry 4. Ensure the `setup.sh` script is executable. If you're not sure, you can make it executable by running the following command:
```bash
chmod +x setup.sh
```
5. Install poetry
ref.: https://python-poetry.org/docs/#installing-with-the-official-installer ref.: https://python-poetry.org/docs/#installing-with-the-official-installer
@ -154,7 +160,7 @@ ref.: https://python-poetry.org/docs/#installing-with-the-official-installer
curl -sSL https://install.python-poetry.org | python3 - curl -sSL https://install.python-poetry.org | python3 -
``` ```
5. Run the `setup.sh`, which will do the following: 6. Run the `setup.sh`, which will do the following:
- Installs python dependencies. - Installs python dependencies.
- Creates aliases in your OS. It should update `~/.bashrc`, `/.zshrc`, and `~/.bash_profile` if they are present in your file system. - Creates aliases in your OS. It should update `~/.bashrc`, `/.zshrc`, and `~/.bash_profile` if they are present in your file system.
@ -162,9 +168,9 @@ curl -sSL https://install.python-poetry.org | python3 -
./setup.sh ./setup.sh
``` ```
6. Restart your shell to reload everything. 7. Restart your shell to reload everything.
7. Set your `OPENAI_API_KEY`. 8. Set your `OPENAI_API_KEY`.
```bash ```bash
fabric --setup fabric --setup
@ -172,7 +178,7 @@ fabric --setup
You'll be asked to enter your OpenAI API key, which will be written to `~/.config/fabric/.env`. Patterns will then be downloaded from Github, which will take a few moments. You'll be asked to enter your OpenAI API key, which will be written to `~/.config/fabric/.env`. Patterns will then be downloaded from Github, which will take a few moments.
8. Now you are up and running! You can test by pulling the help. 9. Now you are up and running! You can test by pulling the help.
```bash ```bash
# Making sure the paths are set up correctly # Making sure the paths are set up correctly

View File

@ -1,5 +1,12 @@
#!/bin/bash #!/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 # Installs poetry-based python dependencies
echo "Installing python dependencies" echo "Installing python dependencies"
poetry install poetry install
@ -8,10 +15,10 @@ poetry install
commands=("fabric" "fabric-api" "fabric-webui") commands=("fabric" "fabric-api" "fabric-webui")
# List of shell configuration files to update # List of shell configuration files to update
config_files=(~/.bashrc ~/.zshrc ~/.bash_profile) config_files=("$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.bash_profile")
# Initialize an empty string to hold the path of the sourced file # Initialize an array to hold the paths of the sourced files
source_command="" source_commands=()
for config_file in "${config_files[@]}"; do for config_file in "${config_files[@]}"; do
# Check if the configuration file exists # Check if the configuration file exists
@ -19,12 +26,25 @@ for config_file in "${config_files[@]}"; do
echo "Updating $config_file" echo "Updating $config_file"
for cmd in "${commands[@]}"; do for cmd in "${commands[@]}"; do
# Get the path of the command # Get the path of the command
CMD_PATH=$(poetry run which $cmd) 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 # Check if the config file contains an alias for the command
if grep -q "alias $cmd=" "$config_file"; then if grep -qE "alias $cmd=|alias $cmd =" "$config_file"; then
# Replace the existing alias with the new one # 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" sed -i "/alias $cmd=/c\alias $cmd='$CMD_PATH'" "$config_file"
fi
echo "Updated alias for $cmd in $config_file." echo "Updated alias for $cmd in $config_file."
else else
# If not, add the alias to the config file # If not, add the alias to the config file
@ -32,17 +52,19 @@ for config_file in "${config_files[@]}"; do
echo "Added alias for $cmd to $config_file." echo "Added alias for $cmd to $config_file."
fi fi
done done
# Set source_command to source the updated file # Add to source_commands array
source_command="source $config_file" source_commands+=("$config_file")
else else
echo "$config_file does not exist." echo "$config_file does not exist."
fi fi
done done
# Provide instruction to source the updated file # Provide instruction to source the updated files
if [ ! -z "$source_command" ]; then if [ ${#source_commands[@]} -ne 0 ]; then
echo "To apply the changes, please run the following command in your terminal:" echo "To apply the changes, please run the following command(s) in your terminal:"
echo "$source_command" for file in "${source_commands[@]}"; do
echo "source $file"
done
else else
echo "No configuration files were updated. No need to source." echo "No configuration files were updated. No need to source."
fi fi