From a13ae48efa3457fb49e1b3d960433283a1c065dc Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Thu, 8 Sep 2022 16:29:15 -0500 Subject: [PATCH] 1. /usr/local/bin may not even exist, so try to create it if it doesn't exist; 2. use `chown` in the installation script if /usr/local/bin is not writable --- DESCRIPTION | 2 +- R/install.R | 16 ++++++++++------ tools/install-bin-unix.sh | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4404d7caf..b7518ac8e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: tinytex Type: Package Title: Helper Functions to Install and Maintain TeX Live, and Compile LaTeX Documents -Version: 0.41.2 +Version: 0.41.3 Authors@R: c( person("Yihui", "Xie", role = c("aut", "cre", "cph"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), person(family = "RStudio, PBC", role = "cph"), diff --git a/R/install.R b/R/install.R index 1d3b64dc1..6c1817cea 100644 --- a/R/install.R +++ b/R/install.R @@ -204,17 +204,21 @@ win_app_dir = function(..., error = TRUE) { # check if /usr/local/bin on macOS is writable check_local_bin = function() { - if (os_index != 3 || is_writable('/usr/local/bin')) return() - chown_cmd = 'chown -R `whoami`:admin /usr/local/bin' + if (os_index != 3 || is_writable(p <- '/usr/local/bin')) return() message( - 'The directory /usr/local/bin is not writable. I recommend that you ', - 'make it writable. See https://github.com/rstudio/tinytex/issues/24 for more info.' + 'The directory ', p, ' is not writable. I recommend that you make it writable. ', + 'See https://github.com/rstudio/tinytex/issues/24 for more info.' ) + if (!dir_exists(p)) osascript(paste('mkdir -p', p)) + osascript(paste('chown -R `whoami`:admin', p)) +} + +osascript = function(cmd) { if (system(sprintf( - "/usr/bin/osascript -e 'do shell script \"%s\" with administrator privileges'", chown_cmd + "/usr/bin/osascript -e 'do shell script \"%s\" with administrator privileges'", cmd )) != 0) warning( "Please run this command in your Terminal (password required):\n sudo ", - chown_cmd, call. = FALSE + cmd, call. = FALSE ) } diff --git a/tools/install-bin-unix.sh b/tools/install-bin-unix.sh index 8ae263692..916876598 100755 --- a/tools/install-bin-unix.sh +++ b/tools/install-bin-unix.sh @@ -68,4 +68,18 @@ fi [ $OSNAME != "Darwin" ] && ./tlmgr option sys_bin $BINDIR ./tlmgr postaction install script xetex # GH issue #313 ([ -z $CI ] || [ $(echo $CI | tr "[:upper:]" "[:lower:]") != "true" ]) && ./tlmgr option repository ctan + +if [ $OSNAME = 'Darwin' ]; then + # create the dir if it doesn't exist + if [ ! -d /usr/local/bin ]; then + echo "Admin privilege (password) is required to create the directory /usr/local/bin:" + sudo mkdir -p /usr/local/bin + fi + # change owner of the dir + if [ ! -w /usr/local/bin ]; then + echo "Admin privilege (password) is required to make /usr/local/bin writable:" + sudo chown -R `whoami`:admin /usr/local/bin + fi +fi + ./tlmgr path add