Repository Public License
1#!/usr/bin/env bash2# ORIX Secure3# File: Scripts/seed-photos.sh4# Description: Fills a simulator's photo library with generated test images for Photo Cleanup: byte-identical copies, re-encoded5# and resized variants of the same picture, unrelated pictures. Resets ORIX Secure's photo permission so the tests go through the system prompt.6# usage: seed-photos.sh ORIX_SIM selects the simulator.7#8# Author: Simon-Pierre Boucher9# Contact: contact@spboucher.ai10set -euo pipefail11cd "$(dirname "$0")/.."12SIM="${ORIX_SIM:-ORIXSecure iPhone}"13OUT="build/fixtures/photos"14rm -rf "$OUT"; mkdir -p "$OUT"15python3 - "$OUT" <<'PY'16import sys, random, shutil, os17from PIL import Image, ImageDraw18out = sys.argv[1]19def scene(seed, size=(1200, 900)):20 rnd = random.Random(seed)21 base = tuple(rnd.randint(30, 220) for _ in range(3))22 img = Image.new("RGB", size, base)23 d = ImageDraw.Draw(img)24 for y in range(size[1]):25 t = y / size[1]26 d.line([(0, y), (size[0], y)], fill=tuple(int(base[i] * (1 - 0.5 * t)) for i in range(3)))27 for _ in range(14):28 x, y = rnd.randint(0, size[0]), rnd.randint(0, size[1]); r = rnd.randint(40, 260)29 color = tuple(rnd.randint(0, 255) for _ in range(3))30 (d.ellipse if rnd.random() < 0.5 else d.rectangle)([x - r, y - r, x + r, y + r], fill=color)31 return img32for seed in range(1, 7): # six different pictures33 scene(seed).save(f"{out}/scene{seed}.png")34shutil.copy(f"{out}/scene1.png", f"{out}/scene1-copy.png") # byte-identical copies35shutil.copy(f"{out}/scene1.png", f"{out}/scene1-copy2.png")36shutil.copy(f"{out}/scene2.png", f"{out}/scene2-copy.png")37scene(3).resize((900, 675), Image.LANCZOS).save(f"{out}/scene3-small.png") # same picture, smaller38scene(4).resize((1500, 1125), Image.LANCZOS).save(f"{out}/scene4-large.png") # same picture, larger39img = scene(5); img = img.point(lambda v: min(255, v + 10)); img.save(f"{out}/scene5-brighter.png")40print(len(os.listdir(out)), "images")41PY42xcrun simctl boot "$SIM" 2>/dev/null || true43xcrun simctl bootstatus "$SIM" -b >/dev/null 2>&1 || true44# A fresh or erased simulator has no photo library until Photos has been opened once.45xcrun simctl launch "$SIM" com.apple.mobileslideshow >/dev/null 2>&1 || true46sleep 647xcrun simctl terminate "$SIM" com.apple.mobileslideshow >/dev/null 2>&1 || true48# addmedia can hang when the simulator's photo service is in a bad state: bound it, restart the simulator once, retry.49add() { perl -e 'alarm shift; exec @ARGV' 90 xcrun simctl addmedia "$SIM" "$OUT"/*.png; }50if ! add; then51 echo "addmedia did not finish; restarting $SIM"52 xcrun simctl shutdown "$SIM" 2>/dev/null || true53 xcrun simctl boot "$SIM"54 xcrun simctl bootstatus "$SIM" -b >/dev/null 2>&1 || true55 add56fi57# Permission goes through the real system prompt in the UI tests (simctl "grant photos" has no effect on this runtime).58xcrun simctl privacy "$SIM" reset photos ai.spboucher.orix.secure 2>/dev/null || true59echo "seeded $SIM"60