summaryrefslogtreecommitdiff
path: root/scripts/fix-permissions
blob: 408a23ea35dcc93d03e42b23c71130fa7ad5669a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
# claudomator-fix-perms — Fix ownership and permissions for Claudomator components
set -euo pipefail

SITE_DIR="/site/doot.terst.org"
GIT_REPOS_DIR="/site/git.terst.org/repos"
WORKSPACE_DIR="/workspace"

echo "==> Fixing site ownership (www-data:www-data)..."
chown -R www-data:www-data "${SITE_DIR}"

echo "==> Ensuring binaries are executable..."
if [ -d "${SITE_DIR}/bin" ]; then
    find "${SITE_DIR}/bin" -type f -exec chmod +x {} +
fi
if [ -f "/usr/local/bin/claudomator" ]; then
    chmod +x /usr/local/bin/claudomator
fi

echo "==> Ensuring scripts are executable..."
if [ -d "${SITE_DIR}/scripts" ]; then
    find "${SITE_DIR}/scripts" -type f -exec chmod +x {} +
fi
if [ -d "${WORKSPACE_DIR}/claudomator/scripts" ]; then
    find "${WORKSPACE_DIR}/claudomator/scripts" -type f -exec chmod +x {} +
fi

echo "==> Fixing git bare repo permissions..."
# Specifically fix object permissions that might be corrupted by root runs
if [ -d "${GIT_REPOS_DIR}" ]; then
    chown -R www-data:www-data "${GIT_REPOS_DIR}"
    find "${GIT_REPOS_DIR}" -type d -exec chmod 775 {} +
    find "${GIT_REPOS_DIR}" -type f -exec chmod 664 {} +
fi

echo "==> Fixing database permissions..."
if [ -f "${SITE_DIR}/data/claudomator.db" ]; then
    chmod 664 "${SITE_DIR}/data/claudomator.db"
    # Ensure the data directory is writable for WAL mode
    chmod 775 "${SITE_DIR}/data"
fi

echo "==> Done!"