Unable to install ports from git source as root : Could not open file

Ryan Schmidt ryandesign at macports.org
Sun Jan 13 22:36:08 UTC 2019



On Jan 12, 2019, at 13:50, Joël Tourscher wrote:

> Hello, 
> 
> I'm trying to use macports and ports from git sources. I have followed the instructions from the [https://guide.macports.org/#installing.macports.git manual], but it doesn't work.
> 
> The port macports-base compiles well, but it is impossible to install any port as root (as well as user). I have an error message.
>  - As sudo : "Error: Unable to execute port: Could not open file: macports-ports/sysutils/coreutils/Portfile"
>  - As user : "Error: Insufficient privileges to write to MacPorts install prefix."
> 
> I need to chown the macports-base tree to the user who is running the port, and then most of them can compile, but only as user, and not as root.
>     sudo chown -R $UID:$GROUPS $MACPORTS_DIR/macports-base
>     sudo chown -R $UID:$GROUPS $MACPORTS_DIR/macports-ports
> 
> 
> Some of ports still need to have root access, and cannot be installed (eg libnetpbm) and then cannot be installed.
> 
> The error message is : "Error: Failed to destroot libnetpbm: command execution failed"
> 
> Note that this seems to work if instead of using a subdir of $HOME as root for projects, a subdir of /tmp is used to build the ports.

Any location inside your home directory is not a suitable location for a ports tree, because macOS configures the permissions of your home directory so that other users cannot access it; that includes the macports user that MacPorts uses when you install it as root. Either move your git checkout of the ports tree outside of your home directory, or else change the permissions of your home directory to give other users access to it (understanding the possible security implications of doing that).


> Here is a script that simulates the test cases.
> 
> Regards, Joel
> 
> https://trac.macports.org/ticket/57894
> 
>  
> MACPORTS_DIR=$HOME/macports/WORK
> 
> mkdir -p $MACPORTS_DIR
> chmod 755 $MACPORTS_DIR
> cd $MACPORTS_DIR
> git clone --depth 1 --branch v2.5.4 https://github.com/macports/macports-base.git
> git clone --depth 1 --branch master https://github.com/macports/macports-ports.git
> 
> # Adapting to use local ports (replacing rsync:// and file:// in sources with file://$MACPORTS_DIR/macports-ports)
> find $MACPORTS_DIR/macports-base -name 'sources.conf' -exec /usr/bin/sed -i '' -E 's/^(rsync|file)(.*)$/#\1\2/' {} \;
> find $MACPORTS_DIR/macports-base -name 'sources.conf' -exec sh -c "echo 'file://$MACPORTS_DIR/macports-ports [default]' >> {}" \;
> 
> # Building base ports
> cd $MACPORTS_DIR/macports-base
> export PATH=/bin:/sbin:/usr/bin:/usr/sbin
> mkdir -p $MACPORTS_DIR/macports-base/Applications
> ./configure --enable-readline --prefix=$MACPORTS_DIR/macports-base --with-applications-dir=$MACPORTS_DIR/macports-base/Applications --without-startupitems
> make -j8
> 
> # make install needs sudo, but it changes owner to root on installed files
> sudo make install
> sudo make distclean
> 
> export PATH=$MACPORTS_DIR/macports-base:$MACPORTS_DIR/macports-base/bin:$MACPORTS_DIR/macports-base/sbin:$PATH
> cd $MACPORTS_DIR/macports-ports
> $MACPORTS_DIR/macports-base/bin/portindex
> 
> # Failure when installing as sudo
> sudo $MACPORTS_DIR/macports-base/bin/port install -vd coreutils
> sudo $MACPORTS_DIR/macports-base/bin/port install -vd libnetpbm
> 
> sudo chown -R $UID:$GROUPS $MACPORTS_DIR/macports-base
> sudo chown -R $UID:$GROUPS $MACPORTS_DIR/macports-ports
> 
> # After chown done, some ports can build, but not when sudo access is needed
> $MACPORTS_DIR/macports-base/bin/port install -vd coreutils
> $MACPORTS_DIR/macports-base/bin/port install -vd libnetpbm

Note that single-dash flags like -v and -d have no effect unless placed immediately after the word "port", before (not after) the command verb.





More information about the macports-users mailing list