Skip to content

armgit / ODS

Public Imported from GitHub
0

ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.

1.8 KB
Raw Blame
#!/usr/bin/env bash
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
TEST_ROOT="$(mktemp -d)"
trap 'rm -rf "$TEST_ROOT"' EXIT

eval "$(sed -n '/^secure_pixel_catalog_sources() {/,/^}/p' "$ROOT/get-ods.sh")"
type secure_pixel_catalog_sources >/dev/null 2>&1

install_root="$TEST_ROOT/ods"
(
    umask 0002
    mkdir -p \
        "$install_root/config" \
        "$install_root/extensions/library/services/library-fixture" \
        "$install_root/extensions/services/builtin-fixture"
    printf '%s\n' '{"extensions":[]}' > "$install_root/config/extensions-catalog.json"
    printf '%s\n' 'services: {}' > "$install_root/extensions/library/services/library-fixture/compose.yaml"
    printf '%s\n' 'services: {}' > "$install_root/extensions/services/builtin-fixture/compose.yaml"
)

[[ "$(stat -c '%a' "$install_root/config/extensions-catalog.json")" == 664 ]]
[[ "$(stat -c '%a' "$install_root/extensions/services")" == 775 ]]

# Match BSD/macOS chmod's option surface while still applying the permission
# change on Linux. The bootstrap helper must not rely on GNU-only `--`.
# shellcheck disable=SC2317
chmod() {
    local arg
    for arg in "$@"; do
        [[ "$arg" != "--" ]] || return 64
    done
    command chmod "$@"
}
secure_pixel_catalog_sources "$install_root"
unset -f chmod

while IFS= read -r -d '' path; do
    mode="$(stat -c '%a' "$path")"
    (( (8#$mode & 8#022) == 0 )) || {
        printf 'FAIL: Pixel catalog input remained writable: %s (%s)\n' "$path" "$mode" >&2
        exit 1
    }
done < <(find \
    "$install_root/config/extensions-catalog.json" \
    "$install_root/extensions/library/services" \
    "$install_root/extensions/services" \
    -print0)

printf 'PASS: bootstrap removes group/world write from Pixel catalog inputs under umask 0002\n'