Files
IronFox/scripts/sign.sh
Akash Yadav aeb8d3a5f0 feat: lint shell scripts with shellcheck + shfmt in CI and pre-commit
ironfox-oss/IronFox!162
Add a blocking `lint` CI stage (runs first, on a lightweight Alpine
image) plus a core.hooksPath pre-commit hook, with scripts/lint.sh as
the shared runner for CI, the hook, and manual use. Checks are
configured in .shellcheckrc and formatting in .editorconfig.

Reformat all scripts with shfmt (2-space indent, switch-case indent,
space redirects) via .editorconfig, so a bare `shfmt` is consistent
everywhere. bootstrap.sh installs shellcheck + shfmt per-OS and
enables the pre-commit hook.

The hook is a convenience (bypassable with --no-verify); the CI
`lint-scripts` job is the enforcement gate. SC2086/SC2046 are
disabled for now as tracked follow-up.

MR-author: Akash Yadav <itsaky01@gmail.com>
Co-authored-by: Akash Yadav <contact@itsaky.com>
Approved-by: celenity <celenity@celenity.dev>
Merged-by: celenity <celenity@celenity.dev>
2026-07-31 02:33:10 +00:00

144 lines
4.2 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
# Ensure this is never ran with xtrace...
set +x
# Set-up our environment
source $(dirname $0)/env.sh
# Include utilities
source "${IRONFOX_UTILS}"
# Include version info
source "${IRONFOX_VERSIONS}"
readonly target="$1"
# Functions
function sign_apk() {
local -r apk_in="$1"
local -r apk_out="$2"
# Ensure the APK to sign exists
verify_file "${apk_in}" || exit 1
"${IRONFOX_APKSIGNER}" sign \
--ks="${IRONFOX_ANDROID_KEYSTORE}" \
--ks-pass="file:/${IRONFOX_ANDROID_KEYSTORE_PASS_FILE}" \
--ks-key-alias="${IRONFOX_ANDROID_KEYSTORE_KEY_ALIAS}" \
--key-pass="file:/${IRONFOX_ANDROID_KEYSTORE_KEY_PASS_FILE}" \
--out="${apk_out}" \
"${apk_in}"
}
function sign_bundle() {
echo_red_text 'Building signed bundleset...'
# Ensure the AAB to sign exists
verify_file_with_env "${IRONFOX_OUTPUTS_BUNDLE_AAB}" 'IRONFOX_OUTPUTS_BUNDLE_AAB' || exit 1
# Create our output directory
"${IRONFOX_MKDIR}" -p $("${IRONFOX_DIRNAME}" "${IRONFOX_OUTPUTS_BUNDLE}")
"${IRONFOX_BUNDLETOOL}" build-apks \
--bundle="${IRONFOX_OUTPUTS_BUNDLE_AAB}" \
--output="${IRONFOX_OUTPUTS_BUNDLE}" \
--ks="${IRONFOX_ANDROID_KEYSTORE}" \
--ks-pass="file:/${IRONFOX_ANDROID_KEYSTORE_PASS_FILE}" \
--ks-key-alias="${IRONFOX_ANDROID_KEYSTORE_KEY_ALIAS}" \
--key-pass="file:/${IRONFOX_ANDROID_KEYSTORE_KEY_PASS_FILE}"
echo_green_text 'SUCCESS: Created signed bundleset'
}
function sign_arm64() {
# Create our output directory
"${IRONFOX_MKDIR}" -p $("${IRONFOX_DIRNAME}" "${IRONFOX_OUTPUTS_ARM64}")
echo_red_text 'Signing APK (ARM64)...'
sign_apk "${IRONFOX_OUTPUTS_ARM64_UNSIGNED}" "${IRONFOX_OUTPUTS_ARM64}"
echo_green_text 'SUCCESS: Signed APK (ARM64)'
}
function sign_arm() {
# Create our output directory
"${IRONFOX_MKDIR}" -p $("${IRONFOX_DIRNAME}" "${IRONFOX_OUTPUTS_ARM}")
echo_red_text 'Signing APK (ARM)...'
sign_apk "${IRONFOX_OUTPUTS_ARM_UNSIGNED}" "${IRONFOX_OUTPUTS_ARM}"
echo_green_text 'SUCCESS: Signed APK (ARM)'
}
function sign_x86_64() {
# Create our output directory
"${IRONFOX_MKDIR}" -p $("${IRONFOX_DIRNAME}" "${IRONFOX_OUTPUTS_X86_64}")
echo_red_text 'Signing APK (x86_64)...'
sign_apk "${IRONFOX_OUTPUTS_X86_64_UNSIGNED}" "${IRONFOX_OUTPUTS_X86_64}"
echo_green_text 'SUCCESS: Signed APK (x86_64)'
}
function sign_universal() {
# Create our output directory
"${IRONFOX_MKDIR}" -p $("${IRONFOX_DIRNAME}" "${IRONFOX_OUTPUTS_UNIVERSAL}")
echo_red_text 'Signing APK (Universal)...'
sign_apk "${IRONFOX_OUTPUTS_UNIVERSAL_UNSIGNED}" "${IRONFOX_OUTPUTS_UNIVERSAL}"
echo_green_text 'SUCCESS: Signed APK (Universal)'
}
# Sign ARM64 APK
if [[ "${target}" == 'arm64' ]] || [[ "${target}" == 'bundle' ]]; then
sign_arm64
fi
# Sign ARM APK
if [[ "${target}" == 'arm' ]] || [[ "${target}" == 'bundle' ]]; then
sign_arm
fi
# Sign x86_64 APK
if [[ "${target}" == 'x86_64' ]] || [[ "${target}" == 'bundle' ]]; then
sign_x86_64
fi
# Sign universal APK + build signed APK set
if [[ "${target}" == 'bundle' ]]; then
sign_universal
sign_bundle
fi
if [[ "${IRONFOX_SIGN_SKIP_ADB}" != 1 ]]; then
echo_red_text 'Would you like to install IronFox to a connected device?'
read -p "If you'd like to install IronFox, please ensure your device is connected before proceeding. [y/N] " -n 1 -r
echo
if [[ "${REPLY}" =~ ^[Yy]$ ]]; then
"${IRONFOX_ADB}" devices
if [[ "${IRONFOX_OS}" == 'osx' ]]; then
# On OS X, the user may need to accept a prompt to allow their device to connect,
## so wait to ensure we allow them to accept it
"${IRONFOX_SLEEP}" 6
fi
if [[ "${target}" == 'bundle' ]]; then
# If we built a bundle, install the universal APK
"${IRONFOX_ADB}" install -r "${IRONFOX_OUTPUTS_UNIVERSAL}"
elif [[ "${target}" == 'arm64' ]]; then
# Install the ARM64 APK
"${IRONFOX_ADB}" install -r "${IRONFOX_OUTPUTS_ARM64}"
elif [[ "${target}" == 'arm' ]]; then
# Install the ARM APK
"${IRONFOX_ADB}" install -r "${IRONFOX_OUTPUTS_ARM}"
elif [[ "${target}" == 'x86_64' ]]; then
# Install the x86_64 APK
"${IRONFOX_ADB}" install -r "${IRONFOX_OUTPUTS_X86_64}"
fi
# Now that the app is installed, we can kill the server
"${IRONFOX_ADB}" kill-server
else
exit 0
fi
fi