Add portable SimLingo environment: restore.sh
Browse files- restore.sh +54 -0
restore.sh
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
if [[ $# -lt 1 || $# -gt 2 || ( $# -eq 2 && "${2:-}" != --offline ) ]]; then
|
| 4 |
+
echo 'Usage: bash restore.sh /absolute/path/to/environment [--offline]' >&2
|
| 5 |
+
exit 2
|
| 6 |
+
fi
|
| 7 |
+
TARGET=$(readlink -m -- "$1")
|
| 8 |
+
if [[ -e "$TARGET" && ( ! -d "$TARGET" || -n "$(ls -A "$TARGET")" ) ]]; then
|
| 9 |
+
echo "Refusing to overwrite a nonempty environment: $TARGET" >&2
|
| 10 |
+
exit 2
|
| 11 |
+
fi
|
| 12 |
+
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
|
| 13 |
+
if [[ -f "$SCRIPT_DIR/SHA256SUMS" && -d "$SCRIPT_DIR/archives" ]]; then
|
| 14 |
+
DEFAULT_CACHE=$SCRIPT_DIR
|
| 15 |
+
else
|
| 16 |
+
DEFAULT_CACHE=$SCRIPT_DIR/simlingo-env-files
|
| 17 |
+
fi
|
| 18 |
+
CACHE=${SIMLINGO_PACKAGE_CACHE:-$DEFAULT_CACHE}
|
| 19 |
+
mkdir -p "$CACHE/archives"
|
| 20 |
+
CACHE=$(cd "$CACHE" && pwd)
|
| 21 |
+
BASE_URL="https://huggingface.co/datasets/data-loader/simlingo-conda-env/resolve/${SIMLINGO_ENV_REVISION:-main}"
|
| 22 |
+
OFFLINE=${2:-}
|
| 23 |
+
ARCHIVES=(archives/simlingo-linux-x86_64-py38-20261015.tar.gz.part-000 archives/simlingo-linux-x86_64-py38-20261015.tar.gz.part-001 archives/simlingo-linux-x86_64-py38-20261015.tar.gz.part-002 archives/simlingo-linux-x86_64-py38-20261015.tar.gz.part-003)
|
| 24 |
+
METADATA=(manifest.json packages.json environment-info.json requirements-snapshot.txt restore-validation.json public-audit.json THIRD_PARTY_NOTICES.md)
|
| 25 |
+
download() {
|
| 26 |
+
local rel=$1
|
| 27 |
+
local file="$CACHE/$rel"
|
| 28 |
+
if [[ "$OFFLINE" == --offline ]]; then
|
| 29 |
+
test -f "$file" || { echo "Missing offline file: $rel" >&2; exit 2; }
|
| 30 |
+
return
|
| 31 |
+
fi
|
| 32 |
+
if [[ "$rel" != SHA256SUMS && -f "$file" && -f "$CACHE/SHA256SUMS" ]]; then
|
| 33 |
+
if (cd "$CACHE" && awk -v f="$rel" '$2 == f { print }' SHA256SUMS | sha256sum -c --status); then
|
| 34 |
+
return
|
| 35 |
+
fi
|
| 36 |
+
fi
|
| 37 |
+
curl --fail --location --retry 3 --connect-timeout 30 --continue-at - --output "$file.partial" "$BASE_URL/$rel"
|
| 38 |
+
mv -- "$file.partial" "$file"
|
| 39 |
+
}
|
| 40 |
+
download SHA256SUMS
|
| 41 |
+
for rel in "${METADATA[@]}" "${ARCHIVES[@]}"; do download "$rel"; done
|
| 42 |
+
(cd "$CACHE" && sha256sum -c SHA256SUMS)
|
| 43 |
+
mkdir -p "$TARGET"
|
| 44 |
+
ARCHIVE_PATHS=()
|
| 45 |
+
for rel in "${ARCHIVES[@]}"; do ARCHIVE_PATHS+=("$CACHE/$rel"); done
|
| 46 |
+
cat "${ARCHIVE_PATHS[@]}" | tar --no-same-owner -xz -C "$TARGET"
|
| 47 |
+
set +u
|
| 48 |
+
source "$TARGET/bin/activate"
|
| 49 |
+
set -u
|
| 50 |
+
hash -r
|
| 51 |
+
test "$(command -v python)" = "$TARGET/bin/python"
|
| 52 |
+
python "$TARGET/bin/conda-unpack"
|
| 53 |
+
python -c 'import sys, torch; print("Python:", sys.executable); print("PyTorch:", torch.__version__)'
|
| 54 |
+
printf '\nEnvironment ready. In your shell run:\nsource %q/bin/activate\n' "$TARGET"
|