Skip to content

Commit

Permalink
use osascript to ask for password to chown /usr/local/bin on macOS (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Oct 12, 2018
1 parent 1b130e1 commit 85b626c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tinytex
Type: Package
Title: Helper Functions to Install and Maintain 'TeX Live', and Compile 'LaTeX' Documents
Version: 0.8.2
Version: 0.8.3
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre", "cph"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person(family = "RStudio, Inc.", role = "cph"),
Expand Down
21 changes: 14 additions & 7 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ install_tinytex = function(
if (Sys.which(downloader) == '') stop(sprintf(
"'%s' is not found but required to install TinyTeX", downloader
), call. = FALSE)
if (macos && file.access('/usr/local/bin', 2) != 0) {
chown_cmd = 'chown -R `whoami`:admin /usr/local/bin'
message(
'The directory /usr/local/bin is not writable. I need your admin privilege ',
'to make it writable. See https://github.com/yihui/tinytex/issues/24 for more info.'
)
if (system(sprintf(
"/usr/bin/osascript -e 'do shell script \"%s\" with administrator privileges'", chown_cmd
)) != 0) stop(
"Please run this command in your Terminal and retry installing TinyTeX:\n sudo ",
chown_cmd, call. = FALSE
)
}
if (!macos && !dir_exists('~/bin')) on.exit(message(
'You may have to restart your system after installing TinyTeX to make sure ',
'~/bin appears in your PATH variable (https://github.com/yihui/tinytex/issues/16).'
Expand All @@ -98,13 +111,7 @@ install_tinytex = function(
'--no-admin', '--path', shQuote(repository), if (macos && https) 'tlgpg'
)
))
if (res != 0) {
if (macos && file.access('/usr/local/bin', 2) != 0) message(
'The directory /usr/local/bin is not writable; ',
'see https://github.com/yihui/tinytex/issues/24 for more info.'
)
stop('Failed to install TinyTeX', call. = FALSE)
}
if (res != 0) stop('Failed to install TinyTeX', call. = FALSE)
target = normalizePath(
if (macos) '~/Library/TinyTeX' else '~/.TinyTeX'
)
Expand Down

0 comments on commit 85b626c

Please sign in to comment.