Skip to content

Instantly share code, notes, and snippets.

@munepi
Last active February 10, 2024 05:02
Show Gist options
  • Save munepi/e5cbb2176b7c48581ff4 to your computer and use it in GitHub Desktop.
Save munepi/e5cbb2176b7c48581ff4 to your computer and use it in GitHub Desktop.
Command line installer/updater of LibreOffice+Japanese language pack on Mac OS X
#!/bin/bash -x
set -euxo pipefail
##cd "$(dirname "$0")/"
LibO=${LibO:-24.2.0}
LibO_major=$(echo $LibO | awk -F. '{ OFS=FS; print $1 }')
LibO_minor=$(echo $LibO | awk -F. '{ OFS=FS; print $2 }')
LibO_rev=$(echo $LibO | awk -F. '{ OFS=FS; print $3 }')
__hdiutil="hdiutil attach -nobrowse"
trap cleanup EXIT
cleanup() {
set +e
# rm -f /Library/Caches/LibreOffice_${LibO}_MacOS_{x86-64,aarch64}{,_langpack_ja}.dmg{,.asc}
umount -f /Volumes/LibreOffice >/dev/null ||:
umount -f /Volumes/LibreOffice\ ja\ Language\ Pack >/dev/null ||:
for x in $(seq 1 200); do
if [ -d "/Volumes/LibreOffice ${x}" ]; then
diskutil umount force /Volumes/LibreOffice\ ${x} >/dev/null ||:
umount -f /Volumes/LibreOffice\ ${x} >/dev/null ||:
fi
if [ -d "/Volumes/LibreOffice ja Language Pack ${x}" ]; then
diskutil umount force /Volumes/LibreOffice\ ja\ Language\ Pack\ ${x} >/dev/null ||:
umount -f /Volumes/LibreOffice\ ja\ Language\ Pack\ ${x} >/dev/null ||:
fi
done
}
cleanup
set -e
## set archtecture
case $(uname -m) in
x86_64)
DIRARCH=x86_64
DMGARCH=x86-64
;;
arm64)
DIRARCH=aarch64
DMGARCH=aarch64
;;
*)
echo $(uname -m): not supported
exit 1
esac
cd /Library/Caches/
wget -N http://ftp.jaist.ac.jp/pub/tdf/libreoffice/stable/${LibO}/mac/${DIRARCH}/LibreOffice_${LibO}_MacOS_${DMGARCH}{,_langpack_ja}.dmg{,.asc}
## Remove/Install LibreOffice.app
rm -rf /Applications/LibreOffice.app ||:
$__hdiutil LibreOffice_${LibO}_MacOS_${DMGARCH}.dmg
cp -af /Volumes/LibreOffice/LibreOffice.app /Applications/
diskutil umount /Volumes/LibreOffice/
## Install Japanese Language Pack
$__hdiutil LibreOffice_${LibO}_MacOS_${DMGARCH}_langpack_ja.dmg
## From /Volumes/LibreOffice\ Language\ Pack/LibreOffice\ Language\ Pack.app/Contents/osx_install.applescript:
## set tarCommand to "/usr/bin/tar -C " & quoted form of (choice as string) & " -xjf " & quoted form of sourcedir & "/tarball.tar.bz2 && touch " & quoted form of (choice as string) & "/Contents/Resources/extensions"
# PACKDIR="LibreOffice Language Pack"
PACKDIR="LibreOffice ja Language Pack"
/usr/bin/tar -C "/Applications/LibreOffice.app" -xjf "/Volumes/${PACKDIR}/LibreOffice Language Pack.app/Contents/Resources/tarball.tar.bz2"
touch /Applications/LibreOffice.app/Contents/Resources/extensions
diskutil umount "/Volumes/${PACKDIR}/"
echo $(basename $0): finished
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment