summaryrefslogtreecommitdiffstats
path: root/packaging/macos/jhb/usr/bin
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xpackaging/macos/jhb/usr/bin/archive205
-rwxr-xr-xpackaging/macos/jhb/usr/bin/bootstrap135
-rwxr-xr-xpackaging/macos/jhb/usr/bin/jhb63
-rwxr-xr-xpackaging/macos/jhb/usr/bin/run-parts73
4 files changed, 476 insertions, 0 deletions
diff --git a/packaging/macos/jhb/usr/bin/archive b/packaging/macos/jhb/usr/bin/archive
new file mode 100755
index 0000000..f84f0c8
--- /dev/null
+++ b/packaging/macos/jhb/usr/bin/archive
@@ -0,0 +1,205 @@
+#!/usr/bin/env bash
+#
+# SPDX-FileCopyrightText: 2021 René de Hesselle <dehesselle@web.de>
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+### description ################################################################
+
+# This is a helper to create release archives and mount them.
+
+### shellcheck #################################################################
+
+# Nothing here.
+
+### dependencies ###############################################################
+
+#------------------------------------------------------ source jhb configuration
+
+source "$(dirname "${BASH_SOURCE[0]}")"/../../etc/jhb.conf.sh
+
+#------------------------------------------- source common functions from bash_d
+
+# bash_d is already available (it's part of jhb configuration)
+
+bash_d_include error
+
+### variables ##################################################################
+
+# Nothing here.
+
+### functions ##################################################################
+
+function create_tar
+{
+ local file=$ARTIFACT_DIR/$RELEASE_ARCHIVE
+
+ echo_i "creating $file"
+
+ tar -C "$WRK_DIR" -cp "$(basename "$VER_DIR")" |
+ XZ_OPT=-T0 "$BIN_DIR"/xz > "$file"
+
+ shasum -a 256 "$file" > "$file".sha256
+ cat "$file".sha256
+}
+
+function create_dmg
+{
+ local file=$ARTIFACT_DIR/$RELEASE_ARCHIVE
+
+ ( # create dmg
+ local vol_name
+ vol_name=$(basename "$VER_DIR")
+
+ cd "$WRK_DIR" || exit 1
+ hdiutil create -fs HFS+ -ov -format UDBZ \
+ -srcfolder "$vol_name" \
+ -volname "$vol_name" \
+ "$file"
+ )
+
+ ( # create and print checksum
+ cd "$(dirname "$file")" || exit 1
+ shasum -a 256 "$(basename "$file")" > "$file".sha256
+ cat "$file".sha256
+ )
+}
+
+function mount_dmg
+{
+ local file=$REP_DIR/$RELEASE_ARCHIVE
+ local mountpoint=$VER_DIR
+
+ if [ ! -d "$mountpoint" ]; then
+ mkdir -p "$mountpoint"
+ fi
+
+ echo_i "mounting $(basename "$file") may take some time"
+ local device
+ device=$(hdiutil attach -nomount "$file" | grep "^/dev/disk" |
+ grep "Apple_HFS" | awk '{ print $1 }')
+ echo_i "$file attached to $device"
+ mount -o nobrowse,noowners,noquarantine,ro -t hfs "$device" "$mountpoint"
+ echo_i "$device mounted to $mountpoint"
+}
+
+function unmount_dmg
+{
+ local mountpoint=$VER_DIR
+
+ while : ; do # unmount everything (in reverse order)
+ local disk
+ disk=$(mount | grep "$mountpoint" | tail -n1 | awk '{ print $1 }')
+ disk=${disk%s[0-9]} # cut off slice specification
+
+ if [ ${#disk} -eq 0 ]; then
+ break # nothing to do here
+ else
+ # We loop over the 'eject' since it occasionally timeouts.
+ while ! diskutil eject "$disk" > /dev/null; do
+ echo_w "retrying to eject $disk in 5 seconds"
+ sleep 5
+ done
+
+ echo_i "ejected $disk"
+ fi
+ done
+}
+
+function download_dmg
+{
+ if [ ! -d "$REP_DIR" ]; then
+ mkdir -p "$REP_DIR"
+ fi
+
+ for url in "${RELEASE_URLS[@]}"; do
+ local partial_download=$REP_DIR/${FUNCNAME[0]} # TMP_DIR not available yet
+ # download (at least) 100 kb of data
+ curl -L "$url" 2>/dev/null | head -c 100000 > "$partial_download"
+ # if we got 100 kb, it's not a "404 file not found"
+ if [ "$(stat -f%z "$partial_download")" -eq 100000 ]; then
+ echo_i "downloading $url"
+ curl -o "$REP_DIR/$RELEASE_ARCHIVE" -L -C - "$url"
+ break
+ fi
+ done
+
+ rm "$partial_download"
+}
+
+function install_dmg
+{
+ local overlay_size=${1:-1} # unit GiB, default 1
+
+ local file=$REP_DIR/$RELEASE_ARCHIVE
+
+ # download and mount read-only disk image
+ if [ -f "$file" ]; then
+ echo_i "using $file"
+ else
+ download_dmg
+ fi
+ mount_dmg
+
+ # create writable overlay
+ local device
+ device=$(hdiutil attach -nomount ram://$((overlay_size * 1024 * 2048)) | xargs)
+ newfs_hfs -v "$RELEASE_OVERLAY" "$device" >/dev/null
+ echo_i "$overlay_size GiB ram attached to $device"
+ mount -o nobrowse,rw,union -t hfs "$device" "$VER_DIR"
+ echo_i "$device union-mounted at $VER_DIR"
+
+ # Sadly, there are some limitations involved with union-mounting:
+ # - Files are not visible to macOS' versions of 'ls' or 'find'.
+ # (The GNU versions do work though.)
+ # - You cannot write in a location without having written to its
+ # parent location first. That's why we need to pre-create all directories
+ # below.
+ #
+ # (Shadow-mounting a dmg is not a feasible alternative due to its
+ # bad write-performance.)
+
+ # Create and run a script for mass-creating directories.
+ echo_i "setting up directories in overlay"
+ gfind "$VER_DIR" -mindepth 1 -type d \
+ ! -path "$BLD_DIR/*" ! -path "$SRC_DIR/*" \
+ -exec echo "mkdir {}" \; > "$VER_DIR"/create_dirs.sh
+ chmod 755 "$VER_DIR"/create_dirs.sh
+ "$VER_DIR"/create_dirs.sh
+ rm "$VER_DIR"/create_dirs.sh
+}
+
+function uninstall_dmg
+{
+ unmount_dmg
+}
+
+function main
+{
+ local command=$1
+ local option=$2
+
+ case "$command" in
+ create_dmg)
+ create_dmg
+ ;;
+ create_tar)
+ create_tar
+ ;;
+ install_dmg)
+ install_dmg "$option" # option: overlay size in GiB, defaul is 1
+ ;;
+ uninstall_dmg)
+ uninstall_dmg
+ ;;
+ *)
+ echo_e "usage: $0 {create_dmg|create_tar|install_dmg|uninstall_dmg}"
+ ;;
+ esac
+}
+
+### main #######################################################################
+
+error_trace_enable
+
+main "$@"
diff --git a/packaging/macos/jhb/usr/bin/bootstrap b/packaging/macos/jhb/usr/bin/bootstrap
new file mode 100755
index 0000000..3d46dbb
--- /dev/null
+++ b/packaging/macos/jhb/usr/bin/bootstrap
@@ -0,0 +1,135 @@
+#!/usr/bin/env bash
+#
+# SPDX-FileCopyrightText: 2021 René de Hesselle <dehesselle@web.de>
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+### description ################################################################
+
+# This script bootstraps JHBuild so it's ready to build any module.
+
+### shellcheck #################################################################
+
+# Nothing here.
+
+### dependencies ###############################################################
+
+#------------------------------------------------------ source jhb configuration
+
+# You can install a custom configuration file by passing it as first
+# argument. It has to be named '*.conf.sh'.
+
+source "$(dirname "${BASH_SOURCE[0]}")"/../../etc/jhb.conf.sh "$1"
+
+#------------------------------------------- source common functions from bash_d
+
+# bash_d is already available (it's part of jhb configuration)
+
+bash_d_include error
+
+### variables ##################################################################
+
+SELF_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1; pwd)
+
+FORCE_BUILD_FROM_SOURCE=${FORCE_BUILD_FROM_SOURCE:-false}
+
+### functions ##################################################################
+
+function is_release_usable
+{
+ local url=$1
+
+ local partial_download="$TMP_DIR/${FUNCNAME[0]}".tar.xz
+ local rc=1
+
+ # download at least 100 kb of data
+ curl -L "$url" 2>/dev/null | head -c 100000 > "$partial_download"
+ # if we got 100 kb, it's not a "404 file not found"
+ if [ "$(stat -f%z "$partial_download")" -eq 100000 ]; then
+ # look inside: dir needs to match our VER_DIR to be usable
+ local dir
+ dir=$(basename "$(tar -tvJf "$partial_download" 2>/dev/null |
+ head -n 1 | awk '{ print $NF }')")
+ if [ "$dir" = "$(basename "$VER_DIR")" ]; then
+ rc=0
+ fi
+ fi
+
+ rm "$partial_download"
+
+ return $rc
+}
+
+### main #######################################################################
+
+error_trace_enable
+
+#-------------------------------------------------------- print main directories
+
+echo_i "WRK_DIR = $WRK_DIR"
+echo_i "VER_DIR = $VER_DIR"
+
+#--------------------------------------------------------- perform system checks
+
+if sys_wrkdir_is_usable &&
+ sdkroot_exists &&
+ sys_usrlocal_is_clean; then
+
+ # these checks may issue warnings but have have no consequences otherwise
+ sys_macos_is_recommended || true
+ sys_sdk_is_recommended || true
+else
+ exit 1 # cannot continue
+fi
+
+#--------------------------------------------------- initialize directory layout
+
+if [ "$SELF_DIR" = "$USR_DIR"/bin ]; then
+ : # we are already running inside target directory layout
+else
+ # sync repository into target structure, remove everything git-related
+ rsync -a "$SELF_DIR"/../../../jhb/ "$VER_DIR"/
+ find "$VER_DIR" -type f -name ".gitignore" -delete
+ rm -rf "$VER_DIR"/.git
+ rm "$VER_DIR"/.gitmodules
+fi
+
+#------------------------------------------- check if binary release can be used
+
+for URL in "${RELEASE_URLS[@]}"; do
+ if is_release_usable "$URL" && ! $FORCE_BUILD_FROM_SOURCE; then
+ echo_i "using $URL"
+ curl -L "$URL" | tar -C "$WRK_DIR" -xJ
+ exit $? # we can quit here and now, nothing further to do
+ fi
+done
+
+echo_i "building everything from scratch"
+
+#---------------------------------------------------------------- install ccache
+
+ccache_install
+ccache_configure
+
+#------------------------------------------ log relevant versions to release.log
+
+sys_create_log
+
+#------------------------------------------------- install and configure JHBuild
+
+jhbuild_install
+jhbuild_configure
+
+#------------------------------------------------------- run bootstrap procedure
+
+jhbuild bootstrap-gtk-osx
+
+#--------------------------------------------------------- install GNU utilities
+
+# GNU versions of various utilites make life significantly easier on macOS.
+
+jhbuild build coreutils findutils sed tar
+
+#-------------------------------------------------------------- install dmgbuild
+
+dmgbuild_install
diff --git a/packaging/macos/jhb/usr/bin/jhb b/packaging/macos/jhb/usr/bin/jhb
new file mode 100755
index 0000000..b268339
--- /dev/null
+++ b/packaging/macos/jhb/usr/bin/jhb
@@ -0,0 +1,63 @@
+#!/usr/bin/env bash
+#
+# SPDX-FileCopyrightText: 2021 René de Hesselle <dehesselle@web.de>
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+### description ################################################################
+
+# This script is a wrapper around the jhbuild binary to run it in our
+# configured environment (etc/jhb.conf).
+
+### shellcheck #################################################################
+
+# Nothing here.
+
+### dependencies ###############################################################
+
+#---------------------------------------------------------- source configuration
+
+source "$(dirname "${BASH_SOURCE[0]}")"/../../etc/jhb.conf.sh
+
+#------------------------------------------- source common functions from bash_d
+
+# bash_d is already available (it's part of etc/jhb.conf)
+
+bash_d_include error
+
+### variables ##################################################################
+
+# Nothing here.
+
+### functions ##################################################################
+
+# Nothing here.
+
+### main #######################################################################
+
+if $CI; then # break in CI, otherwise we get interactive prompt by JHBuild
+ error_trace_enable
+fi
+
+case "$1" in
+ debug)
+ echo_d "doing nothing"
+ ;;
+ configure)
+ jhbuild_configure "$2" # e.g. 'jhbuild/myapp.modules'
+ ccache_configure
+ ;;
+ *)
+ if sys_wrkdir_is_usable &&
+ sdkroot_exists &&
+ sys_usrlocal_is_clean; then
+
+ # these checks may issue warnings but have have no consequences otherwise
+ sys_macos_is_recommended || true
+ sys_sdk_is_recommended || true
+ else
+ exit 1 # cannot continue
+ fi
+ "$USR_DIR"/bin/jhbuild "$@"
+ ;;
+esac \ No newline at end of file
diff --git a/packaging/macos/jhb/usr/bin/run-parts b/packaging/macos/jhb/usr/bin/run-parts
new file mode 100755
index 0000000..ff0470c
--- /dev/null
+++ b/packaging/macos/jhb/usr/bin/run-parts
@@ -0,0 +1,73 @@
+#!/usr/bin/env bash
+
+### description ################################################################
+
+# A partial replacement for Debian's "run-parts" tool. Execute files in a
+# directory in their lexical order with the specialty of being able to
+# use symlinks to create an order without executing the files twice.
+
+### shellcheck #################################################################
+
+# Nothing here.
+
+### dependencies ###############################################################
+
+# Nothing here.
+
+### variables ##################################################################
+
+# Nothing here.
+
+### functions ##################################################################
+
+function main
+{
+ local mode=$1
+ local dir=$2
+
+ local file_pattern
+
+ if [ -d "$dir" ]; then
+ # reconstruct to make it proper (e.g. remove superfluous slashes)
+ dir=$(dirname "$dir")/$(basename "$dir")
+ else
+ # split into directory and file
+ file_pattern=$(basename "$dir")
+ dir=$(dirname "$dir")
+ fi
+
+ file_pattern=${file_pattern:-*} # default pattern is "*"
+
+ local linked_files
+ linked_files=$(find "$dir" -type l -exec readlink {} +)
+
+ for file in "$dir"/$file_pattern; do # requires 'shopt -s nullglob'
+ # Only process files that have no symlinks (in that same directory) pointing
+ # at them.
+ if [[ "$linked_files" != *$(basename "$file")* ]]; then
+ case "$mode" in
+ list)
+ echo "$file"
+ ;;
+ run)
+ $file
+ ;;
+ esac
+ fi
+ done
+}
+
+### main #######################################################################
+
+set -e
+
+shopt -s nullglob # in case no files are found
+
+case "$1" in
+ list)
+ main "list" "$2"
+ ;;
+ *)
+ main "run" "$1"
+ ;;
+esac