carbon-config

config submodule of carbon-core-system
git clone https://ccx.te2000.cz/git/carbon-config
Log | Files | Refs

commit bd12986867bbf55fd837db0f66dd540bcb5a7b9d
parent b953d48263bfdec94973be98e50ec53826f8e50a
Author: ccx <ccx@te2000.cz>
Date:   Sun, 17 Jul 2022 15:21:34 +0200

install and postinstall script

Diffstat:
Ainstall | 42++++++++++++++++++++++++++++++++++++++++++
Apostinstall | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 116 insertions(+), 0 deletions(-)

diff --git a/install b/install @@ -0,0 +1,42 @@ +#!/bin/zsh +setopt no_unset warn_create_global extended_glob +zmodload -F zsh/stat b:zstat || exit $? +zmodload -m -F zsh/files b:zf_\* || exit $? +#zmodload zsh/zutil || exit $? # for zparseopts +#zmodload zsh/datetime || exit $? # for $EPOCHREALTIME + +die_ret() { + local ret + ret=$1 + shift + printf >&2 '%s\n' "$@" + exit $ret +} +die() { + die_ret 1 "$@" +} +die100() { # 100: wrong usage + die_ret 100 "$@" +} +die111() { # 111: system call failed + die_ret 111 "$@" +} + +install_to_all() { + mkdir s6-rc-source || exit $? + ./command/fsapply ./s6-rc-source ./conf/s6-rc.fileset || exit $? + [[ -f ./s6-rc-source/ok-all/type ]] || die111 \ + "Failed to generate s6-rc source directory" + ./command/s6-rc-compile ./s6-rc-db ./s6-rc-source || exit $? + ./init-maker/install $PWD || exit $? +} +typeset -f -t install_to_all + +typeset -g ALL_DIR=$0:h +if [[ $ALL_DIR == /versions/all.* ]]; then + path=( $ALL_DIR/command "$path[@]" ) + #fpath=( $ALL_DIR/zsh-functions "$fpath[@]" ) + install_to_all || exit $? +else + die100 "Fatal: ${(qqq)0}: This script needs to be run from versioned directory as a part of installation procedure." +fi diff --git a/postinstall b/postinstall @@ -0,0 +1,74 @@ +#!/bin/zsh +setopt no_unset warn_create_global extended_glob +zmodload -F zsh/stat b:zstat || exit $? +zmodload -m -F zsh/files b:zf_\* || exit $? +#zmodload zsh/zutil || exit $? # for zparseopts +zmodload zsh/datetime || exit $? # for $EPOCHREALTIME + +ensure_symlink() { + local target + if ! [[ -e $1 ]]; then + s6-ln -s $2 $1 || return $? + fi + + if [[ $2 == /* ]]; then + target=$2:A + else + target=$1:h/$2 + target=$target:A + fi + + if ! [[ -h $1 ]]; then + echo >&2 "Error: not a symlink: ${(qqq)1}" + return 1 + elif [[ $1:A != $target ]]; then + echo >&2 "Error: ${(qqq)1} points to ${(qqq)1:A} instead of ${(qqq)target}" + return 1 + fi +} + +link_changed() { + local pre post + pre=preinstall_link_$1 + post=postinstall_link_$1 + [[ "${(P)preinstall_links:-}" != "${(P)postinstall_links:-}" ]] +} + +postinstall() { + ensure_symlink /command current/command || return $? + + if [[ -d /run/s6-rc/ ]]; then + if link_changed package; then + if link_changed s6-rc-source; then + # Both s6-rc DB source and installed software changed. + # s6-rc-format-upgrade to tmpdir, then s6-rc-update + local tmp_db=/run/old-s6-rc-db-migration.$EPOCHREALTIME + + s6-rc-compile $tmp_db $preinstall_current/s6-rc-source || return $? + s6-rc-format-upgrade -v2 $tmp_db || return $? + s6-rc-update -v2 /current/s6-rc-db/ || return $? + rm -r $tmp_db || return $? + else + # Installed software changed but s6-rc DB source is the same. + # s6-rc-format-upgrade to new compiled DB directly + s6-rc-format-upgrade -v2 /current/s6-rc-db/ || return $? + fi + elif link_changed s6-rc-source; then + # s6-rc DB source changed while keeping same version of software. + # s6-rc-update to new compiled DB directly + s6-rc-update -v2 /current/s6-rc-db/ || return $? + fi + + fi + exit 0 +} +typeset -ft postinstall + +typeset -g ALL_DIR=$0:h +if [[ $ALL_DIR == /versions/all.* ]]; then + path=( $ALL_DIR/command "$path[@]" ) + #fpath=( $ALL_DIR/zsh-functions "$fpath[@]" ) + postinstall || exit $? +else + die100 "Fatal: ${(qqq)0}: This script needs to be run from versioned directory as a part of installation procedure." +fi