|
| 1 | +#!/bin/bash |
| 2 | +############################################################################### |
| 3 | +# |
| 4 | +# build_app.sh: build app bundle for installing Medley Interlisp on MacOS |
| 5 | +# |
| 6 | +# 2023-02-23 Frank Halasz |
| 7 | +# |
| 8 | +# Copyright 2023 by Interlisp.org |
| 9 | +# |
| 10 | +############################################################################### |
| 11 | + |
| 12 | +APPNAME=Medley |
| 13 | + |
| 14 | +# 2023-07-19 Temorary selector to allow us to create .zip asset before app/dmg work is finished |
| 15 | +INCLUDE_APP="no" # "yes" or "no" |
| 16 | + |
| 17 | +# Make sure we are in the right directory |
| 18 | +if [ ! -f ./app/Info.plist ]; |
| 19 | +then |
| 20 | +echo "Can't find ./app/Info.plist file." |
| 21 | +echo "Incorrect cwd?" |
| 22 | +echo "Should be in medley/installers/macos" |
| 23 | +echo "Exiting" |
| 24 | +exit 1 |
| 25 | +fi |
| 26 | + |
| 27 | +# template for artifacts file names should be passed down in the ENV variable: ARTIFACTS_FILENAME_TEMPLATE |
| 28 | +if [ -z "${ARTIFACTS_FILENAME_TEMPLATE}" ]; |
| 29 | +then |
| 30 | + ARTIFACTS_FILENAME_TEMPLATE="medley-full-@@PLATFORM@@-@@ARCH@@-@@MEDLEY.RELEASE@@_@@MAIKO.RELEASE@@" |
| 31 | +fi |
| 32 | + |
| 33 | +# |
| 34 | +# Setup directories |
| 35 | +# |
| 36 | +CWD=$(pwd) |
| 37 | +RESULTS_DIR=${CWD}/artifacts |
| 38 | +APPBUNDLE=${RESULTS_DIR}/${APPNAME}.app |
| 39 | +APPBUNDLECONTENTS=${APPBUNDLE}/Contents |
| 40 | +APPBUNDLEEXE=${APPBUNDLECONTENTS}/MacOS |
| 41 | +APPBUNDLERESOURCES=${APPBUNDLECONTENTS}/Resources |
| 42 | +APPBUNDLEICON=${APPBUNDLECONTENTS}/Resources |
| 43 | +tmp_dir=${CWD}/tmp |
| 44 | +tarball_dir=${tmp_dir}/tarballs |
| 45 | + |
| 46 | +# If running as a github action or -t arg, then skip downloading the tarballs |
| 47 | +if ! [[ -n "${GITHUB_WORKSPACE}" || "$1" = "-t" ]]; |
| 48 | +then |
| 49 | + # First, make sure gh is available and we are logged in to github |
| 50 | + if [ -z "$(which gh)" ]; |
| 51 | + then |
| 52 | + echo "Can't find gh" |
| 53 | + echo "Exiting." |
| 54 | + exit 2 |
| 55 | + fi |
| 56 | + gh auth status 2>&1 | grep --quiet --no-messages "Logged in to github.com" |
| 57 | + if [ $? -ne 0 ]; |
| 58 | + then |
| 59 | + echo "Not logged into github." |
| 60 | + echo "Exiting." |
| 61 | + exit 3 |
| 62 | + fi |
| 63 | + # then clear out the ./tmp directory |
| 64 | + rm -rf ${tmp_dir} |
| 65 | + mkdir -p ${tmp_dir} |
| 66 | + # then download the maiko and medley tarballs |
| 67 | + mkdir -p ${tarball_dir} |
| 68 | + echo "Fetching maiko and medley release tarballs" |
| 69 | + TAG=$(gh release list --repo interlisp/maiko | head -n 1 | awk "{print \$1 }") |
| 70 | + gh release download ${TAG} \ |
| 71 | + --repo interlisp/maiko \ |
| 72 | + --dir ${tarball_dir} \ |
| 73 | + --pattern "*darwin*.tgz" |
| 74 | + TAG=$(gh release list --repo interlisp/medley | head -n 1 | awk "{print \$1 }") |
| 75 | + gh release download ${TAG} \ |
| 76 | + --repo interlisp/medley \ |
| 77 | + --dir ${tarball_dir} \ |
| 78 | + --pattern "*-loadups.tgz" \ |
| 79 | + --pattern "*-runtime.tgz" |
| 80 | + gh repo clone interlisp/notecards notecards -- --depth 1 |
| 81 | + (cd notecards; git archive --format=tgz --output=../notecards.tgz --prefix=notecards/ main) |
| 82 | + mv notecards.tgz ${tarball_dir} |
| 83 | + rm -rf notecards |
| 84 | +fi |
| 85 | + |
| 86 | +# Figure out release tags from tarball names |
| 87 | +pushd ${tarball_dir} >/dev/null 2>/dev/null |
| 88 | +medley_release=$(echo medley-*-loadups.tgz | sed "s/medley-\(.*\)-loadups.tgz/\1/") |
| 89 | +maiko_release=$(echo maiko-*-darwin.x86_64.tgz | sed "s/maiko-\(.*\)-darwin.x86_64.tgz/\1/") |
| 90 | +popd >/dev/null 2>/dev/null |
| 91 | + |
| 92 | +if [ "${INCLUDE_APP}" = "yes" ]; then |
| 93 | + # |
| 94 | + # Create bundle dirs |
| 95 | + # |
| 96 | + rm -rf ${RESULTS_DIR} |
| 97 | + mkdir -p ${RESULTS_DIR} |
| 98 | + rm -rf ${APPBUNDLE} |
| 99 | + mkdir -p ${APPBUNDLE} |
| 100 | + mkdir ${APPBUNDLE}/Contents |
| 101 | + mkdir ${APPBUNDLE}/Contents/MacOS |
| 102 | + mkdir ${APPBUNDLE}/Contents/Resources |
| 103 | + # |
| 104 | + # Create icons and put in bundle |
| 105 | + # |
| 106 | + iconset_dir=${tmp_dir}/${APPNAME}.iconset |
| 107 | + rm -rf ${iconset_dir} |
| 108 | + mkdir -p ${iconset_dir} |
| 109 | + image_dir=${CWD}/images |
| 110 | + sips -z 16 16 ${image_dir}/App_icon1024.png --out ${iconset_dir}/icon_16x16.png >/dev/null 2>&1 |
| 111 | + sips -z 32 32 ${image_dir}/App_icon1024.png --out ${iconset_dir}/ [email protected] >/dev/null 2>&1 |
| 112 | + sips -z 32 32 ${image_dir}/App_icon1024.png --out ${iconset_dir}/icon_32x32.png >/dev/null 2>&1 |
| 113 | + sips -z 64 64 ${image_dir}/App_icon1024.png --out ${iconset_dir}/ [email protected] >/dev/null 2>&1 |
| 114 | + sips -z 128 128 ${image_dir}/App_icon1024.png --out ${iconset_dir}/icon_128x128.png >/dev/null 2>&1 |
| 115 | + sips -z 256 256 ${image_dir}/App_icon1024.png --out ${iconset_dir}/ [email protected] >/dev/null 2>&1 |
| 116 | + sips -z 256 256 ${image_dir}/App_icon1024.png --out ${iconset_dir}/icon_256x256.png >/dev/null 2>&1 |
| 117 | + sips -z 512 512 ${image_dir}/App_icon1024.png --out ${iconset_dir}/ [email protected] >/dev/null 2>&1 |
| 118 | + sips -z 512 512 ${image_dir}/App_icon1024.png --out ${iconset_dir}/icon_512x512.png >/dev/null 2>&1 |
| 119 | + cp ${image_dir}/App_icon1024.png ${iconset_dir}/ [email protected] |
| 120 | + iconutil -c icns -o ${tmp_dir}/${APPNAME}.icns ${iconset_dir} |
| 121 | + cp ${tmp_dir}/${APPNAME}.icns ${APPBUNDLEICON}/ |
| 122 | + rm -r ${iconset_dir} |
| 123 | + rm ${tmp_dir}/${APPNAME}.icns |
| 124 | + # |
| 125 | + # Update and copy in "control" files |
| 126 | + # |
| 127 | + sed -e "s/--VERSION_TAG--/${medley_release}.${maiko_release}.0/g" \ |
| 128 | + < app/Info.plist \ |
| 129 | + > ${APPBUNDLECONTENTS}/Info.plist |
| 130 | + cp app/PkgInfo ${APPBUNDLECONTENTS}/ |
| 131 | +fi #INCLUDE_APP |
| 132 | + |
| 133 | +# |
| 134 | +# Untar the maiko and medley releases into the bundle |
| 135 | +# |
| 136 | +il_dir=${APPBUNDLE}/Contents/MacOS |
| 137 | +mkdir -p ${il_dir} |
| 138 | +tar -x -z -C ${il_dir} \ |
| 139 | + -f "${tarball_dir}/maiko-${maiko_release}-darwin.universal.tgz" |
| 140 | +tar -x -z -C ${il_dir} \ |
| 141 | + -f "${tarball_dir}/medley-${medley_release}-runtime.tgz" |
| 142 | +tar -x -z -C ${il_dir} \ |
| 143 | + -f "${tarball_dir}/medley-${medley_release}-loadups.tgz" |
| 144 | +tar -x -z -C ${il_dir} \ |
| 145 | + -f "${tarball_dir}/notecards.tgz" |
| 146 | +# |
| 147 | +# Handle run_medley needing separate directories for each arch |
| 148 | +# |
| 149 | +pushd ${il_dir}/maiko >/dev/null 2>&1 |
| 150 | +ln -s darwin.universal darwin.aarch64 |
| 151 | +ln -s darwin.universal darwin.x86_64 |
| 152 | +popd >/dev/null 2>&1 |
| 153 | +# |
| 154 | +# Add file icon to medley.command |
| 155 | +# |
| 156 | +if [ -z "$(which fileicon)" ]; |
| 157 | +then |
| 158 | + brew install fileicon |
| 159 | +fi |
| 160 | +fileicon set ${il_dir}/medley/scripts/medley/medley.command ${image_dir}/Command_icon128.png |
| 161 | +# |
| 162 | +# Also create the zip file of il_dir for distribution |
| 163 | +# |
| 164 | +pushd ${il_dir} >/dev/null 2>&1 |
| 165 | +filename="$(echo ${ARTIFACTS_FILENAME_TEMPLATE} | sed -e "s#@@PLATFORM@@#macos#" -e "s#@@ARCH@@#universal#" -e "s#@@MEDLEY.RELEASE@@#${medley_release}#" -e "s#@@MAIKO.RELEASE@@#${maiko_release}#" )" |
| 166 | +zip -r -6 -y -q ${RESULTS_DIR}/${filename}.zip . |
| 167 | +popd >/dev/null 2>&1 |
| 168 | + |
| 169 | +###################################################################################################### |
| 170 | +###################################################################################################### |
0 commit comments