Comments (9)
@coatless you have sudo
in the wrong place - you don't want to run curl
as root
, you want to run tar
as root, so it's sudo tar ...
. However, note that you cannot supply the password on stdin
in that case as curl
is already the stdin
. You may be better off simply using download.file()
instead and untar in a separate step.
That said, as a user I'd be horrified that you are asking for user password with echo, so I'd recommend relying on the system tools instead.
from recipes.
@s-u system is being used in this demo for an MVP. The full setup is given as:
shell_sudo_command = function(cmd, password, prefix = "sudo -kS ") {
cmd_with_sudo = paste0(prefix, cmd)
if (is.null(password)) {
system(cmd_with_sudo, input = password_prompt("Enter user password to run command:"))
} else {
system(cmd_with_sudo, input = password)
}
}
password_prompt = function(msg) {
if(interactive()) {
if(requireNamespace("rstudioapi", quietly = TRUE) && rstudioapi::isAvailable()) {
rstudioapi::askForPassword(msg)
} else {
readline(msg)
}
} else {
stop("Unable to request password as the session is not being run interactively.")
}
}
When possible, we'll accept the password via rstudioapi::askForPassword()
prompt. Is there a better way of asking and storing a password using plain R?
The goal here is to avoid exposing the user to terminal.
from recipes.
This is OT here, but fair enough - I'd just never allow echoed password entry no matter what, not even as fall-back. You can use askpass::askpass()
which uses safe native entry regardless of the UI used.
from recipes.
Apologies for the off-topic component. I'll re-write using askpass()
Back on topic though, I'm still seeing the Can't restore time
error:
# Download file
download.file(
"https://mac.R-project.org/bin/darwin17/x86_64/xz-5.2.5-darwin.17-x86_64.tar.xz",
"xz-5.2.5-darwin.17-x86_64.tar.xz"
)
# Install command
cmd = "sudo -kS tar fxj xz-5.2.5-darwin.17-x86_64.tar.xz -C /"
system(cmd, input = readline("Password:"))
# Password:usr/local/: Can't restore time
# tar: Error exit delayed from previous errors.
Or:
download.file(
"https://mac.R-project.org/bin/darwin17/x86_64/xz-5.2.5-darwin.17-x86_64.tar.xz",
"xz-5.2.5-darwin.17-x86_64.tar.xz"
)
untar("xz-5.2.5-darwin.17-x86_64.tar.xz", exdir = "/")
Yields:
usr/local/: Can't restore time
usr/local/bin/: Can't restore time
usr/local/include/: Can't restore time
usr/local/lib/: Can't restore time
usr/local/pkg/: Can't restore time
usr/local/share/: Can't restore time
usr/local/share/doc/: Can't restore time
usr/local/share/man/: Can't restore time
usr/local/share/man/man1/: Can't restore time
from recipes.
One comment on the process there - note that even root
is not guaranteed to have access to user's files (on macOS places like Documents
, Download
etc. are not readable even by root
), so you want to make sure if you download the file you do so into tempdir()
.
from recipes.
The above is expected, on macOS not even root can change the attributes of /usr/local
. It is just a note, not an error. You can avoid it by not extracting outside of the prefix (as was illustrated in the issue you quoted: b060377).
from recipes.
Still observing a similar issue even with the modifications into tempdir()
and adding the --strip 2
option.
save_location = file.path(tempdir(), "gdal-3.4.2-darwin.17-x86_64.tar.xz")
download.file(
"https://mac.R-project.org/bin/darwin17/x86_64/gdal-3.4.2-darwin.17-x86_64.tar.xz",
save_location
)
untar(save_location, exdir = "/usr/local", extras = "--strip 2")
Switching to a different package, e.g. gdal
gives:
bin/: Can't restore time
include/: Can't restore time
lib/: Can't restore time
pkg/: Can't restore time
share/: Can't restore time
share/gdal/: Can't create 'share/gdal'
share/gdal/bag_template.xml: Failed to create dir 'share/gdal'
share/gdal/cubewerx_extra.wkt: Failed to create dir 'share/gdal'
share/gdal/default.rsc: Failed to create dir 'share/gdal'
share/gdal/ecw_cs.wkt: Failed to create dir 'share/gdal'
share/gdal/eedaconf.json: Failed to create dir 'share/gdal'
share/gdal/epsg.wkt: Failed to create dir 'share/gdal'
share/gdal/esri_StatePlane_extra.wkt: Failed to create dir 'share/gdal'
share/gdal/gdalicon.png: Failed to create dir 'share/gdal'
share/gdal/GDALLogoBW.svg: Failed to create dir 'share/gdal'
Command output:
'/usr/bin/tar -xf '/var/folders/b0/vt_1hj2d6yd8myx9lwh81pww0000gn/T//RtmpYvXNkT/gdal-3.4.2-darwin.17-x86_64.tar.xz' -C '/usr/local' --strip 2' returned error code 1
from recipes.
I think you missed sudo
here?
from recipes.
@s-u yes, untar()
doesn't seem to have that option.
With sudo
present, everything worked beautiful. I settled on:
package_url = "https://mac.R-project.org/bin/darwin17/x86_64/xz-5.2.5-darwin.17-x86_64.tar.xz"
save_location = file.path(tempdir(), basename(package_url))
download.file(
package_url,
save_location
)
cmd = paste0("sudo -kS tar fxj ", save_location," -C /usr/local/ --strip 2")
system(cmd, input = askpass::askpass())
Thanks again for the help!
from recipes.
Related Issues (20)
- Freetype recipe conflicts with freetype from the xQuartz on the same server HOT 4
- build.sh requires /Library/Frameworks/R.framework/Resources/bin/Rscript HOT 3
- Add Suggests: for conditional dependencies HOT 1
- Poppler missing font data HOT 1
- Find pkg-config files under ./share HOT 1
- Can't find gfortran HOT 5
- netcdf missing from gdal build Depends: HOT 1
- Fatal error occured when compiling latest libpq on macOS Ventura HOT 6
- Several URLs in recipes are dead
- error when installing fribidi, seems to be issue with glib HOT 5
- Compilation error of emacs when using the updated pl script
- Error with freetype HOT 2
- SQL headers clobbering HOT 4
- Cannot compile lz4 HOT 1
- MS-SQL incompatibility with system ODBC HOT 3
- lz4 binary missing for arm64 HOT 1
- pkgconfig build error in Xcode 15.3+ HOT 5
- "Packages not available" Error on R Mac Builder (Development) HOT 2
- Add Build-Depends
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from recipes.