Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-install/blob/main/install.sh # interplane-install This project has not described itself yet. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-install / install.sh` 425 lines ยท 27050 bytes Raw Blame History 1 #!/bin/sh 2 # install.sh: put Omega and your own Interplane on this machine, owned by you. 3 # What it does and what it needs: `sh install.sh --help`. That text is in usage() below, in one 4 # place, so it also works when this file is piped into sh. 5 # Exit: 0 done; 1 usage; 2 this machine cannot run it (says why); 3 a download or check failed. 6 # This file is POSIX shell because it has to run before Omega exists on the machine. 7 set -eu 8 umask 077 9 10 # The pins: the Omega release whose compiler becomes `omc`, and the Interplane forge commit whose 11 # store tool (ipl/) is built. The compiler the store tool needs is read from that commit's ipl/PIN. 12 # Git ids are SHA-1; the compilers are also pinned by SHA-256, and that stays: it is what checks the 13 # binary that is run, whatever git says about the commit. 14 OMEGA_RELEASE=`3086ed3ca1061b2625a48d175cd5ac990e783655` 15 OMEGA_RELEASE_OMC_SHA256=`34d611ca0415eab1728d3234911d90e74af17ba9ab0c581d559f48274d7ca6d3` 16 FORGE_COMMIT=`be780afc754657aba010a2f14e6c0c0b14926bac` 17 18 say() { printf '%s\n' "$*"; } 19 step() { printf '\n== %s\n' "$*"; } 20 die() { code=$1; shift; printf 'interplane install: %s\n' "$*" >&2; exit "$code"; } 21 usage() { 22 cat <<'EOF' 23 install.sh: put Omega and your own Interplane on this machine, owned by you. 24 25 sh install.sh [--store DIR] [--quick] [--help] 26 27 What it does, in order. Nothing is sent anywhere; it only downloads. 28 1. checks this machine can run Omega's compiler (64-bit Arm Linux today) and has the tools 29 Interplane uses (bash, git 2.29 or newer, ssh-keygen, flock and the usual coreutils) 30 2. downloads the Omega and Interplane source with plain git from interplane.io (on a later run, 31 only what is new since your store's copy). Run by name from a clone of this repository, it 32 installs exactly the commit you checked out, and refuses when install.sh itself has changes that 33 are not committed; run through a pipe, it takes this installer from the source 34 3. takes the Omega compiler out of the source at the release commit pinned in this file and checks 35 its SHA-256; takes the compiler Interplane's store tool is pinned to the same way 36 4. builds Interplane's store tool from source with that compiler and runs its own test gate 37 (81 seconds on a DGX Spark; --quick skips it) 38 5. makes your owner key (Ed25519, stays on this machine) unless you already have one 39 6. puts Omega, Interplane and this installer in your store as your own private projects, each 40 with a signed first record; on a later run, records their newest heads as signed landings 41 7. installs `omc` and `interplane` in ~/.local/bin (a file you put there yourself is kept; an omc 42 this installer put there earlier is replaced by the new release's) 43 Running it again finishes what an earlier run left, brings the three projects up to the newest 44 main the source serves (what is built and installed stays the pinned commits), and changes nothing 45 else. Your store and everything in ~/.config/interplane are readable only by you. A store is chosen 46 once: --store with a different folder than the one already configured is refused, and so is a 47 folder that already has other files in it. An installer older than the one in your store is refused. 48 49 Environment: INTERPLANE_SOURCE (where to clone from, default https://interplane.io/projects; a 50 directory of NAME/repo.git also works; a password or token in it is never printed or written), 51 XDG_DATA_HOME, XDG_CONFIG_HOME, INTERPLANE_BIN. 52 Exit: 0 done; 1 usage; 2 this machine cannot run it (says why); 3 a download or check failed. 53 EOF 54 } 55 56 SRC=${INTERPLANE_SOURCE:-https://interplane.io/projects} 57 # SRC is only the address git downloads from. Everything printed or written says SHOWN, which has 58 # any password or token in the address taken out. 59 SHOWN=$(printf '%s' "$SRC" | sed 's#^\([a-z+]*://\)[^/]*@#\1#') 60 DATA=${XDG_DATA_HOME:-$HOME/.local/share}/interplane 61 CONF=${XDG_CONFIG_HOME:-$HOME/.config}/interplane 62 BIN=${INTERPLANE_BIN:-$HOME/.local/bin} 63 STORE= 64 QUICK=0 65 while [ $# -gt 0 ]; do 66 case $1 in 67 --store) [ $# -ge 2 ] || die 1 "--store needs a directory"; STORE=$2; shift 2 ;; 68 --quick) QUICK=1; shift ;; 69 -h | --help) usage; exit 0 ;; 70 *) die 1 "unknown option $1 (try --help)" ;; 71 esac 72 done 73 : "${HOME:?set HOME to your home directory}" 74 75 # --- 1. this machine --------------------------------------------------------------------------- 76 step "Checking this machine" 77 os=$(uname -s); arch=$(uname -m) 78 if [ "$os" != Linux ] || { [ "$arch" != aarch64 ] && [ "$arch" != arm64 ]; }; then 79 die 2 "Omega's compiler runs on 64-bit Arm Linux today (for example a Raspberry Pi 4 or 5 with a 80 64-bit system, an NVIDIA DGX Spark, an Arm cloud server, or Linux on an Apple Silicon Mac). 81 This machine is $os on $arch, so nothing was installed. Support for Macs and for Intel and AMD 82 processors is being built." 83 fi 84 missing= 85 for t in bash git ssh-keygen flock sha256sum awk sed cmp getconf realpath od mktemp sync env cut tr head tail wc cp mv rm mkdir chmod cat basename dirname readlink date grep ln ls stat; do 86 command -v "$t" >/dev/null 2>&1 || missing="$missing $t" 87 done 88 [ -z "$missing" ] || die 2 "these programs are missing:$missing 89 On Debian or Ubuntu: sudo apt install bash git openssh-client util-linux coreutils diffutils gawk sed" 90 say "ok: $os $arch, $(git --version)" 91 # git 2.29 is the oldest that has every option used here (init -b, fetch --no-write-fetch-head) 92 gv=$(git --version | sed -n 's/^git version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1 \2/p') 93 [ -n "$gv" ] || die 2 "could not read the version of git ($(git --version)); nothing was installed" 94 if [ "${gv%% *}" -lt 2 ] || { [ "${gv%% *}" -eq 2 ] && [ "${gv##* }" -lt 29 ]; }; then 95 die 2 "git ${gv% *}.${gv#* } is too old: this installer needs git 2.29 or newer, so nothing was installed. 96 On Ubuntu 20.04 or older, get a newer git first, for example: sudo add-apt-repository ppa:git-core/ppa && sudo apt install git" 97 fi 98 99 # --- where things go --------------------------------------------------------------------------- 100 CONFIGURED= 101 if [ -f "$CONF/config" ]; then CONFIGURED=$(sed -n 's/^store=//p' "$CONF/config" | head -n 1); fi 102 if [ -n "$STORE" ]; then 103 case $STORE in /*) ;; *) STORE=$(pwd)/$STORE ;; esac 104 while [ "${STORE%/}" != "$STORE" ] && [ "$STORE" != / ]; do STORE=${STORE%/}; done 105 [ -z "$CONFIGURED" ] || [ "$STORE" = "$CONFIGURED" ] || 106 die 1 "your store is already $CONFIGURED; this install keeps one store, so $STORE was not made and nothing was changed. 107 To use $STORE, run the installer without --store (it keeps using $CONFIGURED)." 108 fi 109 [ -n "$STORE" ] || STORE=$CONFIGURED 110 [ -n "$STORE" ] || STORE=$DATA/store 111 case $STORE in /*) ;; *) STORE=$(pwd)/$STORE ;; esac 112 TOOLS=$DATA/interplane # Interplane source at FORGE_COMMIT, where ipl is built 113 LIB=$DATA/lib # the compilers, and the two source inputs of the store tool 114 RECS=$DATA/records # the evidence and note files the signed records hash 115 CMD=$DATA/install # your store's copy of this installer; `interplane` runs from it 116 KEY=$CONF/owner-key 117 PINS=$CONF/owner-pins 118 # --- 1b. which installer this is, and what is in the folder you named ---------------------------- 119 # This file is a checkout's install.sh when it was run by name (sh install.sh, sh ./install.sh, sh 120 # path/install.sh). A pipe has no file ($0 is then the shell's name), and a file with another name 121 # is treated like a pipe; both take the installer from the source and say so below. 122 ME= 123 MEHEAD= 124 case $0 in 125 install.sh | */install.sh) [ ! -f "$0" ] || ME=$(dirname "$(realpath "$0")") || die 3 "cannot find where $0 is" ;; 126 esac 127 if [ -n "$ME" ] && [ -f "$ME/bin/interplane" ]; then 128 # a folder shaped like a checkout of this repository: it is one (the same physical path, so a 129 # symlinked workspace is fine) or nothing is installed from it, and a checkout that cannot be used 130 # is never replaced by a download 131 top=$(git -C "$ME" rev-parse --show-toplevel 2> /dev/null) || top= 132 [ "$top" = "$ME" ] || die 3 "$ME looks like the folder of this installer but is not a Git checkout of it (a copy, an unpacked archive, a folder Git does not trust, or a subfolder), so what it would install cannot be checked. Nothing was installed. 133 Clone it instead: git clone $SHOWN/interplane-install/repo.git" 134 MEHEAD=$(git -C "$ME" rev-parse -q --verify 'HEAD^{commit}' 2> /dev/null) || die 3 "$ME has no commit checked out. Nothing was installed" 135 myblob=$(git -C "$ME" hash-object -- "$ME/install.sh" 2> /dev/null) || myblob= 136 cblob=$(git -C "$ME" rev-parse -q --verify "$MEHEAD:install.sh" 2> /dev/null) || cblob= 137 [ -n "$myblob" ] && [ "$myblob" = "$cblob" ] || 138 die 3 "install.sh in $ME is not the one in the commit that is checked out ($(printf %.12s "$MEHEAD")): it has changes that are not committed, and this file decides which compilers and tools are installed. Nothing was installed. 139 Commit the change, or put the file back: git -C $ME checkout -- install.sh" 140 sg=$STORE/projects/interplane-install/repo.git 141 have=$(git --git-dir="$sg" rev-parse -q --verify refs/heads/main 2> /dev/null) || have= 142 if [ -n "$have" ] && [ "$have" != "$MEHEAD" ] && git --git-dir="$sg" merge-base --is-ancestor "$MEHEAD" "$have" 2> /dev/null; then 143 die 3 "your store already has a newer installer ($(printf %.12s "$have")); this one ($(printf %.12s "$MEHEAD")) is older, and its compilers and tools would replace newer ones. Nothing was changed. 144 Run the newer one: sh $CMD/install.sh" 145 fi 146 fi 147 if [ -d "$STORE" ] && [ -n "$(ls -A "$STORE" 2> /dev/null)" ] && [ ! -d "$STORE/projects" ] && [ ! -f "$STORE/catalog.tsv" ]; then 148 die 1 "$STORE already has files in it and is not an Interplane store. Nothing was changed (the installer would make it private and add folders to it). Name a new or empty folder with --store" 149 fi 150 if [ -d "$STORE" ]; then 151 m=$(stat -c %a "$STORE") 152 # the last two digits are the group's and everyone else's rights 153 case $m in *00) ;; *) say "note: $STORE already exists and was accessible to other accounts (mode $m); it is now readable only by you" ;; esac 154 fi 155 mkdir -p "$DATA" "$LIB" "$RECS" "$STORE/projects" "$CONF" 156 (umask 022 && mkdir -p "$BIN") 157 chmod 700 "$CONF" "$DATA" "$STORE" 158 exec 9>> "$DATA/.install.lock" 159 flock -n 9 || die 3 "another install is running for this user; wait for it to finish" 160 # what a killed earlier run left behind 161 rm -rf "$DATA"/.stage.* "$TOOLS.new" "$CMD.new" "$BIN/.omc.new" "$LIB"/*.new "$RECS"/*.new "$CONF/config.new" "$KEY.pub.new" "$PINS.new" "$DATA/omc-installed.new" 162 for n in omega-mv interplane-forge interplane-install; do rm -rf "$STORE/projects/$n/repo.git.new"; done 163 STAGE=$(mktemp -d "$DATA/.stage.XXXXXXXX") || die 3 "cannot make a staging folder in $DATA" 164 trap 'rm -rf "$STAGE"' 0 165 trap 'exit 3' 1 2 15 166 167 sha() { sha256sum < "$1" | cut -d' ' -f1; } 168 # put FILE: what comes in on stdin becomes FILE whole or not at all (a kill cannot leave half of it) 169 put() { cat > "$1.new" && mv -f "$1.new" "$1"; } 170 # srcgit COMMAND...: a git command that talks to the source; if it fails, what git said is shown 171 # with any password or token taken out of the address 172 srcgit() { 173 "$@" > /dev/null 2> "$STAGE/git.err" && return 0 174 sed 's#\([a-z+]*://\)[^/ ]*@#\1#g' "$STAGE/git.err" >&2 175 return 1 176 } 177 178 # fetch NAME: main of NAME in the staging folder: your store's copy (if any) moved forward to the 179 # source's main when that descends from it, or a fresh download from the source 180 fetch() { 181 if [ -d "$STORE/projects/$1/repo.git" ]; then 182 git clone -q --bare --single-branch --branch main "$STORE/projects/$1/repo.git" "$STAGE/$1.git" >&2 || 183 die 3 "could not read $1 in your store" 184 say "updating $1 from $SHOWN ..." >&2 185 if srcgit git --git-dir="$STAGE/$1.git" fetch -q --no-tags --no-write-fetch-head "$SRC/$1/repo.git" "+refs/heads/main:refs/heads/source"; then 186 mine=$(git --git-dir="$STAGE/$1.git" rev-parse refs/heads/main) 187 theirs=$(git --git-dir="$STAGE/$1.git" rev-parse refs/heads/source) 188 if git --git-dir="$STAGE/$1.git" merge-base --is-ancestor "$mine" "$theirs"; then 189 git --git-dir="$STAGE/$1.git" update-ref refs/heads/main "$theirs" "$mine" 190 elif ! git --git-dir="$STAGE/$1.git" merge-base --is-ancestor "$theirs" "$mine"; then 191 say "note: main of $1 at the source does not descend from your copy; using your copy" >&2 192 fi 193 else 194 say "note: could not reach $SHOWN/$1/repo.git (why is above); using your store's copy" >&2 195 fi 196 else 197 say "downloading $1 from $SHOWN (git) ..." >&2 198 git init -q --bare "$STAGE/$1.git" && git --git-dir="$STAGE/$1.git" symbolic-ref HEAD refs/heads/main && 199 srcgit git --git-dir="$STAGE/$1.git" fetch -q --no-tags --no-write-fetch-head "$SRC/$1/repo.git" "+refs/heads/main:refs/heads/main" || 200 die 3 "could not download $SHOWN/$1/repo.git" 201 fi 202 echo "$STAGE/$1.git" 203 } 204 # need NAME GITDIR COMMIT: the commit must be on that repository's main 205 need() { 206 [ "$(git --git-dir="$2" cat-file -t "$3" 2>/dev/null)" = commit ] && 207 git --git-dir="$2" merge-base --is-ancestor "$3" refs/heads/main || 208 die 3 "$1 (from $SHOWN or your store) does not have the pinned commit $3 on main; nothing was installed" 209 } 210 211 # --- 2. source --------------------------------------------------------------------------------- 212 step "Getting the source (Omega and Interplane)" 213 OMEGA_GIT=$(fetch omega-mv) 214 FORGE_GIT=$(fetch interplane-forge) 215 need omega-mv "$OMEGA_GIT" "$OMEGA_RELEASE" 216 need interplane-forge "$FORGE_GIT" "$FORGE_COMMIT" 217 # the installer being installed: a checkout (MEHEAD, found and checked above) or the source's copy 218 if [ -n "$MEHEAD" ]; then 219 # the clone form installs exactly the commit that is checked out, whatever branch it is on 220 INSTALL_GIT=$STAGE/interplane-install.git 221 git clone -q --bare --no-tags "$ME" "$INSTALL_GIT" || die 3 "could not read $ME" 222 git --git-dir="$INSTALL_GIT" fetch -q --no-tags --no-write-fetch-head "$ME" HEAD > /dev/null 2>&1 || true 223 git --git-dir="$INSTALL_GIT" cat-file -e "$MEHEAD^{commit}" 2>/dev/null || die 3 "could not read commit $MEHEAD of $ME" 224 git --git-dir="$INSTALL_GIT" update-ref refs/heads/main "$MEHEAD" && git --git-dir="$INSTALL_GIT" symbolic-ref HEAD refs/heads/main || 225 die 3 "could not read $ME" 226 say "ok: this installer is $ME at $(printf %.12s "$MEHEAD")" 227 [ -z "$(git -C "$ME" status --porcelain --untracked-files=no 2>/dev/null)" ] || 228 say "note: $ME has uncommitted changes to tracked files; they are not installed (only the commit above is)" 229 else 230 say "note: this installer is not run from a checkout (a pipe, or a file with no checkout beside it), so the installer and the interplane command come from $SHOWN, not from the folder you are in" 231 INSTALL_GIT=$(fetch interplane-install) 232 fi 233 # What was built and what is recorded must be one installer: the pins of the file that is running 234 # are the pins in the install.sh of the installer commit that goes into your store. 235 THIS=$(git --git-dir="$INSTALL_GIT" rev-parse refs/heads/main) 236 git --git-dir="$INSTALL_GIT" cat-file -e refs/heads/main:install.sh 2> /dev/null || die 3 "no install.sh in the installer commit $THIS" 237 STOREPINS=$(git --git-dir="$INSTALL_GIT" show refs/heads/main:install.sh | sed -n -e 's/^OMEGA_RELEASE=//p' -e 's/^OMEGA_RELEASE_OMC_SHA256=//p' -e 's/^FORGE_COMMIT=//p') 238 [ "$STOREPINS" = "$(printf '%s\n' "$OMEGA_RELEASE" "$OMEGA_RELEASE_OMC_SHA256" "$FORGE_COMMIT")" ] || 239 die 3 "the installer you ran is not the one it would put in your store (commit $(printf %.12s "$THIS") has other pins). Nothing was installed. Run the install.sh of that installer from a clone, or run the same one that is on $SHOWN" 240 241 # --- 3. compilers ------------------------------------------------------------------------------ 242 step "Checking the Omega compilers" 243 git --git-dir="$OMEGA_GIT" show "$OMEGA_RELEASE:seed/out/omc" > "$STAGE/omc" || die 3 "no compiler at $OMEGA_RELEASE" 244 [ "$(sha "$STAGE/omc")" = "$OMEGA_RELEASE_OMC_SHA256" ] || die 3 "the Omega compiler's SHA-256 is not the pinned one; nothing was installed" 245 chmod 755 "$STAGE/omc" 246 say "ok: omc from Omega $OMEGA_RELEASE, sha256 $OMEGA_RELEASE_OMC_SHA256" 247 248 pin() { git --git-dir="$FORGE_GIT" show "$FORGE_COMMIT:ipl/PIN" | sed -n "s/^$1 //p"; } 249 IPL_OMEGA=$(pin omega-mv); IPL_OMC_SHA=$(pin omc-sha256); IPL_FORGE=$(pin forge) 250 [ -n "$IPL_OMEGA" ] && [ -n "$IPL_OMC_SHA" ] && [ -n "$IPL_FORGE" ] || die 3 "ipl/PIN at $FORGE_COMMIT is not readable" 251 need omega-mv "$OMEGA_GIT" "$IPL_OMEGA" 252 need interplane-forge "$FORGE_GIT" "$IPL_FORGE" 253 git --git-dir="$OMEGA_GIT" show "$IPL_OMEGA:seed/out/omc" > "$STAGE/omc-ipl" || die 3 "no compiler at $IPL_OMEGA" 254 [ "$(sha "$STAGE/omc-ipl")" = "$IPL_OMC_SHA" ] || die 3 "the store tool's compiler is not the one ipl/PIN names; nothing was installed" 255 chmod 700 "$STAGE/omc-ipl" 256 git --git-dir="$OMEGA_GIT" show "$IPL_OMEGA:om/tls/sha2.om" > "$STAGE/sha2.om" || die 3 "no om/tls/sha2.om at $IPL_OMEGA" 257 git --git-dir="$FORGE_GIT" show "$IPL_FORGE:chain/chain.om" > "$STAGE/chain.om" || die 3 "no chain/chain.om at $IPL_FORGE" 258 # OMCREC lists the sha256 of every omc this installer has put in $BIN (one per line). The omc of the 259 # previous release in $LIB is added before it is replaced below, so an install made by an older 260 # installer, or by a run that was killed after this step, is still known as this installer's own. 261 OMCREC=$DATA/omc-installed 262 add_seen() { grep -qxF "$1" "$OMCREC" 2> /dev/null || { cat "$OMCREC" 2> /dev/null; echo "$1"; } | put "$OMCREC"; } 263 if [ -f "$LIB/omc" ]; then add_seen "$(sha "$LIB/omc")"; fi 264 for f in omc omc-ipl sha2.om chain.om; do cp -p "$STAGE/$f" "$LIB/$f.new" && mv -f "$LIB/$f.new" "$LIB/$f"; done 265 say "ok: store tool compiler from Omega $IPL_OMEGA, sha256 $IPL_OMC_SHA" 266 267 # --- 4. the store tool ------------------------------------------------------------------------- 268 # swap X: the finished tree "$X.new" takes the place of "$X"; what was there is kept as "$X.prev". 269 # $TOOLS and $CMD are derived (built again from the store's source each run), so each is built whole 270 # in "$X.new" first; a kill at any point leaves either the old tree or the new one, and the next run 271 # builds again. 272 swap() { 273 rm -rf "$1.prev" 274 if [ -e "$1" ]; then 275 mv "$1" "$1.prev" 276 if [ -n "$(git -C "$1.prev" status --porcelain --untracked-files=no 2>/dev/null)" ] || ! git -C "$1.prev" rev-parse -q --verify HEAD > /dev/null 2>&1; then 277 say "note: the previous $1 was not as it should be; it is kept as $1.prev" 278 fi 279 fi 280 mv "$1.new" "$1" 281 } 282 step "Building Interplane's store tool with Omega" 283 git clone -q --no-checkout "$FORGE_GIT" "$TOOLS.new" || die 3 "could not make $TOOLS.new" 284 git -C "$TOOLS.new" -c advice.detachedHead=false checkout -q --detach "$FORGE_COMMIT" || die 3 "could not check out $FORGE_COMMIT in $TOOLS.new" 285 sh "$TOOLS.new/ipl/build.sh" "$LIB/omc-ipl" "$LIB/sha2.om" "$LIB/chain.om" >/dev/null || die 3 "the store tool did not build" 286 say "ok: built $(cd "$TOOLS.new/ipl/bin" && sha256sum landrec chain | awk '{printf "%s %s ", $2, substr($1,1,12)}')" 287 if [ "$QUICK" = 0 ]; then 288 say "running the store tool's own test gate (81 seconds on a DGX Spark) ..." 289 if bash "$TOOLS.new/ipl/tests/run.sh" "$LIB/omc-ipl" "$LIB/sha2.om" "$LIB/chain.om" > "$DATA/gate.log" 2>&1 && tail -n 1 "$DATA/gate.log" | grep -q '^GATE PASS'; then 290 say "ok: $(tail -n 1 "$DATA/gate.log") (log: $DATA/gate.log)" 291 else 292 die 3 "the store tool's test gate failed on this machine; nothing was put in your store. Log: $DATA/gate.log" 293 fi 294 else 295 say "skipped the test gate (--quick)" 296 fi 297 swap "$TOOLS" 298 IPL=$TOOLS/ipl/ipl 299 300 # --- 5. your key ------------------------------------------------------------------------------- 301 step "Your owner key" 302 if [ -f "$KEY" ]; then 303 chmod 600 "$KEY" 304 if [ ! -s "$KEY.pub" ]; then 305 ssh-keygen -y -f "$KEY" > "$KEY.pub.new" && [ -s "$KEY.pub.new" ] || { rm -f "$KEY.pub.new"; die 3 "$KEY is not a key ssh-keygen can read"; } 306 mv -f "$KEY.pub.new" "$KEY.pub" 307 fi 308 say "ok: using your existing key $KEY" 309 else 310 ssh-keygen -q -t `ed25519` -N '' -C "interplane owner" -f "$KEY" || die 3 "could not make a key" 311 say "made a new Ed25519 key at $KEY (no passphrase, readable only by you). Keep a copy of it somewhere safe:" 312 say "whoever holds it can sign for your projects, and without it you cannot add to them." 313 fi 314 chmod 600 "$KEY" 315 FP=$(ssh-keygen -lf "$KEY.pub" | awk '{print $2}') 316 case $FP in SHA256:*) ;; *) die 3 "$KEY.pub is not a key ssh-keygen can read" ;; esac 317 if [ -f "$PINS" ]; then 318 if grep -q '^\* ' "$PINS"; then 319 grep -qx "\* $FP" "$PINS" || die 3 "$PINS already names another owner key for every project; not changing it" 320 else 321 { cat "$PINS" && printf '* %s\n' "$FP"; } | put "$PINS" 322 fi 323 else 324 printf '# The owner key of every project in your store. Write it only from your own key.\n* %s\n' "$FP" | put "$PINS" 325 fi 326 chmod 600 "$PINS" 327 say "ok: owner $FP" 328 329 # --- 6. your store ----------------------------------------------------------------------------- 330 step "Putting Omega and Interplane in your store at $STORE" 331 # adopt NAME GITDIR: first time, a private project with a signed first record and an IMPORT of 332 # main; later, main brought forward as a signed landing when the new main descends from yours 333 adopt() { 334 name=$1 from=$2 p=$STORE/projects/$1 335 new=$(git --git-dir="$from" rev-parse refs/heads/main) || die 3 "$name has no main" 336 if [ -f "$p/chain.tsv" ] && ok=$(bash "$IPL" verify "$STORE" "$name" 2>/dev/null); then 337 rec=$(printf '%s\n' "$ok" | awk '{print $5}') 338 if [ "$rec" = "$new" ]; then say "ok: $name is up to date at $(printf %.12s "$new")"; return 0; fi 339 if [ "$rec" != none ] && ! git --git-dir="$from" merge-base --is-ancestor "$rec" "$new" 2>/dev/null; then 340 say "kept your $name at $(printf %.12s "$rec"): the new main does not descend from it"; return 0 341 fi 342 rf=$RECS/$name.update-$new.receipt vf=$RECS/$name.update-$new.verdict 343 [ -f "$rf" ] || printf 'interplane-install update\nsource %s/%s/repo.git\nbranch main\nold %s\nnew %s\nutc %s\n' \ 344 "$SHOWN" "$name" "$rec" "$new" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" | put "$rf" 345 [ -f "$vf" ] || printf 'no review here: taken as it was downloaded by interplane-install\n' | put "$vf" 346 bash "$IPL" land "$STORE" "$name" main "$new" "$from" "$rf" "$vf" "install-$name-$(printf %.12s "$new")" "$KEY" >/dev/null || 347 die 3 "could not record the new head of $name" 348 say "ok: $name brought up to $(printf %.12s "$new")"; return 0 349 fi 350 if [ ! -d "$p/repo.git" ]; then 351 mkdir -p "$p" 352 git clone -q --bare --single-branch --branch main "$from" "$p/repo.git.new" && mv "$p/repo.git.new" "$p/repo.git" || 353 die 3 "could not put $name in the store" 354 git --git-dir="$p/repo.git" remote remove origin 2>/dev/null || true 355 fi 356 head=$(git --git-dir="$p/repo.git" rev-parse refs/heads/main) || die 3 "$name in your store has no main" 357 ev=$RECS/$name.import-evidence 358 nt=$RECS/$name.import-note 359 [ -f "$ev" ] || printf 'interplane-install import\nsource %s/%s/repo.git\nbranch main\nhead %s\nutc %s\n' \ 360 "$SHOWN" "$name" "$head" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" | put "$ev" 361 [ -f "$nt" ] || printf 'Installed by interplane-install. Taken over as it was downloaded: not gated or reviewed here.\n' | put "$nt" 362 # both steps finish an earlier run that stopped part-way, and refuse anything else 363 bash "$IPL" init "$STORE" "$name" main private - "$KEY" >/dev/null || die 3 "could not record $name in your store" 364 bash "$IPL" verify "$STORE" "$name" 2>/dev/null | awk '{exit $5 != "none"}' || { say "ok: $name verifies"; adopt "$name" "$from"; return 0; } 365 bash "$IPL" import "$STORE" "$name" main "$ev" "$nt" "install-$name" "$KEY" >/dev/null || die 3 "could not record the head of $name" 366 say "ok: $name (private) at $(printf %.12s "$head")" 367 [ "$head" = "$new" ] || adopt "$name" "$from" 368 } 369 adopt omega-mv "$OMEGA_GIT" 370 adopt interplane-forge "$FORGE_GIT" 371 adopt interplane-install "$INSTALL_GIT" 372 git -C "$TOOLS" remote set-url origin "$STORE/projects/interplane-forge/repo.git" 2>/dev/null || 373 git -C "$TOOLS" remote add origin "$STORE/projects/interplane-forge/repo.git" 374 375 # --- 7. commands ------------------------------------------------------------------------------- 376 step "Installing omc and interplane in $BIN" 377 # OMC_OURS says whether the omc in $BIN is the compiler of this release (the final line tells it) 378 OMC_OURS=0 379 OMCCUR= 380 if [ -f "$BIN/omc" ] && [ ! -L "$BIN/omc" ]; then OMCCUR=$(sha "$BIN/omc"); fi 381 if [ -e "$BIN/omc" ] || [ -L "$BIN/omc" ]; then 382 if [ -f "$BIN/omc" ] && [ "$(sha "$BIN/omc")" = "$OMEGA_RELEASE_OMC_SHA256" ]; then 383 say "ok: $BIN/omc is already this compiler"; OMC_OURS=1 384 add_seen "$OMEGA_RELEASE_OMC_SHA256" 385 elif [ -n "$OMCCUR" ] && grep -qxF "$OMCCUR" "$OMCREC" 2> /dev/null; then 386 # a file this installer put there on an earlier run (by its sha256): the new release replaces it 387 cp "$STAGE/omc" "$BIN/.omc.new" && chmod 755 "$BIN/.omc.new" && mv "$BIN/.omc.new" "$BIN/omc" 388 add_seen "$OMEGA_RELEASE_OMC_SHA256" 389 say "updated $BIN/omc to the compiler of Omega $OMEGA_RELEASE (it was the one an earlier run of this installer put there)"; OMC_OURS=1 390 else 391 say "kept your existing $BIN/omc (it is a different file, not one this installer put there). This release's compiler is at $LIB/omc" 392 fi 393 else 394 cp "$STAGE/omc" "$BIN/.omc.new" && chmod 755 "$BIN/.omc.new" && mv "$BIN/.omc.new" "$BIN/omc" 395 add_seen "$OMEGA_RELEASE_OMC_SHA256" 396 say "installed $BIN/omc"; OMC_OURS=1 397 fi 398 # the interplane command runs from your store's copy of this installer, checked out whole each run 399 git clone -q "$STORE/projects/interplane-install/repo.git" "$CMD.new" || die 3 "could not check out the interplane command" 400 swap "$CMD" 401 printf 'store=%s\ntools=%s\nkey=%s\n' "$STORE" "$TOOLS" "$KEY" | put "$CONF/config" 402 if [ -L "$BIN/interplane" ] && [ "$(readlink "$BIN/interplane")" = "$CMD/bin/interplane" ]; then 403 say "ok: $BIN/interplane" 404 elif [ -e "$BIN/interplane" ] || [ -L "$BIN/interplane" ]; then 405 say "kept your existing $BIN/interplane (it is something else). This command is $CMD/bin/interplane" 406 else 407 ln -s "$CMD/bin/interplane" "$BIN/interplane" 408 say "installed $BIN/interplane" 409 fi 410 411 # --- done -------------------------------------------------------------------------------------- 412 bash "$CMD/bin/interplane" verify >/dev/null || die 3 "installed, but your store does not verify; run: interplane verify" 413 step "Done" 414 say "Your store: $STORE" 415 say "Your key: $KEY ($FP)" 416 if [ "$OMC_OURS" = 1 ]; then say "Omega: $BIN/omc (source: interplane get omega-mv)" 417 else say "Omega: your own $BIN/omc is kept; this release's compiler is $LIB/omc (source: interplane get omega-mv)"; fi 418 SHEAD=$(git --git-dir="$STORE/projects/interplane-install/repo.git" rev-parse refs/heads/main) 419 say "Installer: interplane-install $(printf %.12s "$SHEAD")" 420 [ "$SHEAD" = "$THIS" ] || say " (this run's compilers and store tool are the pins of installer $(printf %.12s "$THIS"), which your store does not have as its installer)" 421 case :$PATH: in *:"$BIN":*) ;; *) say ""; say "Add $BIN to your PATH, for example: echo 'export PATH=\"$BIN:\$PATH\"' >> ~/.profile" ;; esac 422 say "" 423 say "Next: interplane list what is in your store" 424 say " interplane import URL bring in a Git repository you choose" 425 say " interplane help everything else"