Create /usr/local/bin if necessary in OS X
@@ -17,11 +17,19 @@ sdk_install_dir() {
if [ "${DFX_INSTALL_ROOT:-}" ]; then
# By default we install to a home directory.
printf %s "${DFX_INSTALL_ROOT}"
- elif [ -d /usr/local/bin ]; then
+ elif [ -d /usr/local/bin ] && [ -w /usr/local/bin ]; then
printf %s /usr/local/bin
- elif [ -d /usr/bin ]; then
+ elif [ "$(uname -s)" = Darwin ]; then
+ # OS X does not allow users to write to /usr/bin by default. In case the
+ # user is missing a /usr/local/bin we need to create it. Even if it is
+ # not "writeable" we expect the user to have access to super user
+ # privileges during the installation.
+ mkdir -p /usr/local/bin 2>/dev/null || sudo mkdir -p /usr/local/bin || true
+ printf %s /usr/local/bin
+ elif [ -d /usr/bin ] && [ -w /usr/bin ]; then
printf %s /usr/bin
else
+ # This is our last choice.
printf %s "${HOME}/bin"
fi
}
@@ -78,6 +86,7 @@ main() {
local _install_dir
_install_dir="$(sdk_install_dir)"
+ printf "%s\n" "Will install in: ${_install_dir}"
mkdir -p "${_install_dir}" || true
mv "$_dfx_file" "${_install_dir}" || sudo mv "$_dfx_file" "${_install_dir}" \
@@ -213,6 +222,9 @@ downloader() {
install_uninstall_script() {
set +u
+ local uninstall_file_path
+ local uninstall_script
+
uninstall_script=$(
cat <<'EOF'
#!/usr/bin/env sh
@@ -246,7 +258,6 @@ clean_cache() {
uninstall
EOF
)
-
set -u
# Being a bit more paranoid and rechecking.
assert_nz "${HOME}"
