#!/bin/sh # shellcheck shell=dash # # This script installs Julia using the official juliaup installer and # initialises the KM3NeT Julia registry. set -u check_prerequisites() { MACOS_INSTALL_NOTE="If you are using macOS, make sure you have homebrew installed (https://brew.sh), that should be enough." LINUX_INSTALL_NOTE="Please install it using\n\n sudo apt install ... # Debian/Ubuntu...\n sudo yum install ... # RedHat/CentOS...\n sudo dnf install ... # Alma/Rocky..." if ! command -v curl 2>&1 >/dev/null then echo "'curl' could not be found. $LINUX_INSTALL_NOTE\n\n$MACOS_INSTALL_NOTE" exit 1 fi if ! command -v ps 2>&1 >/dev/null then echo "'procps' (ps) could not be found. $LINUX_INSTALL_NOTE\n\n$MACOS_INSTALL_NOTE" exit 1 fi if ! command -v git 2>&1 >/dev/null then echo "'git' could not be found. $LINUX_INSTALL_NOTE\n\n$MACOS_INSTALL_NOTE" exit 1 fi } err() { echo "$1" >&2 exit 1 } ensure() { if ! "$@"; then err "command failed: $*"; fi } initialise_julia_registry() { echo "#####################################################" echo "Initialising the general Julia registry" echo "#####################################################" ensure julia -e 'using Pkg; Pkg.Registry.add()' } initialise_km3net_julia_registry() { echo "#####################################################" echo "Initialising the KM3NeT Julia registry" echo "#####################################################" km3net_registry_dir="${HOME}/.julia/registries/KM3NeT" if [ ! -d "$km3net_registry_dir" ]; then ensure git clone https://git.km3net.de/common/julia-registry.git ~/.julia/registries/KM3NeT ensure julia -e 'using Pkg; Pkg.Registry.update()' fi } main() { check_prerequisites export JULIA_PKG_USE_CLI_GIT=true # fix for Windows users ensure curl -fsSL https://install.julialang.org | sh -s -- --yes export PATH=${HOME}/.juliaup/bin${PATH:+:${PATH}} juliaup add 1.11 juliaup default 1.11 echo echo "Configuring your Julia installation for KM3NeT, stay tuned!" echo juliastartup="${HOME}/.julia/config/startup.jl" ijuliastartup="${HOME}/.julia/config/startup_ijulia.jl" initialise_julia_registry ensure_julia_config_folder_exists ensure_package_is_installed BenchmarkTools ensure_package_is_installed IJulia build_package IJulia ensure_package_is_installed Pluto ensure_package_is_installed Revise ensure_package_is_in_config Revise "${juliastartup}" ensure_package_is_in_config Revise "${ijuliastartup}" ensure_package_is_installed OhMyREPL ensure_package_is_in_config OhMyREPL "${juliastartup}" # ensure_package_is_installed Makie initialise_km3net_julia_registry # ensure_package_is_installed KM3io # ensure_package_is_installed KM3NeTTestData echo "#####################################################" echo echo "All setup, you are ready to enjoy KM3NeT with Julia!" echo "Start a new terminal/shell or log out and in again to" echo "reload your environment." echo echo "If you are using Windows and encounter any Git-related" echo "problems when installing packages or instantiating" echo "environments, try setting the following environment" echo "variable in your ~/.bashrc" echo echo export JULIA_PKG_USE_CLI_GIT=true echo echo "#####################################################" } ensure_julia_config_folder_exists() { ensure mkdir -p "${HOME}/.julia/config" } add_package_to_config() { cat << EOF >> "$2" # >>> KM3NeT Julia installer >>> try using $1 catch e @warn "Error initializing $1" exception=(e, catch_backtrace()) end # <<< KM3NeT Julia installer <<< EOF } ensure_package_is_in_config() { touch $2 is_in_file=$(grep -c "using $1" $2) if [ $is_in_file -eq 0 ] then echo "Adding $1 to $2" add_package_to_config $1 $2 else echo " -> $1 already configured in $2" fi } ensure_package_is_installed() { echo "#####################################################" echo "Installing $1..." ensure julia -e "using Pkg; Pkg.add(\"$1\")" } build_package() { echo " -> Building $1..." ensure julia -e "using Pkg; Pkg.build(\"$1\")" } main || exit 1