You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.6 KiB
80 lines
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:
|
|
|
|
1. **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.
|
|
|
|
2. **Error Handling:**
|
|
- Implement proper error handling and informative messages for critical steps.
|
|
- Consider using `trap` to catch and handle errors gracefully.
|
|
|
|
3. **Logging:**
|
|
- Add logging statements to track the script execution flow and display informative messages.
|
|
|
|
4. **Consistent Variable Naming:**
|
|
- Ensure consistency in variable names and use descriptive names for clarity.
|
|
|
|
5. **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.
|
|
|
|
6. **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
|
|
|
|
# Global variables
|
|
ROOT="/mnt/data1/swarms"
|
|
WORKSOURCE="${ROOT}/opt/swarms/api"
|
|
|
|
# Function to clone or update a git repository
|
|
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
|
|
}
|
|
|
|
# Ensure swarms repository is cloned
|
|
git_clone_or_update "https://github.com/jmikedupont2/swarms" "${ROOT}/opt/swarms"
|
|
|
|
# Switch to a specific branch
|
|
pushd "${ROOT}/opt/swarms/" || exit 1
|
|
git checkout feature/ec2
|
|
git pull local feature/ec2
|
|
popd || exit 2
|
|
|
|
# Ensure swarms-memory repository is cloned
|
|
git_clone_or_update "https://github.com/The-Swarm-Corporation/swarms-memory" "${ROOT}/opt/swarms-memory"
|
|
|
|
# Other setup steps go here...
|
|
|
|
# Additional set up for uvicorn and nginx
|
|
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
|
|
|
|
# Start services
|
|
systemctl daemon-reload
|
|
systemctl start swarms-uvicorn
|
|
systemctl enable swarms-uvicorn
|
|
service nginx restart
|