From 9f9db22fa0bcaef3170d46b39be09002efaa6bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sat, 11 Jan 2025 16:41:26 +0100 Subject: [PATCH 1/6] refactor: init envs inside container --- .devcontainer/devcontainer.json | 1 - .github/.devcontainer/Dockerfile | 2 +- .github/.devcontainer/devcontainer.json | 1 + .../init-env/devcontainer-feature.json | 32 +++++ .github/.devcontainer/init-env/install.sh | 126 ++++++++++++++++++ init.sh | 83 ------------ 6 files changed, 160 insertions(+), 85 deletions(-) create mode 100644 .github/.devcontainer/init-env/devcontainer-feature.json create mode 100755 .github/.devcontainer/init-env/install.sh delete mode 100755 init.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f44b48b..09015d1 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -9,7 +9,6 @@ // "installChromium": "false" // } }, - "postStartCommand": ["bash", "init.sh"], "customizations": { "vscode": { "extensions": [ diff --git a/.github/.devcontainer/Dockerfile b/.github/.devcontainer/Dockerfile index 197ca53..e5eae6b 100644 --- a/.github/.devcontainer/Dockerfile +++ b/.github/.devcontainer/Dockerfile @@ -1,2 +1,2 @@ ARG VARIANT="jammy" -FROM buildpack-deps:${VARIANT}-curl +FROM --platform=linux/amd64 buildpack-deps:${VARIANT}-curl diff --git a/.github/.devcontainer/devcontainer.json b/.github/.devcontainer/devcontainer.json index ae5d8b2..5c4338c 100644 --- a/.github/.devcontainer/devcontainer.json +++ b/.github/.devcontainer/devcontainer.json @@ -35,6 +35,7 @@ "ghcr.io/julialang/devcontainer-features/julia:1": { "channel": "release" }, + "./init-env": {}, "ghcr.io/rocker-org/devcontainer-features/quarto-cli:1": { "version": "prerelease", "installTinyTex": "true", diff --git a/.github/.devcontainer/init-env/devcontainer-feature.json b/.github/.devcontainer/init-env/devcontainer-feature.json new file mode 100644 index 0000000..e8ae1ae --- /dev/null +++ b/.github/.devcontainer/init-env/devcontainer-feature.json @@ -0,0 +1,32 @@ +{ + "id": "init-env", + "version": "1.0.0", + "name": "Initialise Computing Environments", + "description": "Initialises R, Python, and Julia environments.", + "options": { + "what": { + "type": "string", + "enum": ["all", "r", "python", "julia"], + "default": "all", + "description": "Specify what to initialise." + }, + "force": { + "type": "boolean", + "default": false, + "description": "Force initialisation regardless of existing files." + } + }, + "postCreateCommand": "/usr/local/share/init-env.sh", + "dependsOn": { + "ghcr.io/devcontainers/features/common-utils": {}, + "ghcr.io/rocker-org/devcontainer-features/r-rig": {}, + "ghcr.io/devcontainers/features/python": {}, + "ghcr.io/julialang/devcontainer-features/julia": {} + }, + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils", + "ghcr.io/rocker-org/devcontainer-features/r-rig", + "ghcr.io/devcontainers/features/python", + "ghcr.io/julialang/devcontainer-features/julia" + ] +} diff --git a/.github/.devcontainer/init-env/install.sh b/.github/.devcontainer/init-env/install.sh new file mode 100755 index 0000000..4246163 --- /dev/null +++ b/.github/.devcontainer/init-env/install.sh @@ -0,0 +1,126 @@ +#!/usr/bin/env bash + +set -e + +export DEBIAN_FRONTEND=noninteractive +USERNAME=${_REMOTE_USER:-"vscode"} + +show_help() { + echo "Usage: $0 [--what/-w all|r|python|julia] [--force/-f] [--help/-h]" + echo " --what/-w: Specify what to initialise (default: all)." + echo " all: Initialise R (renv), Python (virtualenv), and Julia (project)." + echo " r: Initialise R (renv)." + echo " python: Initialise Python (virtualenv)." + echo " julia: Initialise Julia (project)." + echo " --force/-f: Force initialisation regardless of existing files." + echo " --help/-h: Show this help message." +} + +initialise_r() { + if [ "$FORCE" = true ] || [ ! -f "renv.lock" ]; then + su "${USERNAME}" -c "Rscript -e 'renv::init(bare = FALSE)'" + su "${USERNAME}" -c "Rscript -e 'renv::install(\"rmarkdown\")'" + su "${USERNAME}" -c "Rscript -e 'renv::snapshot(type = \"all\")'" + fi +} + +initialise_python() { + if [ "$FORCE" = true ] || [ ! -f "requirements.txt" ]; then + su "${USERNAME}" -c "python3 -m venv .venv" + su "${USERNAME}" -c "source .venv/bin/activate" + su "${USERNAME}" -c "python3 -m pip install jupyter" + su "${USERNAME}" -c "python3 -m pip freeze > requirements.txt" + fi +} + +initialise_julia() { + if [ "$FORCE" = true ] || [ ! -f "Project.toml" ]; then + su "${USERNAME}" -c "julia -e 'using Pkg; Pkg.activate(\".\"); Pkg.instantiate()'" + su "${USERNAME}" -c "julia --project=. -e 'using Pkg; Pkg.add("IJulia")'" + fi +} + +WHAT="all" +FORCE=false + +while [[ "$#" -gt 0 ]]; do + case $1 in + --what|-w) + WHAT="$2" + shift + ;; + --force|-f) + FORCE=true + ;; + --help|-h) + show_help + exit 0 + ;; + *) + echo "Unknown parameter passed: $1" + show_help + exit 1 + ;; + esac + shift +done + +mkdir -p ${_REMOTE_USER_HOME}/quarto-env +cd ${_REMOTE_USER_HOME}/quarto-env + +case $WHAT in + all) + initialise_r + initialise_python + initialise_julia + ;; + r) + initialise_r + ;; + python) + initialise_python + ;; + julia) + initialise_julia + ;; + *) + echo "Unknown option for --what: $WHAT" + show_help + exit 1 + ;; +esac + +INIT_ENV_PATH="/usr/local/share/init-env.sh" + +tee "${INIT_ENV_PATH}" > /dev/null \ +<< EOF +#!/usr/bin/env bash +set -e +EOF + +tee -a "${INIT_ENV_PATH}" > /dev/null \ +<< 'EOF' +while [[ "$#" -gt 0 ]]; do + case $1 in + --source|-s) + SOURCE_DIR="$2" + shift + ;; + --target|-t) + TARGET_DIR="$2" + ;; + *) + echo "Unknown parameter passed: $1" + show_help + exit 1 + ;; + esac + shift +done + +for item in "${SOURCE_DIR}"/*; do + ln -sf "${item}" "${TARGET_DIR}/" +done +EOF + +chmod 755 "${INIT_ENV_PATH}" diff --git a/init.sh b/init.sh deleted file mode 100755 index 9a74c96..0000000 --- a/init.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env bash - -show_help() { - echo "Usage: $0 [--what/-w all|r|python|julia] [--force/-f] [--help/-h]" - echo " --what/-w: Specify what to initialise (default: all)." - echo " all: Initialise R (renv), Python (virtualenv), and Julia (project)." - echo " r: Initialise R (renv)." - echo " python: Initialise Python (virtualenv)." - echo " julia: Initialise Julia (project)." - echo " --force/-f: Force initialisation regardless of existing files." - echo " --help/-h: Show this help message." -} - -initialize_r() { - if [ "$FORCE" = true ] || [ ! -f "renv.lock" ]; then - Rscript -e 'renv::init(bare = FALSE)' - Rscript -e 'renv::install("rmarkdown")' - Rscript -e 'renv::snapshot(type = "all")' - fi -} - -initialize_python() { - if [ "$FORCE" = true ] || [ ! -f "requirements.txt" ]; then - python3 -m venv .venv - source .venv/bin/activate - python3 -m pip install jupyter - python3 -m pip freeze > requirements.txt - fi -} - -initialize_julia() { - if [ "$FORCE" = true ] || [ ! -f "Project.toml" ]; then - julia -e 'using Pkg; Pkg.activate("."); Pkg.instantiate()' - julia --project=. -e 'using Pkg; Pkg.add("IJulia")' - fi -} - -WHAT="all" -FORCE=false - -while [[ "$#" -gt 0 ]]; do - case $1 in - --what|-w) - WHAT="$2" - shift - ;; - --force|-f) - FORCE=true - ;; - --help|-h) - show_help - exit 0 - ;; - *) - echo "Unknown parameter passed: $1" - show_help - exit 1 - ;; - esac - shift -done - -case $WHAT in - all) - initialize_r - initialize_python - initialize_julia - ;; - r) - initialize_r - ;; - python) - initialize_python - ;; - julia) - initialize_julia - ;; - *) - echo "Unknown option for --what: $WHAT" - show_help - exit 1 - ;; -esac From 9044a1ec5cdf473c6da3d54c5b9ebe13d3aa4136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sat, 11 Jan 2025 17:07:11 +0100 Subject: [PATCH 2/6] refactor: install deps as root --- .github/.devcontainer/devcontainer.json | 4 +- .github/.devcontainer/init-env/install.sh | 126 ------------------ .../devcontainer-feature.json | 16 +-- .../install-quarto-dependencies/install.sh | 36 +++++ 4 files changed, 44 insertions(+), 138 deletions(-) delete mode 100755 .github/.devcontainer/init-env/install.sh rename .github/.devcontainer/{init-env => install-quarto-dependencies}/devcontainer-feature.json (60%) create mode 100755 .github/.devcontainer/install-quarto-dependencies/install.sh diff --git a/.github/.devcontainer/devcontainer.json b/.github/.devcontainer/devcontainer.json index 5c4338c..7397f99 100644 --- a/.github/.devcontainer/devcontainer.json +++ b/.github/.devcontainer/devcontainer.json @@ -35,7 +35,9 @@ "ghcr.io/julialang/devcontainer-features/julia:1": { "channel": "release" }, - "./init-env": {}, + "./install-quarto-dependencies": { + "dependencies": "all" + }, "ghcr.io/rocker-org/devcontainer-features/quarto-cli:1": { "version": "prerelease", "installTinyTex": "true", diff --git a/.github/.devcontainer/init-env/install.sh b/.github/.devcontainer/init-env/install.sh deleted file mode 100755 index 4246163..0000000 --- a/.github/.devcontainer/init-env/install.sh +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env bash - -set -e - -export DEBIAN_FRONTEND=noninteractive -USERNAME=${_REMOTE_USER:-"vscode"} - -show_help() { - echo "Usage: $0 [--what/-w all|r|python|julia] [--force/-f] [--help/-h]" - echo " --what/-w: Specify what to initialise (default: all)." - echo " all: Initialise R (renv), Python (virtualenv), and Julia (project)." - echo " r: Initialise R (renv)." - echo " python: Initialise Python (virtualenv)." - echo " julia: Initialise Julia (project)." - echo " --force/-f: Force initialisation regardless of existing files." - echo " --help/-h: Show this help message." -} - -initialise_r() { - if [ "$FORCE" = true ] || [ ! -f "renv.lock" ]; then - su "${USERNAME}" -c "Rscript -e 'renv::init(bare = FALSE)'" - su "${USERNAME}" -c "Rscript -e 'renv::install(\"rmarkdown\")'" - su "${USERNAME}" -c "Rscript -e 'renv::snapshot(type = \"all\")'" - fi -} - -initialise_python() { - if [ "$FORCE" = true ] || [ ! -f "requirements.txt" ]; then - su "${USERNAME}" -c "python3 -m venv .venv" - su "${USERNAME}" -c "source .venv/bin/activate" - su "${USERNAME}" -c "python3 -m pip install jupyter" - su "${USERNAME}" -c "python3 -m pip freeze > requirements.txt" - fi -} - -initialise_julia() { - if [ "$FORCE" = true ] || [ ! -f "Project.toml" ]; then - su "${USERNAME}" -c "julia -e 'using Pkg; Pkg.activate(\".\"); Pkg.instantiate()'" - su "${USERNAME}" -c "julia --project=. -e 'using Pkg; Pkg.add("IJulia")'" - fi -} - -WHAT="all" -FORCE=false - -while [[ "$#" -gt 0 ]]; do - case $1 in - --what|-w) - WHAT="$2" - shift - ;; - --force|-f) - FORCE=true - ;; - --help|-h) - show_help - exit 0 - ;; - *) - echo "Unknown parameter passed: $1" - show_help - exit 1 - ;; - esac - shift -done - -mkdir -p ${_REMOTE_USER_HOME}/quarto-env -cd ${_REMOTE_USER_HOME}/quarto-env - -case $WHAT in - all) - initialise_r - initialise_python - initialise_julia - ;; - r) - initialise_r - ;; - python) - initialise_python - ;; - julia) - initialise_julia - ;; - *) - echo "Unknown option for --what: $WHAT" - show_help - exit 1 - ;; -esac - -INIT_ENV_PATH="/usr/local/share/init-env.sh" - -tee "${INIT_ENV_PATH}" > /dev/null \ -<< EOF -#!/usr/bin/env bash -set -e -EOF - -tee -a "${INIT_ENV_PATH}" > /dev/null \ -<< 'EOF' -while [[ "$#" -gt 0 ]]; do - case $1 in - --source|-s) - SOURCE_DIR="$2" - shift - ;; - --target|-t) - TARGET_DIR="$2" - ;; - *) - echo "Unknown parameter passed: $1" - show_help - exit 1 - ;; - esac - shift -done - -for item in "${SOURCE_DIR}"/*; do - ln -sf "${item}" "${TARGET_DIR}/" -done -EOF - -chmod 755 "${INIT_ENV_PATH}" diff --git a/.github/.devcontainer/init-env/devcontainer-feature.json b/.github/.devcontainer/install-quarto-dependencies/devcontainer-feature.json similarity index 60% rename from .github/.devcontainer/init-env/devcontainer-feature.json rename to .github/.devcontainer/install-quarto-dependencies/devcontainer-feature.json index e8ae1ae..4a7598e 100644 --- a/.github/.devcontainer/init-env/devcontainer-feature.json +++ b/.github/.devcontainer/install-quarto-dependencies/devcontainer-feature.json @@ -1,22 +1,16 @@ { - "id": "init-env", + "id": "install-quarto-dependencies", "version": "1.0.0", - "name": "Initialise Computing Environments", - "description": "Initialises R, Python, and Julia environments.", + "name": "Install Computing Dependencies for Quarto", + "description": "Install R, Python, and Julia dependencies for Quarto.", "options": { - "what": { + "dependencies": { "type": "string", "enum": ["all", "r", "python", "julia"], "default": "all", - "description": "Specify what to initialise." - }, - "force": { - "type": "boolean", - "default": false, - "description": "Force initialisation regardless of existing files." + "description": "Specify what dependencies to install." } }, - "postCreateCommand": "/usr/local/share/init-env.sh", "dependsOn": { "ghcr.io/devcontainers/features/common-utils": {}, "ghcr.io/rocker-org/devcontainer-features/r-rig": {}, diff --git a/.github/.devcontainer/install-quarto-dependencies/install.sh b/.github/.devcontainer/install-quarto-dependencies/install.sh new file mode 100755 index 0000000..4489299 --- /dev/null +++ b/.github/.devcontainer/install-quarto-dependencies/install.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -e + +export DEBIAN_FRONTEND=noninteractive +USERNAME=${_REMOTE_USER:-"vscode"} +DEPENDENCIES=${DEPENDENCIES:-"all"} + +quarto_r_deps() { + su "${USERNAME}" -c "Rscript -e 'pak::pkg_install(\"rmarkdown\")'" +} + +quarto_python_deps() { + su "${USERNAME}" -c "python3 -m pip install jupyter" +} + +initialise_julia() { + su "${USERNAME}" -c "julia -e 'using Pkg; Pkg.add("IJulia")'" +} + +case ${DEPENDENCIES} in + all) + initialise_r + initialise_python + initialise_julia + ;; + r) + initialise_r + ;; + python) + initialise_python + ;; + julia) + initialise_julia + ;; +esac From 1ec6b3faa4094b8be20d28a62d7a97e8afeb4676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sat, 11 Jan 2025 17:07:24 +0100 Subject: [PATCH 3/6] fix: put back env init script --- init-env.sh | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 init-env.sh diff --git a/init-env.sh b/init-env.sh new file mode 100644 index 0000000..9a74c96 --- /dev/null +++ b/init-env.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +show_help() { + echo "Usage: $0 [--what/-w all|r|python|julia] [--force/-f] [--help/-h]" + echo " --what/-w: Specify what to initialise (default: all)." + echo " all: Initialise R (renv), Python (virtualenv), and Julia (project)." + echo " r: Initialise R (renv)." + echo " python: Initialise Python (virtualenv)." + echo " julia: Initialise Julia (project)." + echo " --force/-f: Force initialisation regardless of existing files." + echo " --help/-h: Show this help message." +} + +initialize_r() { + if [ "$FORCE" = true ] || [ ! -f "renv.lock" ]; then + Rscript -e 'renv::init(bare = FALSE)' + Rscript -e 'renv::install("rmarkdown")' + Rscript -e 'renv::snapshot(type = "all")' + fi +} + +initialize_python() { + if [ "$FORCE" = true ] || [ ! -f "requirements.txt" ]; then + python3 -m venv .venv + source .venv/bin/activate + python3 -m pip install jupyter + python3 -m pip freeze > requirements.txt + fi +} + +initialize_julia() { + if [ "$FORCE" = true ] || [ ! -f "Project.toml" ]; then + julia -e 'using Pkg; Pkg.activate("."); Pkg.instantiate()' + julia --project=. -e 'using Pkg; Pkg.add("IJulia")' + fi +} + +WHAT="all" +FORCE=false + +while [[ "$#" -gt 0 ]]; do + case $1 in + --what|-w) + WHAT="$2" + shift + ;; + --force|-f) + FORCE=true + ;; + --help|-h) + show_help + exit 0 + ;; + *) + echo "Unknown parameter passed: $1" + show_help + exit 1 + ;; + esac + shift +done + +case $WHAT in + all) + initialize_r + initialize_python + initialize_julia + ;; + r) + initialize_r + ;; + python) + initialize_python + ;; + julia) + initialize_julia + ;; + *) + echo "Unknown option for --what: $WHAT" + show_help + exit 1 + ;; +esac From ec857f14ad2e4ed3d7561ce5f0eadd448cf5b5c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sat, 11 Jan 2025 17:26:28 +0100 Subject: [PATCH 4/6] refactor: renaming --- .github/.devcontainer/devcontainer.json | 2 +- .../devcontainer-feature.json | 2 +- .../install-quarto-dependencies/install.sh | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/.devcontainer/devcontainer.json b/.github/.devcontainer/devcontainer.json index 7397f99..08e3679 100644 --- a/.github/.devcontainer/devcontainer.json +++ b/.github/.devcontainer/devcontainer.json @@ -35,7 +35,7 @@ "ghcr.io/julialang/devcontainer-features/julia:1": { "channel": "release" }, - "./install-quarto-dependencies": { + "./quarto-computing-dependencies": { "dependencies": "all" }, "ghcr.io/rocker-org/devcontainer-features/quarto-cli:1": { diff --git a/.github/.devcontainer/install-quarto-dependencies/devcontainer-feature.json b/.github/.devcontainer/install-quarto-dependencies/devcontainer-feature.json index 4a7598e..e7c688c 100644 --- a/.github/.devcontainer/install-quarto-dependencies/devcontainer-feature.json +++ b/.github/.devcontainer/install-quarto-dependencies/devcontainer-feature.json @@ -1,5 +1,5 @@ { - "id": "install-quarto-dependencies", + "id": "quarto-computing-dependencies", "version": "1.0.0", "name": "Install Computing Dependencies for Quarto", "description": "Install R, Python, and Julia dependencies for Quarto.", diff --git a/.github/.devcontainer/install-quarto-dependencies/install.sh b/.github/.devcontainer/install-quarto-dependencies/install.sh index 4489299..7e2166d 100755 --- a/.github/.devcontainer/install-quarto-dependencies/install.sh +++ b/.github/.devcontainer/install-quarto-dependencies/install.sh @@ -14,23 +14,23 @@ quarto_python_deps() { su "${USERNAME}" -c "python3 -m pip install jupyter" } -initialise_julia() { +quarto_julia_deps() { su "${USERNAME}" -c "julia -e 'using Pkg; Pkg.add("IJulia")'" } case ${DEPENDENCIES} in all) - initialise_r - initialise_python - initialise_julia + quarto_r_deps + quarto_python_deps + quarto_julia_deps ;; r) - initialise_r + quarto_r_deps ;; python) - initialise_python + quarto_python_deps ;; julia) - initialise_julia + quarto_julia_deps ;; esac From 039597f221459f3cb0e57c85b2f2df4b9bee96f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sat, 11 Jan 2025 17:28:17 +0100 Subject: [PATCH 5/6] refactor: rename feature --- .../devcontainer-feature.json | 0 .../install.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .github/.devcontainer/{install-quarto-dependencies => quarto-computing-dependencies}/devcontainer-feature.json (100%) rename .github/.devcontainer/{install-quarto-dependencies => quarto-computing-dependencies}/install.sh (100%) diff --git a/.github/.devcontainer/install-quarto-dependencies/devcontainer-feature.json b/.github/.devcontainer/quarto-computing-dependencies/devcontainer-feature.json similarity index 100% rename from .github/.devcontainer/install-quarto-dependencies/devcontainer-feature.json rename to .github/.devcontainer/quarto-computing-dependencies/devcontainer-feature.json diff --git a/.github/.devcontainer/install-quarto-dependencies/install.sh b/.github/.devcontainer/quarto-computing-dependencies/install.sh similarity index 100% rename from .github/.devcontainer/install-quarto-dependencies/install.sh rename to .github/.devcontainer/quarto-computing-dependencies/install.sh From 52b58c08ba80883b54d7aaf5df7c1652a71b8d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sat, 11 Jan 2025 17:42:23 +0100 Subject: [PATCH 6/6] fix: use juliaup path --- .../quarto-computing-dependencies/install.sh | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/.github/.devcontainer/quarto-computing-dependencies/install.sh b/.github/.devcontainer/quarto-computing-dependencies/install.sh index 7e2166d..d61cf37 100755 --- a/.github/.devcontainer/quarto-computing-dependencies/install.sh +++ b/.github/.devcontainer/quarto-computing-dependencies/install.sh @@ -3,9 +3,35 @@ set -e export DEBIAN_FRONTEND=noninteractive -USERNAME=${_REMOTE_USER:-"vscode"} + DEPENDENCIES=${DEPENDENCIES:-"all"} +USERNAME=${USERNAME:-${_REMOTE_USER:-"automatic"}} + +set -e + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +# Determine the appropriate non-root user +if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then + USERNAME="" + POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)") + for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do + if id -u "${CURRENT_USER}" >/dev/null 2>&1; then + USERNAME=${CURRENT_USER} + break + fi + done + if [ "${USERNAME}" = "" ]; then + USERNAME=root + fi +elif [ "${USERNAME}" = "none" ] || ! id -u "${USERNAME}" >/dev/null 2>&1; then + USERNAME=root +fi + quarto_r_deps() { su "${USERNAME}" -c "Rscript -e 'pak::pkg_install(\"rmarkdown\")'" } @@ -15,7 +41,7 @@ quarto_python_deps() { } quarto_julia_deps() { - su "${USERNAME}" -c "julia -e 'using Pkg; Pkg.add("IJulia")'" + su "${USERNAME}" -c "~/.juliaup/bin/julia -e 'using Pkg; Pkg.add(\"IJulia\")'" } case ${DEPENDENCIES} in