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
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,13 @@ jobs:
--orchard-release "$HARDWARE_TAG" --orchard .orchard --version "$VERSION" --output out/release-armv7
python audit.py out/release-armv7 --orchard .orchard
python -m orchard.manifests --verify-local out/release-armv7/index.toml
# The installer: install.sh and orchard-install.pyz with orchard's launch loaders.
python -m orchard.installer release out/release \
--pongo "$tools/quiet/pongo.bin" --m1n1 "$tools/quiet/m1n1.bin"
# One release, both roots: its index pins each root's manifest, the board picks by architecture.
python -m orchard.image.publish --distro minimal-linux --tag "$TAG" \
--release-dir out/release --release-dir out/release-armv7 --output out/publication
# install.sh: installs the orchard command and runs `orchard install` for this release.
base="https://github.com/$GITHUB_REPOSITORY/releases/download/$TAG"
python release/install_script.py --index "$base/index.toml" --url "$base/install.sh" \
--output out/publication/install.sh
cp out/release/rootfs.json out/release/build-receipt.json out/base/* out/publication/
cp out/release-armv7/rootfs.json out/publication/rootfs-armv7.json
cp out/release-armv7/build-receipt.json out/publication/build-receipt-armv7.json
Expand Down
3 changes: 2 additions & 1 deletion BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ python3 build.py --base out/base/base.tar.gz --base-receipt out/base/base.tar.gz
--version YOUR_NEW_VERSION --output out/releases/YOUR_NEW_VERSION
python3 audit.py out/releases/YOUR_NEW_VERSION --orchard "$ORCHARD"
python3 -m orchard.manifests --verify-local out/releases/YOUR_NEW_VERSION/index.toml
python3 -m orchard.installer release out/releases/YOUR_NEW_VERSION
python3 release/install_script.py --index index.toml --url install.sh \
--output out/releases/YOUR_NEW_VERSION/install.sh
```

`orchard.inputs` takes the nightly's kernels, m1n1 and tools when they were
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ Distro builds use the orchard checkout `orchard` runs and explicit component art
## Install

Back up the device first; storage changes can permanently erase data. With the
device in DFU mode, a published release installs with its own installer, which
brings its own Python:
device in DFU mode, a published release installs with its `install.sh`, which
installs the `orchard` command and runs `orchard install` for the release:

```sh
curl -fsSL https://github.com/OrchardLinux/minimal-linux/releases/latest/download/install.sh | sh
```

A local build has the same installer next to it (`sh out/releases/VERSION/install.sh`),
A local build has the same script next to it (`sh out/releases/VERSION/install.sh`),
or install it with your orchard checkout:

```sh
Expand Down
22 changes: 22 additions & 0 deletions release/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
# Install Minimal Linux on an iPad or iPhone in DFU mode:
# curl -fsSL @URL@ | sh
# It installs the orchard command (OrchardLinux/tools) or brings it up to
# date, then runs `orchard install` for this release. Arguments go to
# `orchard install`: sh -s -- --ibss, for example.
set -eu
INDEX=@INDEX@
# Next to a local build, its own index.
case "$0" in
install.sh|*/install.sh)
here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
[ ! -f "$here/index.toml" ] || INDEX="$here/index.toml" ;;
esac
command -v curl >/dev/null 2>&1 || { echo 'curl is needed to download the orchard command.' >&2; exit 1; }
curl -fsSL https://raw.githubusercontent.com/OrchardLinux/tools/main/install.sh | sh
orchard=${ORCHARD_BIN:-$HOME/.local/bin}/orchard
# The installer asks on the terminal, also when this script came through a pipe.
if [ -t 0 ] || ! (: </dev/tty) 2>/dev/null; then
exec "$orchard" install "$INDEX" "$@"
fi
exec "$orchard" install "$INDEX" "$@" </dev/tty
36 changes: 36 additions & 0 deletions release/install_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3
"""A release's install.sh: installs the orchard command and runs `orchard install` for that release.

python -m release.install_script --index URL --url URL --output install.sh
"""
import argparse
from pathlib import Path
import re

TEMPLATE = Path(__file__).with_name('install.sh')


def write(output, index, url):
"""install.sh at OUTPUT for the release whose index is INDEX; URL is where the script itself is fetched from."""
for value in (index, url):
if not re.fullmatch(r"[A-Za-z0-9:/._~+-]+", value):
raise ValueError(f'Not a plain URL or path: {value}')
text = TEMPLATE.read_text().replace('@INDEX@', "'" + index + "'").replace('@URL@', url)
output = Path(output)
output.parent.mkdir(parents=True, exist_ok=True)
output.write_text(text)
output.chmod(0o755)
return output


def main():
parser = argparse.ArgumentParser(description=__doc__.split('\n\n')[0])
parser.add_argument('--index', required=True, help="the release's index.toml: its URL, or a path for a local build")
parser.add_argument('--url', required=True, help='where this install.sh is published')
parser.add_argument('--output', required=True, type=Path)
args = parser.parse_args()
print(write(args.output, args.index, args.url))


if __name__ == '__main__':
main()
57 changes: 57 additions & 0 deletions tests/test_install_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""A release's install.sh installs the orchard command and runs `orchard install` for that release. No network or device."""
from pathlib import Path
import subprocess
import tempfile
import unittest

import importlib.util, pathlib
_spec = importlib.util.spec_from_file_location('install_script', pathlib.Path(__file__).resolve().parents[1] / 'release/install_script.py')
install_script = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(install_script)

INDEX = 'https://github.com/OrchardLinux/minimal-linux/releases/download/v9.9.9/index.toml'


class InstallScript(unittest.TestCase):
def setUp(self):
temporary = tempfile.TemporaryDirectory()
self.addCleanup(temporary.cleanup)
self.root = Path(temporary.name).resolve()
self.bin = self.root / 'bin'
self.bin.mkdir()
self.log = self.root / 'log'
# curl prints a script that "installs" the command; the command records how it was called.
(self.root / 'command').write_text('#!/bin/sh\nprintf "orchard %s\\n" "$*" >> "$LOG"\n')
(self.root / 'tools-install.sh').write_text('cp "$HOME/command" "$ORCHARD_BIN/orchard"; chmod 755 "$ORCHARD_BIN/orchard"\n')
(self.bin / 'curl').write_text('#!/bin/sh\nprintf "curl %s\\n" "$*" >> "$LOG"\ncat "$HOME/tools-install.sh"\n')
(self.bin / 'curl').chmod(0o755)
self.script = install_script.write(self.root / 'install.sh', INDEX, INDEX.replace('index.toml', 'install.sh'))

def run_script(self, *arguments, script=None):
return subprocess.run(['sh', str(script or self.script), *arguments], capture_output=True, text=True,
stdin=subprocess.DEVNULL, start_new_session=True,
env={'PATH': f'{self.bin}:/usr/bin:/bin', 'HOME': str(self.root), 'LOG': str(self.log),
'ORCHARD_BIN': str(self.bin)})

def test_installs_the_command_then_installs_this_release_with_the_arguments(self):
result = self.run_script('--ibss')
self.assertEqual(result.returncode, 0, result.stderr)
self.assertEqual(self.log.read_text().splitlines(),
['curl -fsSL https://raw.githubusercontent.com/OrchardLinux/tools/main/install.sh',
f'orchard install {INDEX} --ibss'])

def test_next_to_a_local_build_it_installs_that_build(self):
local = self.root / 'release'
local.mkdir()
(local / 'index.toml').write_text('')
script = install_script.write(local / 'install.sh', INDEX, 'install.sh')
self.assertEqual(self.run_script(script=script).returncode, 0)
self.assertEqual(self.log.read_text().splitlines()[-1], f'orchard install {local}/index.toml')

def test_only_plain_urls_are_written_into_the_script(self):
with self.assertRaises(ValueError):
install_script.write(self.root / 'x.sh', "x'; rm -rf ~; '", 'install.sh')


if __name__ == '__main__':
unittest.main()
8 changes: 3 additions & 5 deletions tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,9 @@ def main():
'--inputs', inputs / 'inputs.json', '--orchard-inputs', resolved, '--orchard', orchard,
'--version', args.version, '--output', args.output)
python('audit.py', args.output, '--orchard', orchard)
# install.sh and orchard-install.pyz, with orchard's launch loaders: the resolved ones, where the
# document names them (an armv7 one from orchard's Python does not), so the installer builds none.
loaders = (['--pongo', shared['pongo'], '--m1n1', shared['m1n1']]
if {'pongo', 'm1n1'} <= shared.keys() else [])
snapshot.command(orchard, 'installer', 'release', args.output, *loaders)
# install.sh: installs the orchard command and runs `orchard install` for the index beside it.
python('release/install_script.py', '--index', 'index.toml', '--url', 'install.sh',
'--output', Path(args.output) / 'install.sh')


if __name__ == '__main__':
Expand Down
Loading