File indexing completed on 2024-05-05 04:57:36

0001 #!/bin/bash
0002 
0003 TMP=/tmp
0004 BUNDLE_PATH=bin
0005 test -d bin || BUNDLE_PATH=../bin
0006 
0007 WORK_TEMPLATE=tmp-Falkon-release.dmg.sparseimage
0008 
0009 # NOTE: Value must currently match -volname exactly or an error happens in AppleScript with Finder
0010 VOLUME_TEMPLATE=Falkon
0011 
0012 echo "Ensuring working disk image template is not in use…"
0013 hdiutil detach "$TMP/$WORK_TEMPLATE"
0014 
0015 echo "Creating writable working disk image template…"
0016 hdiutil create -size 200m "$TMP/$WORK_TEMPLATE" -type SPARSE -fs HFS+ -volname "Falkon"
0017 
0018   echo "Attaching working disk image template for modification…"
0019   hdiutil attach "$TMP/$WORK_TEMPLATE" -mountpoint "$TMP/$VOLUME_TEMPLATE"
0020 
0021     echo "Creating background image folder…"
0022     mkdir "$TMP/$VOLUME_TEMPLATE/.background"
0023 
0024     echo "Copying background image…"
0025     cp dmg-background.png "$TMP/$VOLUME_TEMPLATE/.background/"
0026 
0027     echo "Creating volume icon set…"
0028     ICON=dmg-icon
0029     ICONEXT=png
0030     ICONSETDIR=$ICON.iconset
0031 
0032     mkdir -p "$ICONSETDIR"
0033 
0034     # Convert last with qlmanage since sips does not do SVG
0035     qlmanage -t -s 1024 -o "$ICONSETDIR" "$ICON.$ICONEXT"
0036     mv "$ICONSETDIR/$ICON.$ICONEXT.png" "$ICONSETDIR/icon_512x512@2x.png"
0037 
0038     # Convert remaining with sips since qlmanage does not do 16 pixels
0039     sizes=( 512 256 128 64 32 16 )
0040     for size in ${sizes[@]}
0041     do
0042       sips -Z $size -s format png "$ICONSETDIR/icon_512x512@2x.png" --out "$ICONSETDIR/icon_${size}x${size}.png"
0043 
0044       halfsize=$((size / 2))
0045       if [[ size -ne 16 ]]; then
0046         ln "$ICONSETDIR/icon_${size}x${size}.png" "$ICONSETDIR/icon_${halfsize}x${halfsize}@2x.png"
0047       fi
0048     done
0049 
0050     echo "Creating application reference folder…"
0051     mkdir "$TMP/$VOLUME_TEMPLATE/Falkon.app"
0052 
0053     echo "Creating symbolic link to global Applications folder…"
0054     ln -s /Applications "$TMP/$VOLUME_TEMPLATE/Applications"
0055 
0056     echo "Setting some proprietary window modifications here with AppleScript…"
0057     osascript create_dmg.scpt
0058 
0059     sleep 5
0060 
0061     echo "Registering that a custom icon is being set…"
0062     # iconutil will only pick what it needs
0063     iconutil -c icns "$ICONSETDIR" -o "$TMP/$VOLUME_TEMPLATE/.VolumeIcon.icns"
0064     SetFile -a C "$TMP/$VOLUME_TEMPLATE"
0065 
0066     echo "Copying application bundle contents…"
0067     cp -fpR "$BUNDLE_PATH/Falkon.app/Contents" "$TMP/$VOLUME_TEMPLATE/Falkon.app"
0068 
0069     echo "Blessing folder to automatically open on mount…"
0070     bless --folder "$TMP/$VOLUME_TEMPLATE" --openfolder "$TMP/$VOLUME_TEMPLATE"
0071 
0072   echo "Detaching working disk image template from write…"
0073   hdiutil detach "$TMP/$VOLUME_TEMPLATE"
0074 
0075 echo "Compacting working disk image…"
0076 hdiutil compact "$TMP/$WORK_TEMPLATE"
0077 
0078 echo "Converting working disk image to read only…"
0079 rm "$BUNDLE_PATH/Falkon.dmg"
0080 hdiutil convert "$TMP/$WORK_TEMPLATE" -format UDBZ -o "$BUNDLE_PATH/Falkon.dmg"
0081 
0082 echo  "Cleaning up"
0083 rm -Rf "$ICONSETDIR"
0084 rm "$TMP/$WORK_TEMPLATE"