rstudio / r-builds

an opinionated environment for compiling R
GNU General Public License v3.0
100 stars 19 forks source link

Avoid using /usr/bin/tar on Debian machines #198

Open kevinushey opened 9 months ago

kevinushey commented 9 months ago

This is a follow-up from https://github.com/rstudio/renv/issues/1794.

For the builds of R published on https://docs.posit.co/resources/install-r, it looks like R is configured to use system installations of tar and sed as so:

$ cat Renviron | grep 'SED\|TAR'
SED=${SED-'/usr/bin/sed'}
TAR=${TAR-'/usr/bin/tar'}

This can be problematic in rare scenarios, as /usr/bin/sed and /usr/bin/tar are not actually provided by any apt packages. So, if those programs are not available for some reason, it's not clear for the user on how to recover.

Some other similar instances:

$ cat Renviron | grep /usr/bin/
R_PRINTCMD=${R_PRINTCMD-'/usr/bin/lpr'}
R_TEXI2DVICMD=${R_TEXI2DVICMD-${TEXI2DVI-'/usr/bin/texi2dvi'}}
R_GZIPCMD=${R_GZIPCMD-'/usr/bin/gzip'}
R_UNZIPCMD=${R_UNZIPCMD-'/usr/bin/unzip'}
R_ZIPCMD=${R_ZIPCMD-'/usr/bin/zip'}
R_BZIPCMD=${R_BZIPCMD-'/usr/bin/bzip2'}
PAGER=${PAGER-'/usr/bin/pager'}
R_PDFVIEWER=${R_PDFVIEWER-'/usr/bin/xdg-open'}
SED=${SED-'/usr/bin/sed'}
TAR=${TAR-'/usr/bin/tar'}

In other words, for each of these programs, if a variant exists in /bin, I think that version should be preferred.

glin commented 9 months ago

I bet this is the same issue we once got with /bin/sed vs. /usr/bin/sed before, #72. On recent Ubuntu/Debian, /bin was merged into /usr/bin so with stock docker images like the one we're using, tar is actually at /usr/bin/tar with /bin/tar being a symlink:

docker run -it --rm ubuntu:focal

$ ls -la /bin
lrwxrwxrwx 1 root root 7 Aug 26  2022 /bin -> usr/bin

$ readlink -f /bin/tar
/usr/bin/tar

This causes issues for unmerged systems (if you've upgraded from an older OS perhaps?) and other things unfortunately: https://lwn.net/Articles/890219/

So for newer Ubuntu and Debian builds, we could override the TAR location to /bin/tar. I believe the Ubuntu builds already manually set some bin locations like ZIPCMD but not TAR. But also, I wonder if this could also cause issues if /bin is supposedly intended to be eliminated eventually.

If we want to set TAR and prevent issues from unmerged /usr systems, there are some other variables that the distro default r-base sets as well for reference: https://salsa.debian.org/edd/r-base/-/merge_requests/1

gaborcsardi commented 9 months ago

Yeah, it is the upgrades that cause issues, the symlinks are missing on upgraded systems.

kevinushey commented 9 months ago

Thanks; I wasn't aware of that! For what it's worth:

$ dpkg -L tar | grep /bin/tar
/bin/tar

$ dpkg -L sed | grep /bin/sed
/bin/sed

which I think gives some (small) amount of motivation to prefer /bin/tar over /usr/bin/tar.

gaborcsardi commented 9 months ago

We had this in rig some time ago, for sed (https://github.com/r-lib/rig/issues/119#issuecomment-1644040882), apparently it also applies to tar. It would be nice to fix it properly.

mabuimo commented 9 months ago

I bet this is the same issue we once got with /bin/sed vs. /usr/bin/sed before, #72.

Indeed, I also needed to manually create symlinks for that directory (Ubuntu 20.04 LTS). ln -s /bin/tar /usr/bin/tar