make_dmg.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/bin/bash
  2. # Assembles an installation bundle from a built copy of Slic3r.
  3. # Requires PAR::Packer to be installed for the version of
  4. # perl copied.
  5. # Adapted from script written by bubnikv for Prusa3D.
  6. # Run from slic3r repo root directory.
  7. SLIC3R_VERSION=$(grep "VERSION" xs/src/libslic3r/libslic3r.h | awk -F\" '{print $2}')
  8. if [ "$#" -ne 1 ]; then
  9. echo "Usage: $(basename $0) dmg_name"
  10. exit 1;
  11. fi
  12. WD=$(dirname $0)
  13. # Determine if this is a tagged (release) commit.
  14. # Change the build id accordingly.
  15. if [ $(git describe &>/dev/null) ]; then
  16. TAGGED=true
  17. SLIC3R_BUILD_ID=$(git describe)
  18. else
  19. TAGGED=false
  20. SLIC3R_BUILD_ID=${SLIC3R_VERSION}
  21. fi
  22. if [ -z ${GIT_BRANCH+x} ] && [ -z ${APPVEYOR_REPO_BRANCH+x} ]; then
  23. current_branch=$(git symbolic-ref HEAD | sed 's!refs\/heads\/!!')
  24. else
  25. current_branch="unknown"
  26. if [ ! -z ${GIT_BRANCH+x} ]; then
  27. echo "Setting to GIT_BRANCH"
  28. current_branch=$(echo $GIT_BRANCH | cut -d / -f 2)
  29. fi
  30. if [ ! -z ${APPVEYOR_REPO_BRANCH+x} ]; then
  31. echo "Setting to APPVEYOR_REPO_BRANCH"
  32. current_branch=$APPVEYOR_REPO_BRANCH
  33. fi
  34. fi
  35. # If we're on a branch, add the branch name to the app name.
  36. if [ "$current_branch" == "master" ]; then
  37. appname=Slic3r
  38. dmgfile=slic3r-${SLIC3R_BUILD_ID}-${1}.dmg
  39. else
  40. appname=Slic3r-$(git symbolic-ref HEAD | sed 's!refs\/heads\/!!')
  41. dmgfile=slic3r-${SLIC3R_BUILD_ID}-${1}-$(git symbolic-ref HEAD | sed 's!refs\/heads\/!!').dmg
  42. fi
  43. rm -rf $WD/_tmp
  44. mkdir -p $WD/_tmp
  45. # OSX Application folder shenanigans.
  46. appfolder="$WD/${appname}.app"
  47. macosfolder=$appfolder/Contents/MacOS
  48. resourcefolder=$appfolder/Contents/Resources
  49. plistfile=$appfolder/Contents/Info.plist
  50. PkgInfoContents="APPL????"
  51. source $WD/plist.sh
  52. # Our slic3r dir and location of perl
  53. PERL_BIN=$(which perl)
  54. PP_BIN=$(which pp)
  55. SLIC3R_DIR=$(perl -MCwd=realpath -e "print realpath '${WD}/../../'")
  56. if [[ -d "${appfolder}" ]]; then
  57. echo "Deleting old working folder: ${appfolder}"
  58. rm -rf ${appfolder}
  59. fi
  60. if [[ -e "${dmgfile}" ]]; then
  61. echo "Deleting old dmg: ${dmgfile}"
  62. rm -rf ${dmgfile}
  63. fi
  64. echo "Creating new app folder: $appfolder"
  65. mkdir -p $appfolder
  66. mkdir -p $macosfolder
  67. mkdir -p $resourcefolder
  68. echo "Copying resources..."
  69. cp -rf $SLIC3R_DIR/var $resourcefolder/
  70. mv $resourcefolder/var/Slic3r.icns $resourcefolder
  71. mv $resourcefolder/var/stl.icns $resourcefolder
  72. mv $resourcefolder/var/gcode.icns $resourcefolder
  73. echo "Copying Slic3r..."
  74. cp $SLIC3R_DIR/slic3r.pl $macosfolder/slic3r.pl
  75. cp -fRP $SLIC3R_DIR/local-lib $macosfolder/local-lib
  76. cp -fRP $SLIC3R_DIR/lib/* $macosfolder/local-lib/lib/perl5/
  77. echo "Relocating dylib paths..."
  78. for bundle in $(find $macosfolder/local-lib/lib/perl5/darwin-thread-multi-2level/auto/Wx -name '*.bundle') $(find $macosfolder/local-lib/lib/perl5/darwin-thread-multi-2level/Alien/wxWidgets -name '*.dylib' -type f); do
  79. chmod +w $bundle
  80. for dylib in $(otool -l $bundle | grep .dylib | grep local-lib | awk '{print $2}'); do
  81. install_name_tool -change "$dylib" "@executable_path/local-lib/lib/perl5/darwin-thread-multi-2level/Alien/wxWidgets/osx_cocoa_3_0_2_uni/lib/$(basename $dylib)" $bundle
  82. done
  83. done
  84. echo "Copying startup script..."
  85. cp -f $WD/startup_script.sh $macosfolder/$appname
  86. chmod +x $macosfolder/$appname
  87. echo "Copying perl from $PERL_BIN"
  88. # Edit package/common/coreperl to add/remove core Perl modules added to this package, one per line.
  89. cp -f $PERL_BIN $macosfolder/perl-local
  90. ${PP_BIN} \
  91. -M $(grep -v "^#" ${WD}/../common/coreperl | xargs | awk 'BEGIN { OFS=" -M "}; {$1=$1; print $0}') \
  92. -B -p -e "print 123" -o $WD/_tmp/test.par
  93. unzip -o $WD/_tmp/test.par -d $WD/_tmp/
  94. cp -rf $WD/_tmp/lib/* $macosfolder/local-lib/lib/perl5/
  95. rm -rf $WD/_tmp
  96. echo "Cleaning bundle"
  97. rm -rf $macosfolder/local-lib/bin
  98. rm -rf $macosfolder/local-lib/man
  99. rm -f $macosfolder/local-lib/lib/perl5/Algorithm/*.pl
  100. rm -rf $macosfolder/local-lib/lib/perl5/unicore
  101. rm -rf $macosfolder/local-lib/lib/perl5/App
  102. rm -rf $macosfolder/local-lib/lib/perl5/Devel/CheckLib.pm
  103. rm -rf $macosfolder/local-lib/lib/perl5/ExtUtils
  104. rm -rf $macosfolder/local-lib/lib/perl5/Module/Build*
  105. rm -rf $macosfolder/local-lib/lib/perl5/TAP
  106. rm -rf $macosfolder/local-lib/lib/perl5/Test*
  107. find -d $macosfolder/local-lib -name '*.pod' -delete
  108. find -d $macosfolder/local-lib -name .packlist -delete
  109. find -d $macosfolder/local-lib -name .meta -exec rm -rf "{}" \;
  110. find -d $macosfolder/local-lib -name '*.h' -delete
  111. find -d $macosfolder/local-lib -name wxPerl.app -exec rm -rf "{}" \;
  112. find -d $macosfolder/local-lib -type d -path '*/Wx/*' \( -name WebView \
  113. -or -name DocView -or -name STC -or -name IPC \
  114. -or -name Calendar -or -name DataView \
  115. -or -name DateTime -or -name Media -or -name PerlTest \
  116. -or -name Ribbon \) -exec rm -rf "{}" \;
  117. find -d $macosfolder/local-lib -name libwx_osx_cocoau_ribbon-3.0.0.2.0.dylib -delete
  118. find -d $macosfolder/local-lib -name libwx_osx_cocoau_stc-3.0.0.2.0.dylib -delete
  119. find -d $macosfolder/local-lib -name libwx_osx_cocoau_webview-3.0.0.2.0.dylib -delete
  120. rm -rf $macosfolder/local-lib/lib/perl5/darwin-thread-multi-2level/Alien/wxWidgets/osx_cocoa_3_0_2_uni/include
  121. find -d $macosfolder/local-lib -type d -empty -delete
  122. make_plist
  123. echo $PkgInfoContents >$appfolder/Contents/PkgInfo
  124. if [[ -e "${KEYCHAIN_FILE}" ]]; then
  125. echo "Signing app..."
  126. chmod -R +w $macosfolder/*
  127. security list-keychains -s "${KEYCHAIN_FILE}"
  128. security default-keychain -s "${KEYCHAIN_FILE}"
  129. security unlock-keychain -p "${KEYCHAIN_PASSWORD}" "${KEYCHAIN_FILE}"
  130. codesign --sign "${KEYCHAIN_IDENTITY}" --deep "$appfolder"
  131. fi
  132. echo "Creating dmg file...."
  133. hdiutil create -fs HFS+ -srcfolder "$appfolder" -volname "$appname" "$dmgfile"