Skip to content

Commit c86d09c

Browse files
committed
wip add basic code [skip ci]
1 parent 2d728b7 commit c86d09c

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

src/r-dependent-packages/devcontainer-feature.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
],
1515
"default": "auto",
1616
"description": "Version of pak to install. By default, the stable version is installed if needed."
17-
}
17+
},
18+
"additionalRepositories": {
19+
"type": "string",
20+
"default": "",
21+
"description": "String passed to the `pak::repo_add()` function.",
22+
"proposals": [
23+
"",
24+
"rhub = 'https://r-hub.r-universe.dev', jeroen = 'https://jeroen.r-universe.dev'"
25+
]
26+
},
1827
}
1928
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
3+
PAK_VERSION=${PAKVERSION:-"auto"}
4+
ROOT=${ROOT:-"."}
5+
ADDITIONAL_REPOSITORIES=${ADDITIONALREPOSITORIES:-""}
6+
7+
USERNAME=${USERNAME:-${_REMOTE_USER}}
8+
9+
LIFECYCLE_SCRIPTS_DIR="/usr/local/share/rocker-devcontainer-features/r-dependent-packages/scripts"
10+
11+
set -e
12+
13+
if [ "$(id -u)" -ne 0 ]; then
14+
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
15+
exit 1
16+
fi
17+
18+
check_r() {
19+
if [ ! -x "$(command -v R)" ]; then
20+
echo "(!) Cannot run R. Please install R before installing this Feature."
21+
echo " Skip installation..."
22+
exit 0
23+
fi
24+
}
25+
26+
install_pak() {
27+
local version=$1
28+
29+
if [ "${version}" = "auto" ]; then
30+
if su "${USERNAME}" -c "R -s -e 'packageVersion(\"pak\")'" >/dev/null 2>&1; then
31+
echo "pak is already installed. Skip pak installation..."
32+
return
33+
else
34+
version="stable"
35+
fi
36+
fi
37+
38+
echo "Installing pak ${version}..."
39+
# shellcheck disable=SC2016
40+
su "${USERNAME}" -c 'R -q -e "install.packages(\"pak\", repos = sprintf(\"https://r-lib.github.io/p/pak/'"${version}"'/%s/%s/%s\", .Platform\$pkgType, R.Version()\$os, R.Version()\$arch))"'
41+
}
42+
43+
export DEBIAN_FRONTEND=noninteractive
44+
45+
# Set Lifecycle scripts
46+
mkdir -p "${LIFECYCLE_SCRIPTS_DIR}"
47+
sed \
48+
-e "s|@REPOS@|${ADDITIONAL_REPOSITORIES}|" \
49+
lifecycle_script.sh >"${LIFECYCLE_SCRIPTS_DIR}/lifecycle_script.sh"
50+
51+
check_r
52+
install_pak "${PAK_VERSION}"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
Rscript -e \
4+
'pak::repo_add(@REPOS@);
5+
pak::local_install_deps("@ROOT@", dependencies = @DEPS@)'
6+
# TODO: how to handle deps?

src/r-dependent-packages/oncreate.sh

Whitespace-only changes.

0 commit comments

Comments
 (0)