| set -euo pipefail | |
| # This setup script is intended to be executed as root via: | |
| # echo 'password' | sudo -S /tmp/setup_project_alpha.sh | |
| # | |
| # It prepares the environment for OSWorld-SFT/evaluation_examples/examples/os/task2.json | |
| TARGET_DIR="/home/user/dev/project_alpha" | |
| LOG_DIR="$TARGET_DIR/logs" | |
| DEPLOY="$TARGET_DIR/deploy.sh" | |
| mkdir -p "$LOG_DIR" | |
| # Ensure "developers" group exists and user is a member (so chgrp can succeed without sudo after newgrp). | |
| if ! getent group developers >/dev/null 2>&1; then | |
| groupadd developers || true | |
| fi | |
| usermod -aG developers user || true | |
| # Create deploy.sh with deterministic size + mtime but "wrong" perms/group so the task has work to do. | |
| cat > "$DEPLOY" <<'EOF' | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| echo "Deploy placeholder" | |
| EOF | |
| # Pad deploy.sh to exactly 1234 bytes (deterministic size for evaluator checks). | |
| python3 - <<'PY' | |
| from pathlib import Path | |
| p = Path("/home/user/dev/project_alpha/deploy.sh") | |
| data = p.read_bytes() | |
| TARGET = 1234 | |
| if len(data) > TARGET: | |
| raise SystemExit("deploy.sh too large") | |
| p.write_bytes(data + (b"#" * (TARGET - len(data)))) | |
| PY | |
| # Deterministic mtime for evaluator checks. | |
| touch -d '2001-02-03 04:05:06' "$DEPLOY" | |
| # Set starting ownership/perms (task should change group to developers and perms to 754). | |
| chown user:user "$DEPLOY" | |
| chmod 700 "$DEPLOY" | |
| # Create logs: one recent and one old (>7 days) so cleanup is meaningful. | |
| printf '%s\n' 'recent log' > "$LOG_DIR/recent.log" | |
| printf '%s\n' 'old log' > "$LOG_DIR/old.log" | |
| touch -d '2 days ago' "$LOG_DIR/recent.log" | |
| touch -d '8 days ago' "$LOG_DIR/old.log" | |
| # Ensure ownership for the whole tree. | |
| chown -R user:user "$TARGET_DIR" | |