Maraiah/bundle.sh

116 lines
2.5 KiB
Bash
Raw Normal View History

2019-07-04 20:25:44 -07:00
#!/usr/bin/env bash
err_ok=0
err_bad_arg=1
err_bad_run=2
rm_if() {
2019-07-05 20:21:11 -07:00
if [[ -d $1 ]];
then
rm -rf "$1" && echo "removed dir $1"
elif [[ -f $1 ]]
then
rm -f "$1" && echo "removed file $1"
fi
2019-07-04 20:25:44 -07:00
return 0
}
perish() {
2019-07-05 20:21:11 -07:00
rm_if "${tmpdir}"
exit "$1"
2019-07-04 20:25:44 -07:00
}
err() {
2019-07-05 20:21:11 -07:00
echo "error, dropping build"
rm_if "${appdir}"
rm_if "${dmg}"
perish $1
2019-07-04 20:25:44 -07:00
}
:() {
2019-07-05 20:21:11 -07:00
echo "$@"
echo
eval "$@" || err ${err_bad_run}
2019-07-04 20:25:44 -07:00
}
declare -A icon_names=(
2019-07-05 20:21:11 -07:00
[Tycho]="resources/color/pfhor-hand.png"
2019-07-04 20:25:44 -07:00
)
name=$1
exe=$2
if [[ ! $name ]]
then
2019-07-05 20:21:11 -07:00
echo "program name needed (available: Tycho)"
err ${err_bad_arg}
2019-07-04 20:25:44 -07:00
fi
if [[ ! $exe ]]
then
2019-07-05 20:21:11 -07:00
echo "full path to executable required (ex. '$0 $name ~/bin/maraiah-tycho')"
err ${err_bad_arg}
2019-07-04 20:25:44 -07:00
fi
app=${name}.app
srcdir=${PWD}/${name,,}
exedir=$(dirname "${exe}")
appdir=${exedir}/${app}
tmpdir=$(mktemp -d)
diskdir=${tmpdir}/disk
2019-07-04 20:25:44 -07:00
icondir=${tmpdir}/${name}.iconset
2019-07-04 20:25:44 -07:00
icon=${srcdir}/${icon_names[${name}]}
dmg=${exedir}/${name}.dmg
2019-07-04 20:25:44 -07:00
: rm_if "${appdir}"
2019-07-04 20:25:44 -07:00
: mkdir -p "${appdir}/Contents/"{Frameworks,MacOS,Resources}
2019-07-04 20:25:44 -07:00
: cp "${exe}" "${appdir}/Contents/MacOS"
: cp "${srcdir}/resources/Info.plist" "${appdir}/Contents"
: mkdir -p "${icondir}"
2019-07-04 20:25:44 -07:00
: sips -z 16 16 "${icon}" --out "${icondir}/icon_16x16.png"
: sips -z 32 32 "${icon}" --out "${icondir}/icon_32x32.png"
: sips -z 64 64 "${icon}" --out "${icondir}/icon_64x64.png"
: sips -z 128 128 "${icon}" --out "${icondir}/icon_128x128.png"
: sips -z 256 256 "${icon}" --out "${icondir}/icon_256x256.png"
: sips -z 512 512 "${icon}" --out "${icondir}/icon_512x512.png"
: sips -z 1024 1024 "${icon}" --out "${icondir}/icon_512x512@2x.png"
: cp "${icondir}/icon_32x32.png" "${icondir}/icon_16x16@2x.png"
: cp "${icondir}/icon_64x64.png" "${icondir}/icon_32x32@2x.png"
: cp "${icondir}/icon_256x256.png" "${icondir}/icon_128x128@2x.png"
: cp "${icondir}/icon_512x512.png" "${icondir}/icon_256x256@2x.png"
: iconutil -c icns -o "${appdir}/Contents/Resources/${name}.icns" "${icondir}"
while IFS= read -r lnk
do
2019-07-05 20:21:11 -07:00
lnk=$(dirname "${lnk}")
: cp -r "${lnk}" "${appdir}/Contents/Frameworks"
2019-07-04 20:25:44 -07:00
done < "${exedir}"/build/maraiah-tycho-*/out/etc/link.txt
echo "success: bundle written to ${appdir}"
if [[ ! "$NO_DMG" ]]
then
2019-07-05 20:21:11 -07:00
echo "creating the disk image..."
2019-07-05 20:21:11 -07:00
: rm_if "${dmg}"
2019-07-05 20:21:11 -07:00
: mkdir -p "${diskdir}"
: cp -r "${appdir}" "${diskdir}"
: cp "${srcdir}/resources/Image.DS_Store" "${diskdir}/.DS_Store"
: ln -s /Applications "${diskdir}"
: hdiutil create -volname "${name}" -srcfolder "${diskdir}" "${dmg}"
2019-07-05 20:21:11 -07:00
echo "success: dmg written to ${dmg}"
fi
2019-07-04 20:25:44 -07:00
perish ${err_ok}
## EOF