✨ (install_merlin_worker.sh): enhance installation script with error handling, cross-platform compatibility for sed, and improved directory management for merlin_worker.zsh
This commit is contained in:
@@ -1,6 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
curl -s https://git.miomio.moe/mio/easyzsh/raw/branch/master/patch.sh | bash -s merlin_worker
|
# Exit on any error
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Download and execute the patch script
|
||||||
|
if ! curl -s https://git.miomio.moe/mio/easyzsh/raw/branch/master/patch.sh | bash -s merlin_worker; then
|
||||||
|
echo "Error: Failed to download or execute patch script"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if ~/.bashrc exists and contains PYTHONPATH export
|
# Check if ~/.bashrc exists and contains PYTHONPATH export
|
||||||
if [ -f "$HOME/.bashrc" ]; then
|
if [ -f "$HOME/.bashrc" ]; then
|
||||||
@@ -13,20 +20,27 @@ if [ -f "$HOME/.bashrc" ]; then
|
|||||||
# Path to the merlin_worker.zsh file
|
# Path to the merlin_worker.zsh file
|
||||||
MERLIN_CONFIG="$HOME/.config/zshrc/merlin_worker.zsh"
|
MERLIN_CONFIG="$HOME/.config/zshrc/merlin_worker.zsh"
|
||||||
|
|
||||||
if [ -f "$MERLIN_CONFIG" ]; then
|
# Create directory if it doesn't exist
|
||||||
# Create a backup
|
mkdir -p "$(dirname "$MERLIN_CONFIG")"
|
||||||
cp "$MERLIN_CONFIG" "$MERLIN_CONFIG.backup"
|
|
||||||
|
|
||||||
# Replace the last PYTHONPATH line in merlin_worker.zsh with the one from ~/.bashrc
|
if [ -f "$MERLIN_CONFIG" ]; then
|
||||||
# First, remove existing PYTHONPATH lines
|
# Cross-platform sed: remove existing PYTHONPATH lines
|
||||||
sed -i '/^export PYTHONPATH=/d' "$MERLIN_CONFIG"
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
# macOS
|
||||||
|
sed -i '' '/^export PYTHONPATH=/d' "$MERLIN_CONFIG"
|
||||||
|
else
|
||||||
|
# Linux/Ubuntu and others
|
||||||
|
sed -i '/^export PYTHONPATH=/d' "$MERLIN_CONFIG"
|
||||||
|
fi
|
||||||
|
|
||||||
# Then append the PYTHONPATH from ~/.bashrc
|
# Then append the PYTHONPATH from ~/.bashrc
|
||||||
echo "$BASHRC_PYTHONPATH" >> "$MERLIN_CONFIG"
|
echo "$BASHRC_PYTHONPATH" >> "$MERLIN_CONFIG"
|
||||||
|
|
||||||
echo "Updated PYTHONPATH in $MERLIN_CONFIG with value from ~/.bashrc"
|
echo "Updated PYTHONPATH in $MERLIN_CONFIG with value from ~/.bashrc"
|
||||||
else
|
else
|
||||||
echo "Warning: $MERLIN_CONFIG not found"
|
# Create the file with just the PYTHONPATH
|
||||||
|
echo "$BASHRC_PYTHONPATH" > "$MERLIN_CONFIG"
|
||||||
|
echo "Created $MERLIN_CONFIG with PYTHONPATH from ~/.bashrc"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "No PYTHONPATH export found in ~/.bashrc"
|
echo "No PYTHONPATH export found in ~/.bashrc"
|
||||||
|
|||||||
Reference in New Issue
Block a user