#!/usr/bin/env sh set -e # Moonlander Layout # # Copyright (C) 2024 Benedikt Peetz # SPDX-License-Identifier: AGPL-3.0-or-later # # This file is part of Moonlander Layout. # # You should have received a copy of the License along with this program. # If not, see . LAYOUT_ID="KWBYA" LAYOUT_GEOMETRY="moonlander" # # Download layout source # data="$(mktemp)" # echo # cat <"$data" # { "query": "query getLayout(\$hashId: String!, \$revisionId: String!, \$geometry: String) {layout(hashId: \$hashId, geometry: \$geometry, revisionId: \$revisionId) { revision { hashId, qmkVersion, title }}}","variables":{"hashId":"$LAYOUT_ID","geometry":"$LAYOUT_GEOMETRY","revisionId":"latest"}} # EOF # # response="$(curl --location 'https://oryx.zsa.io/graphql' --header 'Content-Type: application/json' --data "$(cat "$data")" | jq '.data.layout.revision | [.hashId, .qmkVersion, .title]')" # # hash_id="$(echo "${response}" | jq -r '.[0]')" # firmware_version=$(printf "%.0f" "$(echo "${response}" | jq -r '.[1]')") # change_description=$(echo "${response}" | jq -r '.[2]') # if [ -z "${change_description}" ]; then # change_description="latest layout modification made with Oryx" # fi # # curl -L "https://oryx.zsa.io/source/${hash_id}" -o source.zip # # # Unzip the source file # unzip -oj source.zip '*_source/*' -d "$LAYOUT_ID" # rm source.zip # # # Commit and Push changes # git config --local user.name "github-actions" # git config --local user.email "github-actions@github.com" # git add . # git commit -m "✨(oryx): $change_description" || echo "No layout change" # git push # # # Merge Oryx with custom QMK # git fetch origin main # git checkout -B main origin/main # git merge -Xignore-all-space oryx # git push # # # Checkout the right firmware branch # cd qmk_firmware # git submodule update --init --remote # git fetch origin "firmware$firmware_version" # git checkout -B "firmware$firmware_version" "origin/firmware$firmware_version" # git submodule update --init --recursive # # # Build qmk docker image # docker build -t qmk . # # Build the layout # ## Set keyboard directory and make prefix based on firmware version # if [ "$firmware_version" -ge 24 ]; then # keyboard_directory="qmk_firmware/keyboards/zsa" # make_prefix="zsa/" # else # keyboard_directory="qmk_firmware/keyboards" # make_prefix="" # fi # # ## Copy layout files to the qmk folder # rm -rf ${keyboard_directory}/$LAYOUT_GEOMETRY/keymaps/$LAYOUT_ID # mkdir -p ${keyboard_directory}/$LAYOUT_GEOMETRY/keymaps && cp -r $LAYOUT_ID ${keyboard_directory}/$LAYOUT_GEOMETRY/keymaps ## Build the layout docker run -v ./qmk_firmware:/root --rm qmk /bin/sh -c " qmk setup zsa/qmk_firmware -b 'firmware$firmware_version' -y make ${make_prefix}$LAYOUT_GEOMETRY:$LAYOUT_ID " ## Find and export built layout normalized_layout_geometry="$(echo "$LAYOUT_GEOMETRY" | sed 's/\//_/g')" built_layout_file="$(find ./qmk_firmware -maxdepth 1 -type f -regex ".*${normalized_layout_geometry}.*\.\(bin\|hex\)$")"