-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave
More file actions
executable file
·39 lines (36 loc) · 1.8 KB
/
Copy pathsave
File metadata and controls
executable file
·39 lines (36 loc) · 1.8 KB
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
#!/usr/bin/env bash
#
# Save the current state of src/ (MediaWiki installation) for fast restore later.
# Uses Docker-as-root to copy files, so it works on both macOS and Linux
# (where src/ files are owned by the container user).
#
# Usage: ./save
# ENVIRONMENT=0 ./save
#
set -euo pipefail # exit on error, undefined vars, or pipe failures
. "$(dirname "$0")"/lib/setup # source shared setup (docker checks, shared vars, output capture, trace into the log)
. "$(dirname "$0")"/lib/docker_chmod # provides docker_chmod function
# Check that src/ exists and is not empty
# Uses QUIBBLE_SRC from lib/setup (default "src", overridden by ENVIRONMENT or parallel workers).
if [ ! -d "$QUIBBLE_SRC" ] || [ -z "$(ls -A "$QUIBBLE_SRC" 2>/dev/null)" ]; then
echo "Error: $QUIBBLE_SRC/ is empty or missing. Run ./fresh_install first." >&2 # >&2 prints to stderr
exit 1
fi
# Create save directory with proper permissions for the container user.
# Uses QUIBBLE_SAVE from lib/setup (default "src_save", overridden by ENVIRONMENT).
mkdir -p "$QUIBBLE_SAVE"
docker_chmod "$QUIBBLE_SAVE" # make dir world-writable for the container user
# Copy src/ to save directory using Docker-as-root.
# --rm: remove container on exit
# --entrypoint bash: override default entrypoint to run a shell command
# --user root: run as root to have permission to read/write all files
# -v: mount src/ (read-only) and save dir (writable)
# cp -a: preserve permissions, ownership, timestamps
# /workspace/src/.: copy contents (not the directory itself)
docker run --rm \
--entrypoint bash \
--user root \
-v "$QUIBBLE_DIR"/"$QUIBBLE_SRC":/workspace/src:ro \
-v "$QUIBBLE_DIR"/"$QUIBBLE_SAVE":/workspace/src_save \
"$QUIBBLE_IMAGE" \
-c 'find /workspace/src_save -mindepth 1 -delete && cp -a /workspace/src/. /workspace/src_save/' # clear old save, then copy