#!/bin/sh # # ciao-boot.sh # # Boot the Ciao builder (with or without sources) # # Copyright (C) 2015-2022 Ciao Developer Team # set -u if [ "$0" != "sh" ]; then # Boot from sources # Physical directory where the script is located _base=$(e=$0;while test -L "$e";do d=$(dirname "$e");e=$(readlink "$e");\ cd "$d";done;cd "$(dirname "$e")";pwd -P) # Builder boot _boot="$_base"/builder/sh_boot/builder_boot.sh if [ -x "$_boot" ]; then exec "$_boot" "$@"; fi fi # Otherwise continue with network-based installer... (below) # --------------------------------------------------------------------------- # The network-based installer automatically downloads and installs a # Ciao release selected by the user. It extends builder installation # 'target' with the notion of 'release' and 'tag', and allows using # precompiled parts when available (binaries, documentation, etc.). # # It can run in a fully automatic mode (when the target and parameters # are fully specified) or (partially) interactivelly (when the target # is not specified). # --------------------------------------------------------------------------- # --------------------------------------------------------------------------- # Release info # input: release os arch target # output: # - `tag` that identifies this source version or binary release # - `a__*`: `v__*` is allowed release_query_info() { case "$v__release" in stable) tag=v1.23.0-m1 ;; beta) tag=v1.23.0-m1 ;; latest) tag=master ;; esac # Set other defaults based on release if [ "$v__devenv" = "yes" ]; then a__prebuilt_bin=no # TODO: no prebuilt bin for devenv yet case "$tag" in master) a__prebuilt_docs=no; a__with_docs=yes ;; *) a__prebuilt_docs=yes; a__with_docs=no ;; esac else case "$os$arch" in DARWINaarch64) a__prebuilt_bin=no ;; # TODO: not yet *) a__prebuilt_bin=yes ;; esac a__prebuilt_docs=no; a__with_docs=no fi } # Select URL for fetching sources and releases select_url() { # requires: cfg, tag _url_archive="https://github.com/ciao-lang/ciao/archive" _url_releases="https://github.com/ciao-lang/ciao/releases/download" case "$tag" in # extract version from tag (when needed) master) _vers=$tag ;; v*) _vers=${tag%%-*}; _vers=${_vers#?} ;; esac if [ "$tag" = "master" ]; then # no release for head url="$_url_archive/refs/heads/$tag.tar.gz" unset urldocs # (error if used) else if [ "$cfg" = "source" ]; then url="$_url_archive/refs/tags/$tag.tar.gz" else url="$_url_releases/$tag/ciao-$_vers-$cfg.tar.gz" fi urldocs="$_url_releases/$tag/ciao-$_vers-docs.tar.gz" fi } # --------------------------------------------------------------------------- # IO helper functions errmsg() { printf "%s\n" "$*" 1>&2 } errcat() { cat 1>&2 } normal_message() { errmsg " $*" } check_tty() { if ! [ -t 1 ] ; then errcat <&2 # print question, wait answer read answer < /dev/tty if _valid_answer "$@"; then break else errmsg "Invalid answer. Please try again." fi done } _valid_answer() { # valid answers (first is default) if [ "$answer" = "" ]; then answer="$1" return 0 # OK (use default) fi for _v in "$@"; do if [ "$answer" = "$_v" ]; then return 0 # OK fi done return 1 # Wrong } # --------------------------------------------------------------------------- # Get normalized $os and $arch get_os_arch() { # (simpler version of ciao_sysconf) os=`uname -s` arch=`uname -m` case "$os" in Linux) os=LINUX ;; CYGWIN_*|MSYS_NT*|MINGW32_NT*|MINGW64_NT*) os=Win32 ;; Darwin) os=DARWIN ;; esac case "$arch" in i[3456]86|i86pc) arch=i686 ;; x86_64|amd64) arch=x86_64 ;; arm64) arch=aarch64 ;; esac } # --------------------------------------------------------------------------- # (source or binary) fetch_url() { normal_message "fetching core from $url" curl -sSfL "$url" | tar -xz --strip-components 1 -C "$ciaoroot" -f - } # (docs) fetch_urldocs() { normal_message "fetching docs from $urldocs" mkdir -p "$ciaoroot"/build curl -sSfL "$urldocs" | tar -xz -C "$ciaoroot"/build -f - # Link to site dir docs (for ciao-serve) # TODO: move mkdir -p "$ciaoroot"/build/site/ciao/build ln -s ../../../doc "$ciaoroot"/build/site/ciao/build/doc } # --------------------------------------------------------------------------- fetch_and_boot() { # [BOOTOPTS] # Prepare for download # TODO: split tar.gz into source, bin-$os$arch, etc. so that there is # no overlapping and we can do multi-architecture installs if [ -x "$ciaoroot" ]; then _ciaoroot_bak="$ciaoroot"-`date +%Y%m%d%H%M%S` normal_message "backing up previous installation (as `basename $_ciaoroot_bak`)" # TODO: remove ONLY if the directory is empty or this is a Ciao installation (e.g., ciao-boot.sh exists) mv "$ciaoroot" "$_ciaoroot_bak" fi mkdir -p "$ciaoroot" # Download select_url fetch_url if ! [ -x "$ciaoroot"/builder/sh_boot/builder_boot.sh ]; then errcat < /dev/null 2>&1 } missing() { errcat <