-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestore
More file actions
executable file
·40 lines (37 loc) · 1.87 KB
/
Copy pathrestore
File metadata and controls
executable file
·40 lines (37 loc) · 1.87 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
40
#!/usr/bin/env bash
#
# Restore src/ from a previously saved state (created by ./save).
# Much faster than running ./fresh_install again.
# Uses Docker-as-root to handle files owned by the container user (works on macOS and Linux).
#
# Usage: ./restore
# ENVIRONMENT=0 ./restore
#
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 save directory exists and is not empty.
# Uses QUIBBLE_SAVE from lib/setup (default "src_save", overridden by ENVIRONMENT).
if [ ! -d "$QUIBBLE_SAVE" ] || [ -z "$(ls -A "$QUIBBLE_SAVE" 2>/dev/null)" ]; then
echo "Error: $QUIBBLE_SAVE/ is empty or missing. Run ./save first." >&2 # >&2 prints to stderr
exit 1
fi
# Ensure target src directory exists with proper permissions.
# Uses QUIBBLE_SRC from lib/setup (default "src", overridden for parallel workers).
mkdir -p "$QUIBBLE_SRC"
docker_chmod "$QUIBBLE_SRC" # make dir world-writable for the container user
# Clear target and restore from src_save/ in one Docker command.
# --rm: remove container on exit
# --entrypoint bash: override default entrypoint to run a shell command
# --user root: run as root to have permission to delete/copy all files
# -v: mount target src (writable) and src_save/ (read-only)
# find -delete: remove all contents of target but not the mount point
# cp -a: preserve permissions, ownership, timestamps
# /workspace/src_save/.: copy contents (not the directory itself)
docker run --rm \
--entrypoint bash \
--user root \
-v "$QUIBBLE_DIR"/"$QUIBBLE_SRC":/workspace/src \
-v "$QUIBBLE_DIR"/"$QUIBBLE_SAVE":/workspace/src_save:ro \
"$QUIBBLE_IMAGE" \
-c 'find /workspace/src -mindepth 1 -delete && cp -a /workspace/src_save/. /workspace/src/' # clear and restore