Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ program it changes. To release, rename `[Unreleased]` to the version and
date and raise the version in Cargo.toml, in the same pull request: once it
is on main, the release is published with that section as its notes (AGENTS.md, Releasing).

## [Unreleased]

### Installer and launcher

- iPads and iPhones on iOS 12.0 to 13.7 can split their storage without DFU
mode: the installer offers Amethyst, signs its helper app with your Apple
ID through xtool and installs it. The device restarts once on the way;
open Orchard Installer again when it is back. It is the first choice on
those versions, ahead of checkra1n, and the only one on A12 and A13
devices there.

### Command line

- `orchard install --access amethyst` takes the same route from the terminal.

## [0.3.18] - 2026-12-05

### Installer and launcher
Expand Down
26 changes: 16 additions & 10 deletions companion/App/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,13 @@ private func wide(_ view: UIView) {
}

/// Some devices restart their screen once before access; nothing can open the app again
/// then, and what that restart was for holds only about 20 seconds.
private func reopenNotice() -> UIView {
let text = label("If Orchard Installer doesn’t open again by itself, reopen it within 20 seconds.", sans(16, semibold: true), .rule, lineSpacing: 4)
/// then, and what that restart was for holds only about 20 seconds. In Amethyst (iOS 12
/// and 13) the first run restarts the whole device instead, and the app is opened again
/// by hand (`restartsDevice`, resize-apfs's same notice).
private func reopenNotice(_ restartsDevice: Bool) -> UIView {
let line = restartsDevice ? "Your \(UIDevice.current.model) restarts once. Open Orchard Installer again when it’s back."
: "If Orchard Installer doesn’t open again by itself, reopen it within 20 seconds."
let text = label(line, sans(16, semibold: true), .rule, lineSpacing: 4)
text.numberOfLines = 0
let content = row([icon("timer", 18), text], spacing: 14)
let box = framed(content, UIColor.amber.withAlphaComponent(0.05), UIColor.amber.withAlphaComponent(0.32), vertical: 18, horizontal: 24)
Expand All @@ -254,7 +258,7 @@ private func reopenNotice() -> UIView {

/// Storage access (the app inside Dopamine, 9.1 and 9.2): with Continue, then with the
/// spinner while access is obtained.
private func storageAccess(working: Bool, proceed: @escaping () -> Void) -> UIView {
private func storageAccess(working: Bool, restartsDevice: Bool, proceed: @escaping () -> Void) -> UIView {
let steps = UIStackView(arrangedSubviews: ["The screen restarts and open apps close", "Unlock the device when it is back",
"Orchard Installer opens again by itself"].map {
row([icon("arrow-right", 18), label($0, sans(16), .rule)], spacing: 14)
Expand All @@ -266,16 +270,16 @@ private func storageAccess(working: Bool, proceed: @escaping () -> Void) -> UIVi
wide(steps)
var views = [working ? badge(.accent, 0.08, fixed(Spinner(), 40, 40)) : badge(.accent, 0.12, icon("hard-drive", 38)),
heading("Storage access", "Orchard Installer needs access to your device’s storage. This takes about a minute."),
steps, reopenNotice()]
steps, reopenNotice(restartsDevice)]
if !working { views.append(ActionButton("Continue", action: proceed)) }
return column(views)
}

/// 9.3.
private func accessFailed(retry: @escaping () -> Void) -> UIView {
private func accessFailed(restartsDevice: Bool, retry: @escaping () -> Void) -> UIView {
column([badge(.red, 0.12, icon("x", 38)),
heading("Couldn’t get storage access", "Your storage was not changed."),
reopenNotice(), ActionButton("Try again", action: retry)])
reopenNotice(restartsDevice), ActionButton("Try again", action: retry)])
}

/// Shows the screen for the helper's status, read every second. Inside the Dopamine app
Expand All @@ -291,6 +295,8 @@ final class StatusController: UIViewController {
refresh()
}
}
/// The device restarts once while access is obtained (Amethyst's first run).
var restartsDevice = false
/// Continue and Try again on the Storage access page.
var proceed: () -> Void = {}
var retry: () -> Void = {}
Expand Down Expand Up @@ -374,9 +380,9 @@ final class StatusController: UIViewController {
content.subviews.forEach { $0.removeFromSuperview() }
let view: UIView
switch screen {
case "access": view = storageAccess(working: false) { [weak self] in self?.proceed() }
case "access-working": view = storageAccess(working: true) {}
case "access-failed": view = accessFailed { [weak self] in self?.retry() }
case "access": view = storageAccess(working: false, restartsDevice: restartsDevice) { [weak self] in self?.proceed() }
case "access-working": view = storageAccess(working: true, restartsDevice: restartsDevice) {}
case "access-failed": view = accessFailed(restartsDevice: restartsDevice) { [weak self] in self?.retry() }
case "splitting": updateMinutes(); view = splitting(minutes: minutes)
case "done": view = done()
case "before": view = before(system: status?.system ?? "the system")
Expand Down
19 changes: 15 additions & 4 deletions companion/App/EmbeddedApp.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// The companion inside the Dopamine app (no DFU): its settings for resize-apfs's shared
// access code (Access/StorageAccess.swift there) and its start.
// The companion inside the Dopamine app, or the Amethyst app on iOS 12 and 13 (no DFU):
// its settings for resize-apfs's shared access code (Access/StorageAccess.swift there)
// and its start. Amethyst's files live in the system's root, not /var/jb: StorageAccess
// moves the payload's path there by itself (`rooted(at:)`).
import UIKit

extension StorageAccess.Configuration {
Expand All @@ -10,17 +12,25 @@ extension StorageAccess.Configuration {
let given = Bundle.main.url(forResource: "helper-arguments", withExtension: "txt")
.flatMap { try? String(contentsOf: $0, encoding: .utf8) }?
.components(separatedBy: .whitespacesAndNewlines).filter { !$0.isEmpty } ?? []
// The Amethyst part (iOS 12.0 to 13.7) brings the Swift runtime its helper needs
// where iOS has none (12.0 and 12.1), as payloads; the helper looks for it here.
let runtime: [(resource: String, path: String)] = (Bundle.main.urls(forResourcesWithExtension: "payload", subdirectory: nil) ?? [])
.map { $0.deletingPathExtension().lastPathComponent }
.filter { $0.hasPrefix("libswift") && $0.hasSuffix(".dylib") }
.sorted()
.map { (resource: $0, path: "/var/jb/usr/libexec/orchard-companion/Frameworks/" + $0) }
return StorageAccess.Configuration(
name: "Orchard Installer", state: "OrchardCompanion", folder: folder, label: "org.orchardlinux.companion.embedded",
payloads: [("orchard-companion", "/var/jb/usr/libexec/orchard-companion/orchard-companion")],
payloads: [(resource: "orchard-companion", path: "/var/jb/usr/libexec/orchard-companion/orchard-companion")] + runtime,
// The helper's status file and log are in the folder.
arguments: ["--state-dir", folder] + given,
lock: "/var/root/Library/OrchardCompanion/helper.lock",
leftovers: [])
}
}

/// Started by resize-apfs's Access/AccessBridge.m once the Dopamine app has launched.
/// Started by resize-apfs's Access/AccessBridge.m (Dopamine) or Access/AmethystBridge.m
/// (Amethyst) once the app has launched.
@objc(RAFEmbeddedApp) final class EmbeddedApp: NSObject {
private static var window: UIWindow?

Expand All @@ -45,6 +55,7 @@ extension StorageAccess.Configuration {
}
}
}
controller.restartsDevice = access.restartsDevice
controller.proceed = { begin(.confirmed) }
controller.retry = { begin(.retry) }
let window = companionWindow(UIWindow(frame: UIScreen.main.bounds), controller)
Expand Down
75 changes: 69 additions & 6 deletions companion/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
# - out/access: what goes into the Dopamine app, so that one app is installed
# without DFU. That is the app's interface as a library (iOS 15+, as
# Dopamine), its Info.plist, its resources and the same helper as a payload.
# - out/access-ios12: the same for the Amethyst app (iOS 12.0 to 13.7), with
# Amethyst's executable built from its source (host/Amethyst) and the Swift
# runtime iOS 12.0 and 12.1 lack.
# Needs Xcode's iOS SDK and ldid.
#
# From a resize-apfs checkout at the pinned commit (RESIZE_APFS, default
Expand All @@ -27,7 +30,7 @@ if [ "${1:-}" = "--simulator" ]; then
echo "Built $app"
exit 0
fi
RESIZE_APFS_COMMIT=cd1f9db334af55104884aca77edfcd2a327140e2
RESIZE_APFS_COMMIT=ade540a2dd457173d85e11e73cfe4293cc5b4696
resize=${RESIZE_APFS:-$PWD/../../worktrees/resize-shared-access}
[ -d "$resize" ] || { echo "No resize-apfs checkout at $resize (set RESIZE_APFS)" >&2; exit 1; }
resize=$(cd "$resize" && pwd)
Expand Down Expand Up @@ -58,7 +61,7 @@ swiftc -parse-as-library -emit-library -static -emit-module -module-name ResizeD
clang -c Helper/native.c -o "$work/native.o"
swiftc -I "$work" -I "$resize/Sources/NativeSystem/include" -L "$work" -lResizeDevice -lResizeCore \
"$work/NativeSystem.o" "$work/native.o" -framework IOKit -framework CoreFoundation -framework MobileCoreServices \
Helper/main.swift -o "$out/orchard-companion"
Helper/main.swift -Xlinker -rpath -Xlinker /usr/libexec/orchard-companion/Frameworks -o "$out/orchard-companion"

# The entry program.
clang Entry/entry.c -o "$out/orchard-companion-entry"
Expand All @@ -77,10 +80,10 @@ xcrun ibtool --minimum-deployment-target 12.0 --target-device iphone --target-de
--compile "$app/LaunchScreen.storyboardc" App/Launch/LaunchScreen.storyboard

# Swift runtime: iOS 12.2 and later have it in /usr/lib/swift, searched first.
# iOS 12.0 and 12.1 don't; the checkra1n route's payload will bring Apple's
# back-deployment runtime in the app's Frameworks (as resize-apfs's
# scripts/build-device-ios12.sh does). Not here: palera1n needs iOS 15, and the
# runtime would add about 11 MB to the installer and every overlay.
# iOS 12.0 and 12.1 don't; only the Amethyst part below brings Apple's
# back-deployment runtime (palera1n needs iOS 15, and the overlays stay small).
# The helper also searches /usr/libexec/orchard-companion/Frameworks, where the
# Amethyst part puts it.

# The app as the library the Dopamine app loads. AppDelegate.swift is the app's
# start as a program of its own, which the library has no part in.
Expand Down Expand Up @@ -115,5 +118,65 @@ ldid -SHelper/helper.entitlements.plist "$out/orchard-companion-entry"
# the app with an Apple ID re-signs every program it finds, which would cost
# the helper its own signature (StorageAccess takes the line off).
{ printf 'RESIZE-APFS-HELPER\n'; cat "$out/orchard-companion"; } > "$access/Resources/orchard-companion.payload"

# The same for the Amethyst app (iOS 12.0 to 13.7, no DFU): the interface as a library
# for iOS 12 with resize-apfs's Access/AmethystBridge.m, the same Info.plist, resources
# and helper, and Amethyst's executable built from its source (resize-apfs's
# scripts/build-amethyst.sh: the official one is stripped of what the bridge calls).
access12="$out/access-ios12"
mkdir -p "$access12/host"
clang -fobjc-arc -fmodules -c "$resize/Access/AmethystBridge.m" -o "$work/AmethystBridge.o"
swiftc -parse-as-library -emit-library -module-name OrchardCompanion \
"$resize/Access/StorageAccess.swift" App/App.swift App/EmbeddedApp.swift "$work/AmethystBridge.o" \
-Xlinker -install_name -Xlinker @executable_path/Frameworks/OrchardCompanion.dylib \
-Xlinker -rpath -Xlinker @executable_path/Frameworks \
-o "$access12/OrchardCompanion.dylib"
for binary in "$access12/OrchardCompanion.dylib" "$out/orchard-companion"; do
first=$(xcrun otool -l "$binary" | awk '/cmd LC_RPATH/ {getline; getline; print $2; exit}')
[ "$first" = /usr/lib/swift ] || { echo "$binary must search /usr/lib/swift first, not $first" >&2; exit 1; }
done
xcrun --sdk iphoneos strip -x "$access12/OrchardCompanion.dylib"
codesign --force --sign - --timestamp=none "$access12/OrchardCompanion.dylib"
cp "$access/Info.plist" "$access12/Info.plist"
cp -R "$access/Resources" "$access12/Resources"
bash "$resize/scripts/build-amethyst.sh" "$access12/host/Amethyst"

# Amethyst brings no Swift runtime, and iOS 12.0 and 12.1 have none (as resize-apfs's
# scripts/build-device-ios12.sh): Apple's back-deployment runtime comes along, each
# library the one that needs it: the interface's in Resources/Frameworks, which lands in
# the app's Frameworks; the helper's as payloads (signing with an Apple ID leaves them
# alone), which the app puts into /usr/libexec/orchard-companion/Frameworks
# (EmbeddedApp.swift). iOS 12.2 and later take their own from /usr/lib/swift, searched first.
runtime="$(dirname "$(dirname "$(xcrun --find swiftc)")")/lib/swift-5.0/iphoneos"
[ -f "$runtime/libswiftCore.dylib" ] || { echo "No Swift back-deployment runtime at $runtime" >&2; exit 1; }
rpath_libs() { xcrun otool -L "$1" | awk '/@rpath\/libswift.*\.dylib/ {sub("@rpath/", "", $1); print $1}'; }
strong_libs() { xcrun otool -l "$1" | awk '/cmd LC_LOAD_DYLIB/ {strong=1} /cmd LC_LOAD_WEAK_DYLIB/ {strong=0} /name @rpath\/libswift/ && strong {sub("@rpath/", "", $2); print $2}'; }
# The runtime libraries `binary` needs, with what they need themselves, into `folder`.
bundle_runtime() {
local binary=$1 folder=$2 pending next lib each
mkdir -p "$folder"
pending=$(rpath_libs "$binary" | sort -u)
while [ -n "$pending" ]; do
next=""
for lib in $pending; do
{ [ -f "$folder/$lib" ] || [ ! -f "$runtime/$lib" ]; } && continue
# Bitcode is not used at runtime; Xcode strips it the same way when embedding.
xcrun bitcode_strip -r "$runtime/$lib" -o "$folder/$lib"
codesign --force --sign - --timestamp=none "$folder/$lib"
next+=" $(rpath_libs "$folder/$lib")"
done
pending=$(echo $next | tr ' ' '\n' | sort -u)
done
for each in "$binary" "$folder"/*.dylib; do
for lib in $(strong_libs "$each"); do
[ -f "$folder/$lib" ] || { echo "$each needs $lib, which iOS 12.0 lacks and which is not bundled" >&2; exit 1; }
done
done
}
bundle_runtime "$access12/OrchardCompanion.dylib" "$access12/Resources/Frameworks"
bundle_runtime "$out/orchard-companion" "$work/helper-runtime"
for lib in "$work"/helper-runtime/*.dylib; do
{ printf 'RESIZE-APFS-HELPER\n'; cat "$lib"; } > "$access12/Resources/$(basename "$lib").payload"
done
rm -rf "$work"
echo "Built the companion in $out"
18 changes: 14 additions & 4 deletions crates/app/src/install_screens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,20 +879,30 @@ fn helper_failed(reason: &str, connected: bool, cx: &mut Context<Installer>) ->
}

/// 7.8: the helper app is on the device; the rest is the user's there.
fn helper_steps(cx: &mut Context<Installer>) -> Div {
/// `amethyst`: in Amethyst (iOS 12 and 13), which have no Developer Mode,
/// and where the device restarts once on the first run (tools#115).
fn helper_steps(amethyst: bool, cx: &mut Context<Installer>) -> Div {
const STEPS: &[Step] = &[
Step { parts: &[Part::Text("Turn on Developer Mode in Settings > Privacy & Security, if it isn't on yet. Your iPad restarts. Confirm Turn On.")], duration: None },
Step { parts: &[Part::Text("Trust your Apple ID in Settings > General > VPN & Device Management")], duration: None },
Step { parts: &[Part::Text("Open Orchard Installer and tap Continue")], duration: None },
];
const AMETHYST_STEPS: &[Step] = &[
Step { parts: &[Part::Text("Trust your Apple ID in Settings > General > Profiles & Device Management")], duration: None },
Step { parts: &[Part::Text("Open Orchard Installer and tap Continue")], duration: None },
];
// The app can get lost over the restarts on the way: once more, then.
let again = pressable(crate::screens::link("install-again"), crate::screens::link_ring, cx, |this, _, _| this.send(Event::Retry))
.py(px(4.))
.child(div().text_size(px(14.)).text_color(c(MUTED)).child("Install the app again"));
let note = div().w_full().text_size(px(13.)).line_height(px(19.)).text_color(c(AMBER)).child("The screen restarts once after step 3. If Orchard Installer doesn't open again by itself, reopen it within 20 seconds.");
let (note, steps) = match amethyst {
true => (orchard_flow::for_device("Your iPad restarts once. Open Orchard Installer again when it's back."), AMETHYST_STEPS),
false => ("The screen restarts once after step 3. If Orchard Installer doesn't open again by itself, reopen it within 20 seconds.", STEPS),
};
let note = div().w_full().text_size(px(13.)).line_height(px(19.)).text_color(c(AMBER)).child(note);
column()
.child(header("Set up the helper app", orchard_flow::for_device("Orchard Installer is now on your iPad. Do these steps there. This window moves on as soon as it's ready."), TITLE))
.child(div().w_full().flex().flex_col().gap(px(16.)).child(note).child(steps_natural(STEPS)))
.child(div().w_full().flex().flex_col().gap(px(16.)).child(note).child(steps_natural(steps)))
.child(div().flex().flex_row().mt(px(-20.)).child(again))
}

Expand Down Expand Up @@ -1365,7 +1375,7 @@ pub fn text_column(installer: &mut Installer, cx: &mut Context<Installer>) -> Op
let connected = matches!(installer.flow.at, Some((_, orchard_flow::UsbMode::Normal)));
helper_failed(reason, connected, cx).into_any_element()
}
State::HelperSteps { .. } => helper_steps(cx).into_any_element(),
State::HelperSteps { .. } => helper_steps(installer.flow.helper() == Some(orchard_flow::Helper::Amethyst), cx).into_any_element(),
State::WaitPwned { device, failed, restarting, .. } => wait_pwned(device, *failed, *restarting, cx).into_any_element(),
State::ChooseSplit { layout, omarchy_gb, approved, .. } => {
installer.layout = Some(layout.clone());
Expand Down
9 changes: 8 additions & 1 deletion crates/app/src/screens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,12 @@ fn options_dialog(installer: &Installer, focus: &gpui::FocusHandle, cx: &mut Con
let mut greyed = Vec::new();
let (label, explanation): (&str, String) = match kind_of {
OptionsFor::Helper => {
for (at, (id, text, helper)) in [("helper-dopamine", "Dopamine", Helper::Dopamine), ("helper-palera1n", "palera1n", Helper::Palera1n), ("helper-checkra1n", "checkra1n", Helper::Checkra1n)].into_iter().enumerate() {
for (at, (id, text, helper)) in [
("helper-dopamine", "Dopamine", Helper::Dopamine),
("helper-amethyst", "Amethyst", Helper::Amethyst),
("helper-palera1n", "palera1n", Helper::Palera1n),
("helper-checkra1n", "checkra1n", Helper::Checkra1n),
].into_iter().enumerate() {
let choice = view.helpers.iter().find(|c| c.value == helper).copied();
let (selected, available) = choice.map_or((false, false), |c| (c.selected, c.available));
if !available {
Expand All @@ -955,6 +960,8 @@ fn options_dialog(installer: &Installer, focus: &gpui::FocusHandle, cx: &mut Con
}
let line = match view.helpers.iter().find(|c| c.selected).map(|c| c.value) {
Some(Helper::Dopamine) => format!("Jailbreaks your {name} without a restart."),
// tools#115: the device restarts once on Amethyst's first run.
Some(Helper::Amethyst) => format!("Jailbreaks your {name} without DFU mode. Your {name} restarts once."),
Some(_) => format!("Restarts your {name} via DFU mode into a temporary jailbreak."),
None => String::new(),
};
Expand Down
Loading
Loading