Run two commands in a terminal. On Windows, use PowerShell.
Step 1: Install latest
Or install a specific version:
macOS
Version 0.1.10, the newest
curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.10
Version 0.1.9
curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.9
Version 0.1.8
curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.8
Version 0.1.7
curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.7
Version 0.1.6
curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.6
Version 0.1.5
curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.5
Version 0.1.4
curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.4
Version 0.1.3
curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.3
Linux
Version 0.1.10, the newest
curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.10
Version 0.1.9
curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.9
Version 0.1.8
curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.8
Version 0.1.7
curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.7
Version 0.1.6
curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.6
Version 0.1.5
curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.5
Version 0.1.4
curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.4
Version 0.1.3
curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.3
Windows (PowerShell)
Version 0.1.10, the newest
& ([scriptblock]::Create((irm https://www.runfactorial.com/install.ps1))) -Version 0.1.10
Version 0.1.9
& ([scriptblock]::Create((irm https://www.runfactorial.com/install.ps1))) -Version 0.1.9
Version 0.1.8
& ([scriptblock]::Create((irm https://www.runfactorial.com/install.ps1))) -Version 0.1.8
Version 0.1.7
& ([scriptblock]::Create((irm https://www.runfactorial.com/install.ps1))) -Version 0.1.7
Version 0.1.6
& ([scriptblock]::Create((irm https://www.runfactorial.com/install.ps1))) -Version 0.1.6
Version 0.1.5
& ([scriptblock]::Create((irm https://www.runfactorial.com/install.ps1))) -Version 0.1.5
Version 0.1.4
& ([scriptblock]::Create((irm https://www.runfactorial.com/install.ps1))) -Version 0.1.4
Version 0.1.3
& ([scriptblock]::Create((irm https://www.runfactorial.com/install.ps1))) -Version 0.1.3
macOS
curl -fsSL https://www.runfactorial.com/install.sh | sh
Read install.sh
#!/bin/sh
# Installs or upgrades Factorial in $HOME/factorial. It never starts the stack: it ends by
# printing the command that does (`docker compose up -d --wait` in the folder):
# curl -fsSL https://www.runfactorial.com/install.sh | sh
# curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.3
# Installs made before this script are not supported: it knows only the stack it writes, whose
# data is the `factorial-public` volume.
# - The version: --version, else FACTORIAL_VERSION, else the one the folder's compose.yaml pins,
# else the site's version.txt. When version.txt is newer than the pinned one, it asks before an
# upgrade, on /dev/tty because stdin is the pipe from curl. With no terminal it stays on the
# installed version. A version older than the pinned one is refused without --force: the
# database is not migrated back.
# - A new version is pulled before anything changes, so a failed pull leaves the stack running.
# Then an upgrade takes the stack down (`docker compose down`, never -v: it removes the
# containers and keeps the volume) and backs up the volume to backups/. A failed backup leaves
# compose.yaml on the installed version.
# - factorial-setup writes factorial.env and seccomp.json on the first run only. A rerun never
# changes factorial.env. A `factorial-public` volume with no factorial.env in the folder stops
# the script: its secrets open only with the file they were made with.
# - compose.yaml is written from the site's template on a first run or a version change only
# (the template's header names the tag rule).
# - It never uses sudo, and never removes a volume or a folder.
# - MIN_VERSION is the oldest version it installs, the first with the two-container stack: a
# --version or a version.txt below it is refused. landing/build/version.ts names the same floor.
# install.ps1 is the same flow for Windows; keep the two in step.
# FACTORIAL_SITE replaces the site address, for tests.
set -eu
MIN_VERSION=0.1.3
main() {
site=${FACTORIAL_SITE:-https://www.runfactorial.com}
dir=$HOME/factorial
requested=${FACTORIAL_VERSION:-}
force=
while [ $# -gt 0 ]; do
case $1 in
--version) [ $# -ge 2 ] || fail "--version needs a value, such as --version 0.1.3."
requested=$2; shift 2 ;;
--version=*) requested=${1#--version=}; shift ;;
--force) force=1; shift ;;
*) fail "Unknown option $1. The options are --version X.Y.Z and --force." ;;
esac
done
[ -z "$requested" ] || is_version "$requested" \
|| fail "$requested is not a version. Give one such as 0.1.3."
[ -z "$requested" ] || supported "$requested"
command -v docker >/dev/null 2>&1 \
|| fail "Docker is not installed. Install Docker Desktop or Docker Engine, then run this again."
docker compose version >/dev/null 2>&1 \
|| fail "Docker Compose is not installed. Install the docker compose plugin, then run this again."
docker info >/dev/null 2>&1 \
|| fail "Docker is not running. Start Docker, then run this again."
mkdir -p "$dir"
cd "$dir"
if docker volume inspect factorial-public >/dev/null 2>&1 && [ ! -f factorial.env ]; then
fail "A Factorial data volume already exists. Put the factorial.env it was made with in $dir, or remove the volume with docker volume rm factorial-public to start over."
fi
template=$(mktemp)
trap 'rm -f "$template"' EXIT
newest=$(curl -fsSL "$site/version.txt") \
|| fail "Cannot read $site/version.txt. Check the network, then run this again."
newest=$(printf '%s' "$newest" | tr -d ' \r\n')
is_version "$newest" || fail "$site/version.txt does not hold a version."
supported "$newest"
curl -fsSL -o "$template" "$site/docs/run-the-public-image/compose.yaml" \
|| fail "Cannot read the compose.yaml template from $site. Check the network, then run this again."
image=$(sed -n 's/^ *image: *\([^ ]*\):[^:]*$/\1/p' "$template" | head -n 1)
[ -n "$image" ] || fail "The compose.yaml template names no image."
installed=
[ -f compose.yaml ] && installed=$(sed -n 's/^ *image: *[^ ]*:\([^:]*\)$/\1/p' compose.yaml | head -n 1)
[ -z "$installed" ] || is_version "$installed" || installed=
if [ -n "$installed" ] && newer "$MIN_VERSION" "$installed"; then
fail "$dir holds an install made before $MIN_VERSION, which this script does not upgrade. Run docker compose down in $dir, move the folder away (its factorial.env opens the old factorial volume), then run this again."
fi
version=$requested
if [ -n "$version" ] && [ -n "$installed" ] && newer "$installed" "$version" && [ -z "$force" ]; then
fail "Factorial $installed is installed, and $version is older. The database is not migrated back, so going back means restoring a backup from $dir/backups made before the upgrade. To start $version on this data anyway, add --force."
fi
if [ -z "$version" ] && [ -n "$installed" ]; then
version=$installed
if newer "$newest" "$installed"; then
if ask "Factorial $installed is installed and $newest is available. Upgrade now? A backup of the data is made first. [y/N] "; then
version=$newest
else
say "Factorial $installed is installed and $newest is available. $installed stays. To upgrade, run this again from a terminal, or run: curl -fsSL $site/install.sh | sh -s -- --version $newest"
fi
fi
fi
[ -n "$version" ] || version=$newest
first=
[ -f factorial.env ] || first=1
if [ "$version" != "$installed" ]; then
docker pull --platform linux/amd64 "$image:$version" \
|| fail "Cannot pull $image:$version. Nothing changed. Check the network, then run this again."
fi
if [ -n "$first" ]; then
say "Making the keys in $dir/factorial.env."
docker run --rm --platform linux/amd64 -v "$dir:/out" --entrypoint factorial-setup "$image:$version" >/dev/null
fi
if [ -n "$installed" ] && [ "$version" != "$installed" ]; then
backup=factorial-$installed-$(date -u +%Y%m%dT%H%M%SZ).tgz
say "Stopping Factorial $installed, and saving a backup of the data to $dir/backups/$backup."
docker compose down
mkdir -p backups
docker run --rm --platform linux/amd64 --entrypoint tar -v factorial-public:/data \
-v "$dir/backups:/backup" "$image:$installed" -czf "/backup/$backup" -C /data . \
|| fail "The backup failed, so Factorial stays on $installed, stopped. Run docker compose up -d in $dir to start $installed again."
fi
if [ "$version" != "$installed" ]; then
sed "s|^\( *image: *[^ ]*:\)[^:]*\$|\1$version|" "$template" > compose.yaml
fi
say ""
say "Factorial $version is installed in $dir."
if [ -n "$installed" ] && [ "$version" != "$installed" ]; then
say "The stack is stopped until you start it."
fi
say "To start it, run: cd ~/factorial && docker compose up -d --wait"
say "Then open http://localhost:8000/factorial/"
if [ -n "$first" ]; then
say "There, push Create an account. The first account becomes the owner."
fi
}
say() { printf '%s\n' "$1"; }
fail() {
printf '%s\n' "$1" >&2
exit 1
}
is_version() {
printf '%s\n' "$1" | grep -Eq '^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'
}
# True when $1 is a higher X.Y.Z than $2.
newer() {
old_ifs=$IFS
IFS=.
# shellcheck disable=SC2086
set -- $1 $2
IFS=$old_ifs
[ "$1" -gt "$4" ] && return 0
[ "$1" -lt "$4" ] && return 1
[ "$2" -gt "$5" ] && return 0
[ "$2" -lt "$5" ] && return 1
[ "$3" -gt "$6" ]
}
supported() {
if newer "$MIN_VERSION" "$1"; then
fail "Factorial $1 predates this install script; use $MIN_VERSION or later."
fi
}
# Opening /dev/tty fails with no controlling terminal; then the answer is no.
ask() {
(: </dev/tty) 2>/dev/null || return 1
printf '%s' "$1" >/dev/tty
read -r answer </dev/tty || return 1
case $answer in
y | Y | yes | Yes | YES) return 0 ;;
*) return 1 ;;
esac
}
main "$@"Linux
curl -fsSL https://www.runfactorial.com/install.sh | sh
Read install.sh
#!/bin/sh
# Installs or upgrades Factorial in $HOME/factorial. It never starts the stack: it ends by
# printing the command that does (`docker compose up -d --wait` in the folder):
# curl -fsSL https://www.runfactorial.com/install.sh | sh
# curl -fsSL https://www.runfactorial.com/install.sh | sh -s -- --version 0.1.3
# Installs made before this script are not supported: it knows only the stack it writes, whose
# data is the `factorial-public` volume.
# - The version: --version, else FACTORIAL_VERSION, else the one the folder's compose.yaml pins,
# else the site's version.txt. When version.txt is newer than the pinned one, it asks before an
# upgrade, on /dev/tty because stdin is the pipe from curl. With no terminal it stays on the
# installed version. A version older than the pinned one is refused without --force: the
# database is not migrated back.
# - A new version is pulled before anything changes, so a failed pull leaves the stack running.
# Then an upgrade takes the stack down (`docker compose down`, never -v: it removes the
# containers and keeps the volume) and backs up the volume to backups/. A failed backup leaves
# compose.yaml on the installed version.
# - factorial-setup writes factorial.env and seccomp.json on the first run only. A rerun never
# changes factorial.env. A `factorial-public` volume with no factorial.env in the folder stops
# the script: its secrets open only with the file they were made with.
# - compose.yaml is written from the site's template on a first run or a version change only
# (the template's header names the tag rule).
# - It never uses sudo, and never removes a volume or a folder.
# - MIN_VERSION is the oldest version it installs, the first with the two-container stack: a
# --version or a version.txt below it is refused. landing/build/version.ts names the same floor.
# install.ps1 is the same flow for Windows; keep the two in step.
# FACTORIAL_SITE replaces the site address, for tests.
set -eu
MIN_VERSION=0.1.3
main() {
site=${FACTORIAL_SITE:-https://www.runfactorial.com}
dir=$HOME/factorial
requested=${FACTORIAL_VERSION:-}
force=
while [ $# -gt 0 ]; do
case $1 in
--version) [ $# -ge 2 ] || fail "--version needs a value, such as --version 0.1.3."
requested=$2; shift 2 ;;
--version=*) requested=${1#--version=}; shift ;;
--force) force=1; shift ;;
*) fail "Unknown option $1. The options are --version X.Y.Z and --force." ;;
esac
done
[ -z "$requested" ] || is_version "$requested" \
|| fail "$requested is not a version. Give one such as 0.1.3."
[ -z "$requested" ] || supported "$requested"
command -v docker >/dev/null 2>&1 \
|| fail "Docker is not installed. Install Docker Desktop or Docker Engine, then run this again."
docker compose version >/dev/null 2>&1 \
|| fail "Docker Compose is not installed. Install the docker compose plugin, then run this again."
docker info >/dev/null 2>&1 \
|| fail "Docker is not running. Start Docker, then run this again."
mkdir -p "$dir"
cd "$dir"
if docker volume inspect factorial-public >/dev/null 2>&1 && [ ! -f factorial.env ]; then
fail "A Factorial data volume already exists. Put the factorial.env it was made with in $dir, or remove the volume with docker volume rm factorial-public to start over."
fi
template=$(mktemp)
trap 'rm -f "$template"' EXIT
newest=$(curl -fsSL "$site/version.txt") \
|| fail "Cannot read $site/version.txt. Check the network, then run this again."
newest=$(printf '%s' "$newest" | tr -d ' \r\n')
is_version "$newest" || fail "$site/version.txt does not hold a version."
supported "$newest"
curl -fsSL -o "$template" "$site/docs/run-the-public-image/compose.yaml" \
|| fail "Cannot read the compose.yaml template from $site. Check the network, then run this again."
image=$(sed -n 's/^ *image: *\([^ ]*\):[^:]*$/\1/p' "$template" | head -n 1)
[ -n "$image" ] || fail "The compose.yaml template names no image."
installed=
[ -f compose.yaml ] && installed=$(sed -n 's/^ *image: *[^ ]*:\([^:]*\)$/\1/p' compose.yaml | head -n 1)
[ -z "$installed" ] || is_version "$installed" || installed=
if [ -n "$installed" ] && newer "$MIN_VERSION" "$installed"; then
fail "$dir holds an install made before $MIN_VERSION, which this script does not upgrade. Run docker compose down in $dir, move the folder away (its factorial.env opens the old factorial volume), then run this again."
fi
version=$requested
if [ -n "$version" ] && [ -n "$installed" ] && newer "$installed" "$version" && [ -z "$force" ]; then
fail "Factorial $installed is installed, and $version is older. The database is not migrated back, so going back means restoring a backup from $dir/backups made before the upgrade. To start $version on this data anyway, add --force."
fi
if [ -z "$version" ] && [ -n "$installed" ]; then
version=$installed
if newer "$newest" "$installed"; then
if ask "Factorial $installed is installed and $newest is available. Upgrade now? A backup of the data is made first. [y/N] "; then
version=$newest
else
say "Factorial $installed is installed and $newest is available. $installed stays. To upgrade, run this again from a terminal, or run: curl -fsSL $site/install.sh | sh -s -- --version $newest"
fi
fi
fi
[ -n "$version" ] || version=$newest
first=
[ -f factorial.env ] || first=1
if [ "$version" != "$installed" ]; then
docker pull --platform linux/amd64 "$image:$version" \
|| fail "Cannot pull $image:$version. Nothing changed. Check the network, then run this again."
fi
if [ -n "$first" ]; then
say "Making the keys in $dir/factorial.env."
docker run --rm --platform linux/amd64 -v "$dir:/out" --entrypoint factorial-setup "$image:$version" >/dev/null
fi
if [ -n "$installed" ] && [ "$version" != "$installed" ]; then
backup=factorial-$installed-$(date -u +%Y%m%dT%H%M%SZ).tgz
say "Stopping Factorial $installed, and saving a backup of the data to $dir/backups/$backup."
docker compose down
mkdir -p backups
docker run --rm --platform linux/amd64 --entrypoint tar -v factorial-public:/data \
-v "$dir/backups:/backup" "$image:$installed" -czf "/backup/$backup" -C /data . \
|| fail "The backup failed, so Factorial stays on $installed, stopped. Run docker compose up -d in $dir to start $installed again."
fi
if [ "$version" != "$installed" ]; then
sed "s|^\( *image: *[^ ]*:\)[^:]*\$|\1$version|" "$template" > compose.yaml
fi
say ""
say "Factorial $version is installed in $dir."
if [ -n "$installed" ] && [ "$version" != "$installed" ]; then
say "The stack is stopped until you start it."
fi
say "To start it, run: cd ~/factorial && docker compose up -d --wait"
say "Then open http://localhost:8000/factorial/"
if [ -n "$first" ]; then
say "There, push Create an account. The first account becomes the owner."
fi
}
say() { printf '%s\n' "$1"; }
fail() {
printf '%s\n' "$1" >&2
exit 1
}
is_version() {
printf '%s\n' "$1" | grep -Eq '^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'
}
# True when $1 is a higher X.Y.Z than $2.
newer() {
old_ifs=$IFS
IFS=.
# shellcheck disable=SC2086
set -- $1 $2
IFS=$old_ifs
[ "$1" -gt "$4" ] && return 0
[ "$1" -lt "$4" ] && return 1
[ "$2" -gt "$5" ] && return 0
[ "$2" -lt "$5" ] && return 1
[ "$3" -gt "$6" ]
}
supported() {
if newer "$MIN_VERSION" "$1"; then
fail "Factorial $1 predates this install script; use $MIN_VERSION or later."
fi
}
# Opening /dev/tty fails with no controlling terminal; then the answer is no.
ask() {
(: </dev/tty) 2>/dev/null || return 1
printf '%s' "$1" >/dev/tty
read -r answer </dev/tty || return 1
case $answer in
y | Y | yes | Yes | YES) return 0 ;;
*) return 1 ;;
esac
}
main "$@"Windows (PowerShell)
irm https://www.runfactorial.com/install.ps1 | iex
Read install.ps1
# Installs or upgrades Factorial in $HOME\factorial. It never starts the stack: it ends by printing
# the command that does (`docker compose up -d --wait` in the folder). Runs under Windows
# PowerShell 5.1 and PowerShell 7:
# irm https://www.runfactorial.com/install.ps1 | iex
# & ([scriptblock]::Create((irm https://www.runfactorial.com/install.ps1))) -Version 0.1.3
# Installs made before this script are not supported: it knows only the stack it writes, whose
# data is the `factorial-public` volume.
# - The version: -Version, else FACTORIAL_VERSION, else the one the folder's compose.yaml pins,
# else the site's version.txt. When version.txt is newer than the pinned one, it asks before an
# upgrade. With no console to ask on, it stays on the installed version. A version older than
# the pinned one is refused without -Force: the database is not migrated back.
# - A new version is pulled before anything changes, so a failed pull leaves the stack running.
# Then an upgrade takes the stack down (`docker compose down`, never -v: it removes the
# containers and keeps the volume) and backs up the volume to backups\. A failed backup leaves
# compose.yaml on the installed version.
# - factorial-setup writes factorial.env and seccomp.json on the first run only. A rerun never
# changes factorial.env. A `factorial-public` volume with no factorial.env in the folder stops
# the script: its secrets open only with the file they were made with.
# - compose.yaml is written from the site's template on a first run or a version change only
# (the template's header names the tag rule).
# - It never removes a volume or a folder. It reports a failure and returns, never `exit`, which
# would close the window it was pasted into.
# - $MinVersion is the oldest version it installs, the first with the two-container stack: a
# -Version or a version.txt below it is refused. landing/build/version.ts names the same floor.
# install.sh is the same flow for macOS and Linux; keep the two in step.
# FACTORIAL_SITE replaces the site address, for tests.
param([string]$Version = "", [switch]$Force)
$MinVersion = "0.1.3"
function Stop-Install([string]$Message) {
throw [System.Exception]::new($Message)
}
function Test-Version([string]$Value) {
return $Value -match '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$'
}
function Assert-Supported([string]$Value) {
if ([version]$Value -lt [version]$MinVersion) {
Stop-Install "Factorial $Value predates this install script; use $MinVersion or later."
}
}
# Native commands run under Continue: Windows PowerShell 5.1 turns a native stderr line into an
# error that Stop throws. The exit code is the only verdict. Out-Host keeps docker's output off
# the pipeline, where it would join the returned value.
function Invoke-Native([string[]]$DockerArgs, [switch]$Quiet, [switch]$DropOutput) {
$saved = $ErrorActionPreference
$ErrorActionPreference = "Continue"
try {
if ($Quiet) { & docker @DockerArgs *> $null } elseif ($DropOutput) { & docker @DockerArgs | Out-Null } else { & docker @DockerArgs | Out-Host }
return ($LASTEXITCODE -eq 0)
} catch {
return $false
} finally {
$ErrorActionPreference = $saved
}
}
function Test-Docker([string[]]$DockerArgs) {
return (Invoke-Native $DockerArgs -Quiet)
}
function Invoke-Docker([string[]]$DockerArgs, [string]$Failure = "", [switch]$DropOutput) {
if (-not (Invoke-Native $DockerArgs -DropOutput:$DropOutput)) {
if (-not $Failure) { $Failure = "docker $($DockerArgs -join ' ') failed. Its message is above." }
Stop-Install $Failure
}
}
function Get-SiteFile([string]$Url, [string]$Path) {
try {
Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile $Path
} catch {
Stop-Install "Cannot read $Url. Check the network, then run this again."
}
}
function Get-ImageMatch([string]$Text, [int]$Group) {
$found = [regex]::Match($Text, '(?m)^[ \t]*image:[ \t]*(\S+):([^:\s]+)[ \t]*\r?$')
if ($found.Success) { return $found.Groups[$Group].Value }
return ""
}
function Install-Factorial([string]$Requested, [bool]$Override) {
$ErrorActionPreference = "Stop"
$site = $env:FACTORIAL_SITE
if (-not $site) { $site = "https://www.runfactorial.com" }
$dir = Join-Path $HOME "factorial"
if (-not $Requested) { $Requested = $env:FACTORIAL_VERSION }
if ($Requested -and -not (Test-Version $Requested)) {
Stop-Install "$Requested is not a version. Give one such as 0.1.3."
}
if ($Requested) { Assert-Supported $Requested }
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
Stop-Install "Docker is not installed. Install Docker Desktop, then run this again."
}
if (-not (Test-Docker @("compose", "version"))) {
Stop-Install "Docker Compose is not installed. Update Docker Desktop, then run this again."
}
if (-not (Test-Docker @("info"))) {
Stop-Install "Docker is not running. Start Docker Desktop, then run this again."
}
New-Item -ItemType Directory -Force -Path $dir | Out-Null
Set-Location $dir
$envFile = Join-Path $dir "factorial.env"
$composeFile = Join-Path $dir "compose.yaml"
if ((Test-Docker @("volume", "inspect", "factorial-public")) -and -not (Test-Path $envFile)) {
Stop-Install "A Factorial data volume already exists. Put the factorial.env it was made with in $dir, or remove the volume with docker volume rm factorial-public to start over."
}
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$download = [IO.Path]::GetTempFileName()
try {
Get-SiteFile "$site/version.txt" $download
$newest = ([IO.File]::ReadAllText($download)).Trim()
Get-SiteFile "$site/docs/run-the-public-image/compose.yaml" $download
$template = [IO.File]::ReadAllText($download)
} finally {
Remove-Item -Force $download -ErrorAction SilentlyContinue
}
if (-not (Test-Version $newest)) { Stop-Install "$site/version.txt does not hold a version." }
Assert-Supported $newest
$image = Get-ImageMatch $template 1
if (-not $image) { Stop-Install "The compose.yaml template names no image." }
$installed = ""
if (Test-Path $composeFile) { $installed = Get-ImageMatch ([IO.File]::ReadAllText($composeFile)) 2 }
if ($installed -and -not (Test-Version $installed)) { $installed = "" }
if ($installed -and ([version]$installed -lt [version]$MinVersion)) {
Stop-Install "$dir holds an install made before $MinVersion, which this script does not upgrade. Run docker compose down in $dir, move the folder away (its factorial.env opens the old factorial volume), then run this again."
}
$chosen = $Requested
if ($chosen -and $installed -and ([version]$installed -gt [version]$chosen) -and -not $Override) {
Stop-Install "Factorial $installed is installed, and $chosen is older. The database is not migrated back, so going back means restoring a backup from $dir\backups made before the upgrade. To start $chosen on this data anyway, add -Force."
}
if (-not $chosen -and $installed) {
$chosen = $installed
if ([version]$newest -gt [version]$installed) {
$answer = $null
try {
$answer = Read-Host "Factorial $installed is installed and $newest is available. Upgrade now? A backup of the data is made first. [y/N]"
} catch {
$answer = $null
}
if ($answer -match '^(y|yes)$') {
$chosen = $newest
} else {
Write-Host "Factorial $installed is installed and $newest is available. $installed stays. To upgrade, run this again from a terminal, or run: & ([scriptblock]::Create((irm $site/install.ps1))) -Version $newest"
}
}
}
if (-not $chosen) { $chosen = $newest }
$first = -not (Test-Path $envFile)
if ($chosen -ne $installed) {
Invoke-Docker @("pull", "--platform", "linux/amd64", "${image}:$chosen") "Cannot pull ${image}:$chosen. Nothing changed. Check the network, then run this again."
}
if ($first) {
Write-Host "Making the keys in $envFile."
Invoke-Docker @("run", "--rm", "--platform", "linux/amd64", "-v", "${dir}:/out", "--entrypoint", "factorial-setup", "${image}:$chosen") -DropOutput
}
if ($installed -and $chosen -ne $installed) {
$stamp = (Get-Date).ToUniversalTime().ToString("yyyyMMdd'T'HHmmss'Z'")
$backup = "factorial-$installed-$stamp.tgz"
$backups = Join-Path $dir "backups"
Write-Host "Stopping Factorial $installed, and saving a backup of the data to $backups\$backup."
Invoke-Docker @("compose", "down")
New-Item -ItemType Directory -Force -Path $backups | Out-Null
Invoke-Docker @("run", "--rm", "--platform", "linux/amd64", "--entrypoint", "tar", "-v", "factorial-public:/data", "-v", "${backups}:/backup", "${image}:$installed", "-czf", "/backup/$backup", "-C", "/data", ".") "The backup failed, so Factorial stays on $installed, stopped. Run docker compose up -d in $dir to start $installed again."
}
if ($chosen -ne $installed) {
$compose = [regex]::Replace($template, '(?m)^([ \t]*image:[ \t]*\S+:)[^:\s]+', '${1}' + $chosen)
[IO.File]::WriteAllText($composeFile, $compose, [Text.UTF8Encoding]::new($false))
}
Write-Host ""
Write-Host "Factorial $chosen is installed in $dir."
if ($installed -and $chosen -ne $installed) {
Write-Host "The stack is stopped until you start it."
}
Write-Host "To start it, run: Set-Location `$HOME\factorial; docker compose up -d --wait"
Write-Host "Then open http://localhost:8000/factorial/"
if ($first) {
Write-Host "There, push Create an account. The first account becomes the owner."
}
}
Push-Location
try {
Install-Factorial $Version $Force.IsPresent
} catch {
Write-Host $_.Exception.Message -ForegroundColor Red
} finally {
Pop-Location
}The script:
- Checks that Docker and Compose run, then works in
~/factorial($HOME\factorialon Windows). - On the first run only, writes
factorial.envwith new keys, andseccomp.json. A rerun never changesfactorial.env. - Writes
compose.yamlwith the version pinned, on a first run or a version change only. - Does not start Factorial, and never removes a volume or a folder.
Step 2: Run
macOS
cd ~/factorial && docker compose up -d --wait
Linux
cd ~/factorial && docker compose up -d --wait
Windows (PowerShell)
Set-Location $HOME\factorial; docker compose up -d --wait
The command returns when both containers are ready.
Then open http://localhost:8000/factorial/ and push Create an account. The first account becomes the owner, so make yours before other people can reach the dashboard.
Next, Your first project connects a repository and takes its first ticket through a gate.