2.6 KiB
It looks like you are setting up a project environment and configuring services using bash scripts. Your script contains steps to clone repositories, switch branches, copy files, set permissions, create directories, install dependencies, and start services.
To improve readability and maintainability, you can consider the following suggestions:
-
Modularize your Script:
- Separate different sets of tasks into functions for better organization.
- Using functions can help with code reuse and make each part of the script easier to understand.
-
Error Handling:
- Implement proper error handling and informative messages for critical steps.
- Consider using `trap` to catch and handle errors gracefully.
-
Logging:
- Add logging statements to track the script execution flow and display informative messages.
-
Consistent Variable Naming:
- Ensure consistency in variable names and use descriptive names for clarity.
-
Comments and Documentation:
- Add comments to explain complex logic or processes in the script.
- Consider adding a header comment to describe the purpose of the script, its inputs, and expected outputs.
-
Configuration Management:
- Consider using configuration files to store variables and settings that may need to change without modifying the script itself.
Here is an example structure to illustrate these suggestions:
```bash #!/bin/bash set -e set -x
ROOT="/mnt/data1/swarms" WORKSOURCE="${ROOT}/opt/swarms/api"
git_clone_or_update() { local repo_url=$1 local target_dir=$2
if [ ! -d "$target_dir" ]; then git clone "$repo_url" "$target_dir" else pushd "$target_dir" || exit 1 git pull popd || exit 2 fi }
git_clone_or_update "https://github.com/jmikedupont2/swarms" "${ROOT}/opt/swarms"
pushd "${ROOT}/opt/swarms/" || exit 1 git checkout feature/ec2 git pull local feature/ec2 popd || exit 2
git_clone_or_update "https://github.com/The-Swarm-Corporation/swarms-memory" "${ROOT}/opt/swarms-memory"
mkdir -p "${ROOT}/var/run/uvicorn/env/"
if [ ! -f "${ROOT}/var/run/uvicorn/env/" ]; then virtualenv "${ROOT}/var/run/uvicorn/env/" fi
. "${ROOT}/var/run/uvicorn/env/bin/activate" pip install uvicorn
systemctl daemon-reload systemctl start swarms-uvicorn systemctl enable swarms-uvicorn service nginx restart