Creating .dmg images from the shell

iceman22

macrumors newbie
Original poster
Dec 24, 2004
11
2
I have written a PHP script I run using cron, which takes arguments as files or directories to back up to an FTP server.

The script takes the args and executes the shell command hdiutil to make a compressed, encrypted image.

It works great, except that I currently get this error:

hdiutil: WARNING: -passphrase has been deprecated in favor of -stdinpass

When using this shell command within the script:

hdiutil create -srcfolder $source -encryption -passphrase $password -fs HFS+ -volname $vol_name $img_name

I haven't been able to enter a password using stdin either from the shell, is it even possible to use -stdinpass in a CGI?
 

Bear

macrumors G3
Jul 23, 2002
8,089
4
Sol III - Terra
iceman22 said:
...
I haven't been able to enter a password using stdin either from the shell, is it even possible to use -stdinpass in a CGI?
From a Terminal window, you need a null character (^@) at the end of your passphrase and on the next line a control-D (^d). Without the null, it doesn't work.

As for using it within a cgi, yes it can be done, you would need to write the null terminated password to a file (no control-D should be needed as all that does is indicate end of file) and run hdiutil redirecting stdin to be from the file.
 

iceman22

macrumors newbie
Original poster
Dec 24, 2004
11
2
Would you mind providing an example of how it could be done in a CGI?

I have tried entering a passphrase followed by a '^@' and was unsuccessful in the terminal. I just tried again and the passphrases didn't match, even when I was copying exactly what I had typed into the shell window that was still open, excluding the NULL char of course.
 

iceman22

macrumors newbie
Original poster
Dec 24, 2004
11
2
I successfully created an image from the shell, using (^@), rather than literally typing caret-@, which did not work.

I can't do ctrl-@ in a text file or in the script, only caret-@, I have tried using "password^@","password\0","password" and a few others.

In the script, this is what I have tried using:
`cat /password.txt | hdiutil create -srcfolder $source -encryption -stdinpass -fs HFS+ -volname $vol_name $img_name`
`echo "$password^@" | hdiutil create -srcfolder $source -encryption -stdinpass -fs HFS+ -volname $vol_name $img_name`
 

iceman22

macrumors newbie
Original poster
Dec 24, 2004
11
2
I got it work, there is no need for a NULL terminating character or using an external file. The fact that echo was adding a \n by default is what was killing me.

This works fine:
`echo -n $password | hdiutil create -srcfolder $source -encryption -stdinpass -fs HFS+ -volname $vol_name $img_name`;
 

anurag1005

macrumors newbie
Aug 11, 2010
1
0
Issue while creating dmg with shell script

Hi,

I am using same command in shell script to create a dmg file but after creation I am not able to open the dmg with same password. If I am creating the dmg from command line it works fine.

echo -n abcd1234|hdiutil create -srcfolder my_folder -encryption -stdinpass -debug my_folder.dmg
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.