-
Notifications
You must be signed in to change notification settings - Fork 35
/
installr
executable file
·112 lines (95 loc) · 3.07 KB
/
installr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#! /bin/ash
set -e
usage() {
echo "Usage: $0 [ -c | -d ] [ -e ] [ -a pkgs ] [ -t pkgs ] [ -r ] [ -p ] REMOTES ..."
echo
echo "Options:"
echo " -c install C and C++ compilers and keep them"
echo " -d install C and C++ compilers, temporarily"
echo " -a install Alpine packages and keep them"
echo " -t install Alpine packages, temporarily"
echo " -p do not remove pak after the installation (ignored if -r is given)".
echo " -e use renv to restore the renv.lock file if present."
echo
echo "REMOTES may be:"
echo " * package names from CRAN/Bioconductor, e.g. ggplot2"
echo " * slugs of GitHub repos, e.g. tidyverse/ggplot2"
echo " * GitHub branch, tag or commit, e.g tidyverse/[email protected]"
echo " * URLs to package .tar.gz files, e.g. url::https://x.com/pkg.tar.gz"
echo " * path to a local directory, e.g. local::."
exit 2
}
error() {
echo $1 >&2
exit 2
}
unset KEEP_PAK
while getopts 'pecda:t:?h' o
do
case $o in
a) APKG_FIN=$OPTARG ; shift ;;
t) APKG_TMP=$OPTARG ; shift ;;
c) APKG_COMPILERS=true ;;
d) APKG_COMPILERS_TMP=true ;;
p) KEEP_PAK=true ;;
e) USE_RENV=true ;;
h|?) usage ;;
esac
shift
done
APKG_GCC="gcc musl-dev g++"
if [[ -n "$APKG_COMPILERS" ]]; then
APKG_FIN="$APKG_FIN $APKG_GCC"
fi
if [[ -n "$APKG_COMPILERS_TMP" ]]; then
APKG_TMP="$APKG_TMP $APKG_GCC"
fi
echo
echo --------------------------------------
[[ -n "$APKG_FIN" ]] && echo Adding "$APKG_FIN"
[[ -n "$APKG_TMP" ]] && echo Temporarily adding "$APKG_TMP"
apk add --no-cache $APKG_FIN $APKG_TMP
echo
echo --------------------------------------
echo "Installing pak (if needed)"
Rscript -e 'if (! requireNamespace("pak", quietly=TRUE)) install.packages("pak", repos = sprintf("https://r-lib.github.io/p/pak/devel/%s/%s/%s", .Platform$pkgType, R.Version()$os, R.Version()$arch))'
if [[ $# -eq 0 ]]; then
echo
echo --------------------------------------
echo No R packages to install
else
echo
echo --------------------------------------
echo Installing "$@"
Rscript -e 'pak::pkg_install(commandArgs(TRUE))' "$@"
fi
echo
echo --------------------------------------
echo Cleaning up pak cache
Rscript -e 'pak::cache_clean(); pak::meta_clean(TRUE)'
rm -rf /tmp/Rtmp*
if [[ -z "$KEEP_PAK" ]]; then
echo
echo --------------------------------------
echo Removing pak
Rscript -e 'remove.packages("pak")'
fi
echo --------------------------------------
echo "Activating and Restoring renv.lock file if needed."
if [[ "$USE_RENV" == true ]]; then
if [[ -f "./renv.lock" ]]; then
Rscript -e 'renv::consent(provided = TRUE)'
Rscript -e 'renv::restore()'
else
echo "renv.lock file is not present in the current directory."
fi
fi
rm -rf /tmp/Rtmp*
echo
echo --------------------------------------
[[ -n "$APKG_TMP" ]] && echo Removing "$APKG_TMP"
apk del $APKG_TMP
echo
echo --------------------------------------
echo Cleaning up cache
rm -rf /var/cache/apk/*