mv command not working on mac - makefile

Here is the part of the makefile that is giving me issues:
-#mv -f -t ./ $(LIBPATH)/userfiles/*
When I run the makefile on Ubuntu it works fine however when running on my Mac I get the following error:
mv: illegal option -- t usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
The -t flag is not defined in the man pages of my mac so I'm wondering how I can get around this.

Just put the destination at the end like how mv is normally used:
-#mv -f $(LIBPATH)/userfiles/* .
You are allowed to have multiple sources (such as the expanded wildcard here). The last argument is the destination. The -t flag is just a way to change this ordering if you have to for some reason, and (as you discovered) it is not always available.

Install coreutils by typing the following command in the terminal:
brew install coreutils
Commands also provided by macOS and the commands dir, dircolors, vdir have been installed with the prefix "g".
If you need to use these commands with their normal names, you can add a "gnubin" directory to your PATH with:
PATH="$(brew --prefix)/opt/coreutils/libexec/gnubin:$PATH"
Reference:
coreutils - Homebrew Formulae

Related

Error installing flite on Mac OSX

I have downloaded the latest source distribution of flite, and went about the usual process of installing it.
$ ./configure
$ make
$ sudo make install
However, I run into a strange error when I try to install the library to my system.
$ sudo make install
Installing
mkdir -p /usr/local/bin
mkdir -p /usr/local/lib
mkdir -p /usr/local/include/flite
/usr/bin/install -c -m 644 include/*.h /usr/local/include/flite
/usr/bin/install -c -m 755 ../bin/flite_time /usr/local/bin
cp -pd ../build/i386-darwin13.1.0/lib/libflite_cmu_us_kal.a ../build/i386-darwin13.1.0/lib/libflite_cmu_time_awb.a ../build/i386-darwin13.1.0/lib/libflite_cmu_us_kal16.a ../build/i386-darwin13.1.0/lib/libflite_cmu_us_awb.a ../build/i386-darwin13.1.0/lib/libflite_cmu_us_rms.a ../build/i386-darwin13.1.0/lib/libflite_cmu_us_slt.a ../build/i386-darwin13.1.0/lib/libflite_usenglish.a ../build/i386-darwin13.1.0/lib/libflite_cmulex.a ../build/i386-darwin13.1.0/lib/libflite.a /usr/local/lib
cp: illegal option -- d
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory
make[1]: *** [install] Error 64
make: *** [install] Error 2
How can I fix this?
There a few subtle differences between the BSD cp that Mac uses and the GNU cp of most linux distributions.
Consider the following snippet of man cp from a linux box:
-d same as --no-dereference --preserve=links
-P, --no-dereference
never follow symbolic links in SOURCE
--preserve[=ATTR_LIST]
preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context,
links, xattr, all
So basically what it's trying to do is "copy the following paths, and if they're links, just copy the link, not the underlying file."
The p option exists under Mac and is equivalent to the linux behavior. The d option, however, is absent.
I've tried to figure out a way to mimic the behavior of "copy links, not targets" with the Mac cp, and as far as I can tell, there's no pleasant way to do it.
There is, fortunately, a gross work around. From man cp under Mac:
Symbolic links are always followed unless the -R flag is set, in which case symbolic links are not followed, by default.
In other words, since we know we're only copying files, you can simply replace the d flag with the R flag. The behavior is technically different (very different), but it won't matter in this specific case. You'll need to find the cp flags used in the Makefile (hopefully in a CP variable at the top of the file) and simply change them.
If you're sure the cp is the last thing to be executed in the Makefile, you could also just copy and paste it instead of changing the Makefile.
I was able to solve this problem using Corbin's suggestion. After searching the Makefile, I was able to spot where the error originated.
I am using flite-2.0.0-release and the Makefile was located in the following directory:
/flite-2.0.0-release/main/.
The last couple lines has the following:
# The libraries: static and shared (if built)
cp -pd $(flite_LIBS_deps) $(INSTALLLIBDIR)
ifdef SHFLAGS
cp -pd $(SHAREDLIBS) $(VERSIONSHAREDLIBS) $(INSTALLLIBDIR)
endif
I've changed the to the following:
# The libraries: static and shared (if built)
cp -pR $(flite_LIBS_deps) $(INSTALLLIBDIR)
ifdef SHFLAGS
cp -pR $(SHAREDLIBS) $(VERSIONSHAREDLIBS) $(INSTALLLIBDIR)
endif
By replacing the cp -pd to cp -pR, I was able to successfully install flite. I hope this advice helps.
I ran into this same issue recently, TJ Rana put me in the right direction but here's the whole process of installing flite on MacOS (original article here):
Flitevox or Flitelib is an open source small run time speech engine. Pass it text and create an audio file with a robot saying it. Really cool and useful for some projects.
Flitelib is not a native filter available in FFmpeg build nor inside the source. Although the documentation states that –enable-libflite is required for config, installing flitelib is required before installing FFmpeg. If you do try to enable the filter you’ll get this error:
$ ./configure --disable-indevs --enable-libflite --enable-cross-compile
ERROR: libflite not found
If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user#ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.
In this post, I’ll show you how to install flite and get it working with FFmpeg
First download flitevox from source and install:
$ git clone https://github.com/festvox/flite.git
$ cd flite/
$ ./configure
$ make
$ sudo make install
If you’re running linux this installation works perfectly. If you’re running MacOS, you’ll get this error:
$ sudo make install
Password:
Installing
mkdir -p /usr/local/bin
mkdir -p /usr/local/lib
mkdir -p /usr/local/include/flite
/usr/bin/install -c -m 644 include/*.h /usr/local/include/flite
/usr/bin/install -c -m 755 ../bin/flite_time /usr/local/bin
cp -pd ../build/x86_64-darwin19.0.0/lib/libflite_cmu_us_kal.a ../build/x86_64-darwin19.0.0/lib/libflite_cmu_time_awb.a ../build/x86_64-darwin19.0.0/lib/libflite_cmu_us_kal16.a ../build/x86_64-darwin19.0.0/lib/libflite_cmu_us_awb.a ../build/x86_64-darwin19.0.0/lib/libflite_cmu_us_rms.a ../build/x86_64-darwin19.0.0/lib/libflite_cmu_us_slt.a ../build/x86_64-darwin19.0.0/lib/libflite_usenglish.a ../build/x86_64-darwin19.0.0/lib/libflite_cmu_indic_lang.a ../build/x86_64-darwin19.0.0/lib/libflite_cmu_grapheme_lang.a ../build/x86_64-darwin19.0.0/lib/libflite_cmulex.a ../build/x86_64-darwin19.0.0/lib/libflite_cmu_indic_lex.a ../build/x86_64-darwin19.0.0/lib/libflite_cmu_grapheme_lex.a ../build/x86_64-darwin19.0.0/lib/libflite.a /usr/local/lib
cp: illegal option -- d
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... target_directory
make[1]: *** [install] Error 64
make: *** [install] Error 2
That’s because MacOS uses different “cp” variables then linux. I found this Stack Overflow answer with the solution: https://stackoverflow.com/a/29075638/525576 but here’s the steps to fix it.
In the folder “flite/main” you’ll need to edit the Makefile with the MacOS version of the command:
$ cd main/
$ vim Makefile
Replace the following (from TJ Rana):
# The libraries: static and shared (if built)
cp -pd $(flite_LIBS_deps) $(INSTALLLIBDIR)
ifdef SHFLAGS
cp -pd $(SHAREDLIBS) $(VERSIONSHAREDLIBS) $(INSTALLLIBDIR)
endif
to (-pd to -pR):
# The libraries: static and shared (if built)
cp -pR $(flite_LIBS_deps) $(INSTALLLIBDIR)
ifdef SHFLAGS
cp -pR $(SHAREDLIBS) $(VERSIONSHAREDLIBS) $(INSTALLLIBDIR)
endif
How we can try installing flite again:
$ sudo make install
flite should not show any errors and the installation should be complete.
Now back in ffmpeg source filter:
$ ./configure --enable-libflite --enable-cross-compile
$ make install
Installation will complete. To test if flite is working open a new terminal and type:
$ ffplay -f lavfi -i flite=text='Hello World!'
Hello world will speak!

Downloading and automatically installing a tgz file

#!/bin/bash
mkdir /tmp
curl -O http://www.mucommander.com/download/nightly/mucommander-current.app.tar.gz /tmp/mucommander.tgz
tar -xvzf /tmp/mucommander.tgz */mucommander.app/*
cp -r /tmp/mucommander.app /Applications
rm -r /tmp
I'm trying to create a shell script to download and extract muCommander to my applications directory on a Mac.
I tried cd into the tmp dir, but then the script stops when I do that.
I can extract all using the -C argument, but the current tgz path is muCommander-0_9_0/mucommander.app, which could change on later builds, so I'm trying to keep it generic.
Can anyone give me pointers where I'm going wrong?
Thanks in advance.
Strip the first path component when you untar the archive, from tar(1):
--strip-components count
(x mode only) Remove the specified number of leading path ele-
ments. Pathnames with fewer elements will be silently skipped.
Note that the pathname is edited after checking inclusion/exclu-
sion patterns but before security checks.
Update
Here is a working bash example of how to, fairly generically, copy the contents of the tgz file to /Applications.
shopt -s nocaseglob
TMPDIR=/tmp
APP=mucommander
TMPAPPDIR=$TMPDIR/$APP
mkdir -p $TMPAPPDIR
curl -o $TMPDIR/$APP.tgz http://www.mucommander.com/download/nightly/mucommander-current.app.tar.gz
tar --strip-components=1 -xvzf $APP.tgz -C $TMPAPPDIR
mv $TMPAPPDIR/${APP}* /Applications
# rm -rf $TMPAPPDIR $TMPDIR/$APP
The rm command is commented out for now, verify that it does no harm before you use it.
The following will update your muCommander.
#for the safety, remove old temporary extraction from the /tmp
rm -rf /tmp/muCommander.app
#kill the running mucommander - you dont want replace the runnung app
ps -ef | grep ' /Applications/muCommander.app/' | grep -v grep | awk '{print $2}' | xargs kill
#download, extract, remove old, move new, open
#each command run only when the previous ended with success
curl http://www.mucommander.com/download/nightly/mucommander-current.app.tar.gz |\
tar -xzf - -C /tmp --strip-components=1 '*/muCommander.app' && \
rm -rf /Applications/muCommander.app && \
mv /tmp/muCommander.app /Applications && \
open /Applications/muCommander.app
Beware, after the '\' must following new line, and not any spaces...

How to unpack and pack pkg file?

I have a pkg file created by Install Maker for Mac.
I want to replace one file in pkg. But I must do this under Linux system, because this is a part of download process. When user starts to download file server must replace one file in pkg.
I have a solution how unpack pkg and replace a file but I dont know how pack again to pkg.
http://emresaglam.com/blog/1035
http://ilostmynotes.blogspot.com/2012/06/mac-os-x-pkg-bom-files-package.html
Packages are just .xar archives with a different extension and a specified file hierarchy. Unfortunately, part of that file hierarchy is a cpio.gz archive of the actual installables, and usually that's what you want to edit. And there's also a Bom file that includes information on the files inside that cpio archive, and a PackageInfo file that includes summary information.
If you really do just need to edit one of the info files, that's simple:
mkdir Foo
cd Foo
xar -xf ../Foo.pkg
# edit stuff
xar -cf ../Foo-new.pkg *
But if you need to edit the installable files:
mkdir Foo
cd Foo
xar -xf ../Foo.pkg
cd foo.pkg
cat Payload | gunzip -dc |cpio -i
# edit Foo.app/*
rm Payload
find ./Foo.app | cpio -o | gzip -c > Payload
mkbom Foo.app Bom # or edit Bom
# edit PackageInfo
rm -rf Foo.app
cd ..
xar -cf ../Foo-new.pkg
I believe you can get mkbom (and lsbom) for most linux distros. (If you can get ditto, that makes things even easier, but I'm not sure if that's nearly as ubiquitously available.)
Here is a bash script inspired by abarnert's answer which will unpack a package named MyPackage.pkg into a subfolder named MyPackage_pkg and then open the folder in Finder.
#!/usr/bin/env bash
filename="$*"
dirname="${filename/\./_}"
pkgutil --expand "$filename" "$dirname"
cd "$dirname"
tar xvf Payload
open .
Usage:
pkg-upack.sh MyPackage.pkg
Warning: This will not work in all cases, and will fail with certain files, e.g. the PKGs inside the OSX system installer. If you want to peek inside the pkg file and see what's inside, you can try SuspiciousPackage (free app), and if you need more options such as selectively unpacking specific files, then have a look at Pacifist (nagware).
You might want to look into my fork of pbzx here: https://github.com/NiklasRosenstein/pbzx
It allows you to stream pbzx files that are not wrapped in a XAR archive. I've experienced this with recent XCode Command-Line Tools Disk Images (eg. 10.12 XCode 8).
pbzx -n Payload | cpio -i
In addition to what #abarnert said, I today had to find out that the default cpio utility on Mountain Lion uses a different archive format per default (not sure which), even with the man page stating it would use the old cpio/odc format. So, if anyone stumbles upon the cpio read error: bad file format message while trying to install his/her manipulated packages, be sure to include the format in the re-pack step:
find ./Foo.app | cpio -o --format odc | gzip -c > Payload
#shrx I've succeeded to unpack the BSD.pkg (part of the Yosemite installer) by using "pbzx" command.
pbzx <pkg> | cpio -idmu
The "pbzx" command can be downloaded from the following link:
pbzx Stream Parser
If you are experiencing errors during PKG installation following the accepted answer, I will give you another procedure that worked for me (please note the little changes to xar, cpio and mkbom commands):
mkdir Foo
cd Foo
xar -xf ../Foo.pkg
cd foo.pkg
cat Payload | gunzip -dc | cpio -i
# edit Foo.app/*
rm Payload
find ./Foo.app | cpio -o --format odc --owner 0:80 | gzip -c > Payload
mkbom -u 0 -g 80 Foo.app Bom # or edit Bom
# edit PackageInfo
rm -rf Foo.app
cd ..
xar --compression none -cf ../Foo-new.pkg
The resulted PKG will have no compression, cpio now uses odc format and specify the owner of the file as well as mkbom.
Bash script to extract pkg: (Inspired by this answer:https://stackoverflow.com/a/23950738/16923394)
Save the following code to a file named pkg-upack.sh on the $HOME/Downloads folder
#!/usr/bin/env bash
filename="$*"
dirname="${filename/\./_}"
mkdir "$dirname"
# pkgutil --expand "$filename" "$dirname"
xar -xf "$filename" -C "$dirname"
cd "$dirname"/*.pkg
pwd
# tar xvf Payload
cat Payload | gunzip -dc |cpio -i
# cd usr/local/bin
# pwd
# ls -lt
# cp -i * $HOME/Downloads/
Uncomment the last four lines, if you are using a rudix package.
Usage:
cd $HOME/Downloads
chmod +x ./pkg-upack.sh
./pkg-upack.sh MyPackage.pkg
This was tested with the ffmpeg and mawk package from rudix.org (https://rudix.org) search for ffmpeg and mawk packages on this site.
Source : My open source projects : https://sourceforge.net/u/nathan-sr/profile/

cp --parents option on mac

On Linux, I have a --parents option available for the cp command so I can do
cp --parents test/withintest/go.rb test2
http://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html
On Mac, I do not have this option available. Is there a way to do this on Mac? Why is this option not available?
PS. The purpose of --parents is the following:
‘--parents’ Form the name of each destination file by appending to the
target directory a slash and the specified name of the source file.
The last argument given to cp must be the name of an existing
directory.
For example, the command:
cp --parents a/b/c existing_dir
copies the file a/b/c to existing_dir/a/b/c, creating any missing intermediate directories.
This bothered me quite a lot as well.
A workaround for this could be to use rsync.
rsync -R test/withintest/go.rb test2
has the same effect as cp --parents and OS X comes standard with rsync.
You can use the ditto command on Mac OS X:
The basic form
ditto <src-path> <dst-path>
does what you want. There's a lot more options too - check out the man page.
You can install the GNU version of cp using MacPorts.
After MacPorts is installed you can install the coreutils packages:
sudo port install coreutils
Then you will be able to use the GNU version cp and other core utilitites (ls, date, cat, etc.) by prefixing the command with a g:
gcp --parents test/withintest/go.rb test2
If you want these GNU versions to be used by default you can add the GNU bin update your path. Add the following to your ~/.bash_profile:
export PATH="/opt/local/libexec/gnubin:$PATH"
The Homebrew way:
Install coreutils
brew install coreutils
Use the GNU g- prefixed command
gcp --parents test/withintest/go.rb test2
I used rsync and what I did was:
rsync -R dir/**/file.json destination
Try
mkdir -p `dirname "$file_path"` && cp "$old_dir/$file_path" "$file_path"
This first creates the directory with all itermediates in the relative file path. Then it copies the file to the newly created directory.
I would not replace mac cp with GNU cp. I would also not used ditto because it is not cross-platform. Instead use cross-platform tools, such as rsync:
rsync <srcDir/srcFile> <dst>
Result: dst/srcDir/srcFile

Bash copy verbose update in Solaris

I'm writing some small bash scripts for copiyng certain files/directories in GNU/Linux and Solaris. Everything is OK in Linux, but cp command hasn't the same options in Linux and Solaris.
Copy command is something like this:
cp -ruv $source $dest
Unfortunately I don't know how to achieve copy verbose and copy update in Solaris. Any idea?
Thanks
Unfortunately, cp under Solaris doesn't have that option. man solaris should reveal that.
Are you comfortable making your script depend on rsync?
Or, if possible, you can install the coreutils package and use GNU's cp.
I ran into a similar issue myself and found that gcp takes care of it too. I've made installing coreutils part of my standard system setup.
I run these on a new Solaris install:
pkgadd -d http://get.opencsw.org/now
pkgutil -U
pkgutil -i -y coreutils
pkgutil -a vim
pkgutil -i -y vim
pkgutil -i -y findutils
Remember to add the path - and the documentation path - to your profile, and possibly to the system profile at /etc/profile:
# Set the program path
PATH=$PATH:/usr/sfw/bin:/usr/sfw/sbin:/usr/openwin/bin:/opt/csw/bin:/usr/ccs/bin:/usr/local/bin:/usr/local
export PATH
# Set the documentation path
MANPATH="$MANPATH:/usr/share/man:/opt/sfw/man:/opt/csw/man"
export MANPATH
It sounds like you might be new to Solaris - as I am relatively new. I also do these, which shouldn't affect anything.
I set VIM as the default editor instead of VI - it's compatible, but has more features, including ANSI color, and some terminal emulators will pass your mouse clicks and scrolling through for even more flexibility:
# Set the default editor
EDITOR=vim
export EDITOR
Then if you are still using the default prompt that doesn't say anything, you might want to add some information - this version requires a Bash shell:
# Set the command prompt, which includes the username, host name, and the current path.
PS1='\u#\h:\w>'
export PS1
To recreate verbose mode, you can tee the output to the controlling terminal (/dev/tty) while the stdoout output of tee itself is passed to cp via xargs.
find /some/source/directory -type f | \
tee /dev/tty | xargs -I {} cp {} /copy/to/this-directory/
Replace the find with whatever you like, so long as it passes the paths to the files to be copied through the pipe to tee.
Tested on a standard Solaris 10 system without extra GNU utils.

Resources