File indexing completed on 2024-05-12 16:02:32

0001 #!/usr/bin/env sh
0002 #
0003 #  SPDX-License-Identifier: GPL-3.0-or-later
0004 #
0005 
0006 # get krita disk mounted image current properties
0007 # creates a dummy folder to aid in setting the layout for
0008 # the dmg image file.
0009 
0010 set_dmgfolder_props() {
0011     cp ${DMG_background} "${DMG_STYLE_DIR}/.background"
0012     BG_FILENAME=${DMG_background##*/}
0013     printf '
0014     tell application "Finder"
0015         tell folder "%s" of %s
0016             open
0017             set current view of container window to icon view
0018             set toolbar visible of container window to false
0019             set statusbar visible of container window to false
0020             set the bounds of container window to {186, 156, 956, 592}
0021             set theViewOptions to the icon view options of container window
0022             set arrangement of theViewOptions to not arranged
0023             set icon size of theViewOptions to 80
0024             set background picture of theViewOptions to file ".background:%s"
0025             set position of item "krita.app" of container window to {279, 272}
0026             set position of item "Applications" of container window to {597, 272}
0027             set position of item "Terms of Use" of container window to {597, 110}
0028             update without registering applications
0029             close
0030         end tell
0031     end tell
0032     ' "${DMG_STYLE_DIR_OSA}" "${DMG_STYLE_LOCATION}" "${BG_FILENAME}" | osascript
0033 
0034     get_dmgfolder_props > /dev/null
0035 }
0036 
0037 get_dmgfolder_props() {
0038     printf '
0039         tell application "Finder"
0040             tell folder "%s" of %s
0041                 open
0042                 set v_cv to current view of container window
0043                 log v_cv
0044                 set v_tb to toolbar visible of container window
0045                 log v_tb
0046                 set v_stat to statusbar visible of container window
0047                 log v_stat
0048                 set v_bounds to the bounds of container window
0049                 log v_bounds
0050                 set theViewOptions to the icon view options of container window
0051                 set v_arr to arrangement of theViewOptions
0052                 log v_arr
0053                 set v_icons to icon size of theViewOptions
0054                 log v_icons
0055                 set v_pos_k to position of item "krita.app" of container window
0056                 log v_pos_k
0057                 set v_pos_ap to position of item "Applications" of container window
0058                 log v_pos_ap
0059                 set v_pos_term to position of item "Terms of Use" of container window
0060                 log v_pos_term
0061                 update without registering applications
0062             end tell
0063         end tell
0064         ' "${DMG_STYLE_DIR_OSA}" "${DMG_STYLE_LOCATION}" | osascript 2>&1 | awk '{printf "%s\n" ,$0}'
0065 }
0066 
0067 # Print Suitable command to paste on osxdeploy.sh
0068 print_osascript_cmd() {
0069     OLD_IFS=${IFS}
0070     IFS=$'\n'
0071     dmg_ops=($@)
0072     printf 'tell application "Finder"
0073     tell disk "%%s"
0074         open
0075         set current view of container window to %s
0076         set toolbar visible of container window to %s
0077         set statusbar visible of container window to %s
0078         set the bounds of container window to {%s}
0079         set theViewOptions to the icon view options of container window
0080         set arrangement of theViewOptions to %s
0081         set icon size of theViewOptions to %s
0082         set background picture of theViewOptions to file ".background:%%s"
0083         set position of item "krita.app" of container window to {%s}
0084         set position of item "Applications" of container window to {%s}
0085         set position of item "Terms of Use" of container window to {%s}
0086         update without registering applications
0087         delay 1
0088         close
0089     end tell
0090 end tell
0091 ' "${dmg_ops[@]}"
0092     IFS=${OLD_IFS}
0093 }
0094 
0095 print_help() {
0096     printf \
0097 "dmgstyle.sh is a minitool to aid in the creation of the DMG look for krita
0098 out is designed to be copy pasted into osxdeploy.sh in the osasrcipt section
0099 
0100 - Run once with set to set new background
0101 - Edit by moving elements or <Cmd> + J to set net icon size
0102 - To get current options for osxdeploy: rerun with no arguments.
0103 
0104 USAGE: dmgstyle.sh [option] <args>
0105 Options:
0106 <empty>     No option fetches dummy design window state for paste in osxdeploy
0107 set         set default values changing the background to image in <args>
0108 "
0109 }
0110 
0111 if test -z ${BUILDROOT}; then
0112     echo "ERROR: BUILDROOT env not set!"
0113     echo "\t Must point to the root of the buildfiles as stated in 3rdparty Readme"
0114     print_help
0115     exit 1
0116 fi
0117 
0118 BUILDROOT=$(cd "$(dirname "${BUILDROOT}")"; pwd -P)/$(basename "${BUILDROOT}") # force full path
0119 
0120 # if in home we get path minus $HOME
0121 # if in Mounted disk we get path minus "/Volumes/diskname"
0122 if [[ -n "$(grep /Users/$(whoami) <<< ${BUILDROOT})" ]];then
0123     # buildroot is in home
0124     build_folder=${BUILDROOT#${HOME}/} # removes home
0125     dmg_vol_name="home"
0126 else
0127     tmp_folder=${BUILDROOT#/Volumes/}
0128     build_folder=${tmp_folder#*/} # get minus all
0129     printf -v dmg_vol_name 'disk "%s"' ${tmp_folder%%/*} # get volume name
0130 fi
0131 
0132 
0133 # Setting global variables
0134 DMG_DUMMY_NAME="dmg_style_dummy"
0135 DMG_STYLE_DIR="${BUILDROOT}/${DMG_DUMMY_NAME}"
0136 DMG_STYLE_DIR_OSA=$(printf "%s/%s" ${build_folder} ${DMG_DUMMY_NAME} | tr / :)
0137 DMG_STYLE_LOCATION=${dmg_vol_name}
0138 KIS_INSTALL_DIR="${BUILDROOT}/i"
0139 
0140 
0141 if [[ ${1} = "-h" || ${1} = "--help" ]]; then
0142     print_help
0143     exit 1
0144 fi
0145 
0146 if [[ ${1} = "set" ]]; then
0147     # Create style container folder it if doesn't exist
0148     if [[ ! -e ${DMG_STYLE_DIR} ]]; then
0149         mkdir "${DMG_STYLE_DIR}"
0150         mkdir "${DMG_STYLE_DIR}/Terms of Use"
0151         mkdir "${DMG_STYLE_DIR}/.background"
0152         ln -s "/Applications" "${DMG_STYLE_DIR}/Applications"
0153         ln -s "${KIS_INSTALL_DIR}/bin/krita.app" "${DMG_STYLE_DIR}/krita.app"
0154     fi
0155 
0156     ## check background validity
0157     if [[ -f ${2} ]]; then
0158         DMG_validBG=0
0159         echo "attempting to check background is valid jpg or png..."
0160         BG_FORMAT=$(sips --getProperty format ${2} | awk '{printf $2}')
0161 
0162         if [[ "png" = ${BG_FORMAT} || "jpeg" = ${BG_FORMAT} ]];then
0163             echo "valid image file"
0164             DMG_background=$(cd "$(dirname "${2}")"; pwd -P)/$(basename "${2}")
0165             DMG_validBG=1
0166         fi
0167     fi
0168 
0169     if [[ ${DMG_validBG} -eq 0 ]]; then
0170         echo "No jpg or png given or valid file detected!!"
0171         exit 1
0172     else
0173         BG_DPI=$(sips --getProperty dpiWidth ${DMG_background} | grep dpi | awk '{print $2}')
0174         if [[ $(echo "${BG_DPI} > 150" | bc -l) -eq 1 ]]; then
0175         printf "WARNING: image dpi has an effect on apparent size!
0176 Check dpi is adequate for screen display if image appears very small
0177 Current dpi is: %s\n" ${BG_DPI}
0178         fi
0179         set_dmgfolder_props
0180     fi
0181 
0182 else
0183     if [[ ! -e ${DMG_STYLE_DIR} ]]; then
0184         echo "First run must use option [set]!!"
0185         exit 1
0186     fi
0187     osa_values=$(get_dmgfolder_props)
0188     print_osascript_cmd "${osa_values}"
0189 fi