Creating .dmg images from the shell

Discussion in 'macOS' started by iceman22, Apr 3, 2005.

  1. iceman22 macrumors newbie

    Dec 24, 2004
    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?
  2. Bear macrumors G3

    Jul 23, 2002
    Sol III - Terra
    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.
  3. iceman22 thread starter macrumors newbie

    Dec 24, 2004
    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.
  4. iceman22 thread starter macrumors newbie

    Dec 24, 2004
    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`
  5. iceman22 thread starter macrumors newbie

    Dec 24, 2004
    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`;
  6. anurag1005 macrumors newbie

    Aug 11, 2010
    Issue while creating dmg with shell script


    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

Share This Page