#!/bin/sh # Prepare owner-only storage for the NAS user. Does not delete or reset any data. set -eu cd "$(dirname "$0")/.." hop_storage_uid=$(sed -n 's/^HOP_RUN_UID=//p' .env) hop_storage_gid=$(sed -n 's/^HOP_RUN_GID=//p' .env) case "$hop_storage_uid:$hop_storage_gid" in *[!0-9:]*|:*|*:) printf '%s\n' 'HOP_RUN_UID/GID를 확인하세요.' >&2; exit 1 ;; esac if [ "$hop_storage_uid" = 0 ]; then printf '%s\n' '앱은 일반 NAS 사용자 UID로 실행해야 합니다.' >&2 exit 1 fi if docker inspect hop >/dev/null 2>&1; then if [ "$(docker inspect --format '{{.State.Running}}' hop)" = true ]; then printf '%s\n' 'Docker 앱에서 hop 프로젝트를 먼저 중지한 뒤 다시 실행하세요.' >&2 exit 1 fi if docker inspect --format '{{range .Mounts}}{{if eq .Destination "/data/uploads"}}{{.Type}}{{end}}{{end}}' hop | grep -qx volume; then printf '%s\n' '기존 업로드 볼륨이 연결돼 있습니다. deploy.md의 저장소 전환 순서를 먼저 진행하세요.' >&2 exit 1 fi fi mkdir -p uploads docker volume create --label com.docker.compose.project=hop --label com.docker.compose.volume=hop_database hop_hop_database >/dev/null docker run --rm --network none --user 0:0 \ --mount type=volume,source=hop_hop_database,target=/database \ --mount "type=bind,source=$PWD/uploads,target=/uploads" \ alpine:3.22 sh -eu -c ' chown -R "$1:$2" /database /uploads chmod 700 /database /uploads for folder in originals temporary chunks; do mkdir -p "/uploads/$folder" chmod 700 "/uploads/$folder" done chown -R "$1:$2" /uploads ' sh "$hop_storage_uid" "$hop_storage_gid" printf '%s\n' '파일 저장소 준비 완료: hop/uploads (NAS 사용자 소유, 기존 파일 유지)'