diff --git a/scripts/launchd/backup-daily.sh b/scripts/launchd/backup-daily.sh
index 8dba1ae..5d06d51 100755
--- a/scripts/launchd/backup-daily.sh
+++ b/scripts/launchd/backup-daily.sh
@@ -3,5 +3,10 @@ set -euo pipefail
export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:$HOME/.local/bin"
export PYTHONUNBUFFERED=1
+BRAINLAYER_DIR="${BRAINLAYER_DIR:-__BRAINLAYER_DIR_VALUE__}"
+case "$BRAINLAYER_DIR" in
+ __BRAINLAYER_DIR_*) BRAINLAYER_DIR="$HOME/Gits/brainlayer" ;;
+esac
+export PYTHONPATH="$BRAINLAYER_DIR/src${PYTHONPATH:+:$PYTHONPATH}"
exec "${BRAINLAYER_PYTHON:-python3}" -m brainlayer.backup_daily
diff --git a/scripts/launchd/install.sh b/scripts/launchd/install.sh
index 48a9c19..1ec6ffa 100755
--- a/scripts/launchd/install.sh
+++ b/scripts/launchd/install.sh
@@ -100,13 +100,17 @@ install_plist() {
install_backup_script() {
local src="$SCRIPT_DIR/backup-daily.sh"
local dst="$BRAINLAYER_LIB_DIR/backup-daily.sh"
+ local escaped_brainlayer_dir
if [ ! -f "$src" ]; then
echo "ERROR: $src not found"
return 1
fi
- cp "$src" "$dst"
+ escaped_brainlayer_dir="$(printf '%s' "$BRAINLAYER_DIR" | sed 's/[\\&|]/\\&/g')"
+ sed \
+ -e "s|__BRAINLAYER_DIR_VALUE__|$escaped_brainlayer_dir|g" \
+ "$src" > "$dst"
chmod 755 "$dst"
echo "Installed: $dst"
}
diff --git a/tests/test_backup_daily.py b/tests/test_backup_daily.py
index 5442251..fbd059d 100644
--- a/tests/test_backup_daily.py
+++ b/tests/test_backup_daily.py
@@ -100,16 +100,23 @@ def files(self):
def test_launchd_installer_knows_backup_target():
install_path = Path("scripts/launchd/install.sh")
+ wrapper_path = Path("scripts/launchd/backup-daily.sh")
plist_path = Path("scripts/launchd/com.brainlayer.backup-daily.plist")
assert install_path.is_file(), f"Installer not found at {install_path}; check test working directory"
+ assert wrapper_path.is_file(), f"Backup wrapper not found at {wrapper_path}; check launchd wrapper is committed"
assert plist_path.is_file(), f"Backup plist not found at {plist_path}; check launchd template is committed"
install = install_path.read_text()
+ wrapper = wrapper_path.read_text()
plist = plist_path.read_text()
assert "backup-daily" in install
assert "install_backup_script" in install
+ assert "escaped_brainlayer_dir" in install
+ assert "__BRAINLAYER_DIR_VALUE__" in install
+ assert "PYTHONPATH" in wrapper
+ assert "__BRAINLAYER_DIR_VALUE__" in wrapper
assert "com.brainlayer.backup-daily" in plist
assert "3" in plist
assert "17" in plist