Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Rename shell scripts

Author DaveJarvis <email>
Date 2021-03-31 22:54:30 GMT-0700
Commit feedb85d9784225331cd1333a1196ce936245648
Parent fb0ed95
build-template
-#!/usr/bin/env bash
-
-# -----------------------------------------------------------------------------
-# Copyright 2020 Dave Jarvis
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be included
-# in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-# -----------------------------------------------------------------------------
-
-set -o errexit
-set -o nounset
-
-readonly SCRIPT_SRC="$(dirname "${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}")"
-readonly SCRIPT_DIR="$(cd "${SCRIPT_SRC}" >/dev/null 2>&1 && pwd)"
-readonly SCRIPT_NAME=$(basename "$0")
-
-# -----------------------------------------------------------------------------
-# The main entry point is responsible for parsing command-line arguments,
-# changing to the appropriate directory, and running all commands requested
-# by the user.
-#
-# $@ - Command-line arguments
-# -----------------------------------------------------------------------------
-main() {
- arguments "$@"
-
- $usage && terminate 3
- requirements && terminate 4
- traps && terminate 5
-
- directory && terminate 6
- preprocess && terminate 7
- execute && terminate 8
- postprocess && terminate 9
-
- terminate 0
-}
-
-# -----------------------------------------------------------------------------
-# Perform all commands that the script requires.
-#
-# @return 0 - Indicate to terminate the script with non-zero exit level
-# @return 1 - All tasks completed successfully (default)
-# -----------------------------------------------------------------------------
-execute() {
- return 1
-}
-
-# -----------------------------------------------------------------------------
-# Changes to the script's working directory, provided it exists.
-#
-# @return 0 - Change directory failed
-# @return 1 - Change directory succeeded
-# -----------------------------------------------------------------------------
-directory() {
- $log "Change directory"
- local result=1
-
- # Track whether change directory failed.
- cd "${SCRIPT_DIR}" > /dev/null 2>&1 || result=0
-
- return "${result}"
-}
-
-# -----------------------------------------------------------------------------
-# Perform any initialization required prior to executing tasks.
-#
-# @return 0 - Preprocessing failed
-# @return 1 - Preprocessing succeeded
-# -----------------------------------------------------------------------------
-preprocess() {
- $log "Preprocess"
-
- return 1
-}
-
-# -----------------------------------------------------------------------------
-# Perform any clean up required prior to executing tasks.
-#
-# @return 0 - Postprocessing failed
-# @return 1 - Postprocessing succeeded
-# -----------------------------------------------------------------------------
-postprocess() {
- $log "Postprocess"
-
- return 1
-}
-
-# -----------------------------------------------------------------------------
-# Check that all required commands are available.
-#
-# @return 0 - At least one command is missing
-# @return 1 - All commands are available
-# -----------------------------------------------------------------------------
-requirements() {
- $log "Verify requirements"
- local -r expected_count=${#DEPENDENCIES[@]}
- local total_count=0
-
- # Verify that each command exists.
- for dependency in "${DEPENDENCIES[@]}"; do
- # Extract the command name [0] and URL [1].
- IFS=',' read -ra dependent <<< "${dependency}"
-
- required "${dependent[0]}" "${dependent[1]}"
- total_count=$(( total_count + $? ))
- done
-
- unset IFS
-
- # Total dependencies found must match the expected number.
- # Integer-only division rounds down.
- return $(( total_count / expected_count ))
-}
-
-# -----------------------------------------------------------------------------
-# Called before terminating the script.
-# -----------------------------------------------------------------------------
-cleanup() {
- $log "Cleanup"
-}
-
-# -----------------------------------------------------------------------------
-# Terminates the program immediately.
-# -----------------------------------------------------------------------------
-trap_control_c() {
- $log "Interrupted"
- cleanup
- error "⯃"
- terminate 1
-}
-
-# -----------------------------------------------------------------------------
-# Configure signal traps.
-#
-# @return 1 - Signal traps are set.
-# -----------------------------------------------------------------------------
-traps() {
- # Suppress echoing ^C if pressed.
- stty -echoctl
- trap trap_control_c INT
-
- return 1
-}
-
-# -----------------------------------------------------------------------------
-# Check for a required command.
-#
-# $1 - Command or file to check for existence
-# $2 - Command's website (e.g., download for binaries and source code)
-#
-# @return 0 - Command is missing
-# @return 1 - Command exists
-# -----------------------------------------------------------------------------
-required() {
- local result=0
-
- test -f "$1" || \
- command -v "$1" > /dev/null 2>&1 && result=1 || \
- warning "Missing: $1 ($2)"
-
- return ${result}
-}
-
-# -----------------------------------------------------------------------------
-# Show acceptable command-line arguments.
-#
-# @return 0 - Indicate script may not continue
-# -----------------------------------------------------------------------------
-utile_usage() {
- printf "Usage: %s [OPTIONS...]\n\n" "${SCRIPT_NAME}" >&2
-
- # Number of spaces to pad after the longest long argument.
- local -r PADDING=2
-
- # Determine the longest long argument to adjust spacing.
- local -r LEN=$(printf '%s\n' "${ARGUMENTS[@]}" | \
- awk -F"," '{print length($2)+'${PADDING}'}' | sort -n | tail -1)
-
- local duplicates
-
- for argument in "${ARGUMENTS[@]}"; do
- # Extract the short [0] and long [1] arguments and description [2].
- arg=("$(echo ${argument} | cut -d ',' -f1)" \
- "$(echo ${argument} | cut -d ',' -f2)" \
- "$(echo ${argument} | cut -d ',' -f3-)")
-
- duplicates+=("${arg[0]}")
-
- printf " -%s, --%-${LEN}s%s\n" "${arg[0]}" "${arg[1]}" "${arg[2]}" >&2
- done
-
- # Sort the arguments to make sure no duplicates exist.
- duplicates=$(echo "${duplicates[@]}" | tr ' ' '\n' | sort | uniq -c -d)
-
- # Warn the developer that there's a duplicate command-line option.
- if [ -n "${duplicates}" ]; then
- # Trim all the whitespaces
- duplicates=$(echo "${duplicates}" | xargs echo -n)
- error "Duplicate command-line argument exists: ${duplicates}"
- fi
-
- return 0
-}
-
-# -----------------------------------------------------------------------------
-# Write coloured text to standard output.
-#
-# $1 - Text to write
-# $2 - Text's colour
-# -----------------------------------------------------------------------------
-coloured_text() {
- printf "%b%s%b\n" "$2" "$1" "${COLOUR_OFF}"
-}
-
-# -----------------------------------------------------------------------------
-# Write a warning message to standard output.
-#
-# $1 - Text to write
-# -----------------------------------------------------------------------------
-warning() {
- coloured_text "$1" "${COLOUR_WARNING}"
-}
-
-# -----------------------------------------------------------------------------
-# Write an error message to standard output.
-#
-# $1 - Text to write
-# -----------------------------------------------------------------------------
-error() {
- coloured_text "$1" "${COLOUR_ERROR}"
-}
-
-# -----------------------------------------------------------------------------
-# Write a timestamp and message to standard output.
-#
-# $1 - Text to write
-# -----------------------------------------------------------------------------
-utile_log() {
- printf "[%s] " "$(date +%H:%M:%S.%4N)"
- coloured_text "$1" "${COLOUR_LOGGING}"
-}
-
-# -----------------------------------------------------------------------------
-# Perform no operations.
-#
-# return 1 - Success
-# -----------------------------------------------------------------------------
-noop() {
- return 1
-}
-
-# -----------------------------------------------------------------------------
-# Exit the program with a given exit code.
-#
-# $1 - Exit code
-# -----------------------------------------------------------------------------
-terminate() {
- exit "$1"
-}
-
-# -----------------------------------------------------------------------------
-# Set global variables from command-line arguments.
-# -----------------------------------------------------------------------------
-arguments() {
- while [ "$#" -gt "0" ]; do
- local consume=1
-
- case "$1" in
- -V|--verbose)
- log=utile_log
- ;;
- -h|-\?|--help)
- usage=utile_usage
- ;;
- *)
- set +e
- argument "$@"
- consume=$?
- set -e
- ;;
- esac
-
- shift ${consume}
- done
-}
-
-# -----------------------------------------------------------------------------
-# Parses a single command-line argument. This must return a value greater
-# than or equal to 1, otherwise parsing the command-line arguments will
-# loop indefinitely.
-#
-# @return The number of arguments to consume (1 by default).
-# -----------------------------------------------------------------------------
-argument() {
- return 1
-}
-
-# ANSI colour escape sequences.
-readonly COLOUR_BLUE='\033[1;34m'
-readonly COLOUR_PINK='\033[1;35m'
-readonly COLOUR_DKGRAY='\033[30m'
-readonly COLOUR_DKRED='\033[31m'
-readonly COLOUR_LTRED='\033[1;31m'
-readonly COLOUR_YELLOW='\033[1;33m'
-readonly COLOUR_OFF='\033[0m'
-
-# Colour definitions used by script.
-COLOUR_LOGGING=${COLOUR_BLUE}
-COLOUR_WARNING=${COLOUR_YELLOW}
-COLOUR_ERROR=${COLOUR_LTRED}
-
-# Define required commands to check when script starts.
-DEPENDENCIES=(
- "awk,https://www.gnu.org/software/gawk/manual/gawk.html"
- "cut,https://www.gnu.org/software/coreutils"
-)
-
-# Define help for command-line arguments.
-ARGUMENTS=(
- "V,verbose,Log messages while processing"
- "h,help,Show this help message then exit"
-)
-
-# These functions may be set to utile delegates while parsing arguments.
-usage=noop
-log=noop
-
font-names
-#!/usr/bin/env bash
-
-# Outputs font names for all font files.
-
-find src/main/resources/fonts -type f \( -name "*otf" -o -name "*ttf" \) -exec \
- fc-scan --format "%{foundry}: %{family}\n" {} \; | uniq | sort
-
installer
-#!/usr/bin/env bash
-
-# ---------------------------------------------------------------------------
-# This script cross-compiles application launchers for different platforms.
-#
-# The application binaries are self-contained launchers that do not need
-# to be installed.
-# ---------------------------------------------------------------------------
-
-source $HOME/bin/build-template
-
-readonly APP_NAME=$(find "${SCRIPT_DIR}/src" -type f -name "settings.properties" -exec cat {} \; | grep "application.title=" | cut -d'=' -f2)
-readonly FILE_APP_JAR="${APP_NAME}.jar"
-
-ARG_JAVA_OS="linux"
-ARG_JAVA_ARCH="amd64"
-ARG_JAVA_VERSION="15.0.2"
-ARG_JAVA_UPDATE="10"
-ARG_JAVA_DIR="java"
-
-ARG_DIR_DIST="dist"
-
-FILE_DIST_EXEC="run.sh"
-
-ARG_PATH_DIST_JAR="${SCRIPT_DIR}/build/libs/${FILE_APP_JAR}"
-
-DEPENDENCIES=(
- "gradle,https://gradle.org"
- "warp-packer,https://github.com/dgiagio/warp"
- "tar,https://www.gnu.org/software/tar"
- "unzip,http://infozip.sourceforge.net"
-)
-
-ARGUMENTS+=(
- "a,arch,Target operating system architecture (amd64)"
- "o,os,Target operating system (linux, windows, mac)"
- "u,update,Java update version number (${ARG_JAVA_UPDATE})"
- "v,version,Full Java version (${ARG_JAVA_VERSION})"
-)
-
-ARCHIVE_EXT="tar.gz"
-ARCHIVE_APP="tar xf"
-APP_EXTENSION="bin"
-
-# ---------------------------------------------------------------------------
-# Generates
-# ---------------------------------------------------------------------------
-execute() {
- $do_configure_target
- $do_build
- $do_clean
-
- pushd "${ARG_DIR_DIST}" > /dev/null 2>&1
-
- $do_extract_java
- $do_create_launch_script
- $do_copy_archive
-
- popd > /dev/null 2>&1
-
- $do_create_launcher
-
- return 1
-}
-
-# ---------------------------------------------------------------------------
-# Configure platform-specific commands and file names.
-# ---------------------------------------------------------------------------
-utile_configure_target() {
- if [ "${ARG_JAVA_OS}" = "windows" ]; then
- ARCHIVE_EXT="zip"
- ARCHIVE_APP="unzip -qq"
- FILE_DIST_EXEC="run.bat"
- APP_EXTENSION="exe"
- do_create_launch_script=utile_create_launch_script_windows
- fi
-}
-
-# ---------------------------------------------------------------------------
-# Build platform-specific überjar.
-# ---------------------------------------------------------------------------
-utile_build() {
- $log "Delete ${ARG_PATH_DIST_JAR}"
- rm -f "${ARG_PATH_DIST_JAR}"
-
- $log "Build application for ${ARG_JAVA_OS}"
- gradle clean jar -PtargetOs="${ARG_JAVA_OS}"
-}
-
-# ---------------------------------------------------------------------------
-# Purges the existing distribution directory to recreate the launcher.
-# This refreshes the JRE from the downloaded archive.
-# ---------------------------------------------------------------------------
-utile_clean() {
- $log "Recreate ${ARG_DIR_DIST}"
- rm -rf "${ARG_DIR_DIST}"
- mkdir -p "${ARG_DIR_DIST}"
-}
-
-# ---------------------------------------------------------------------------
-# Extract platform-specific Java Runtime Environment. This will download
-# and cache the required Java Runtime Environment for the target platform.
-# On subsequent runs, the cached version is used, instead of issuing another
-# download.
-# ---------------------------------------------------------------------------
-utile_extract_java() {
- $log "Extract Java"
- local -r java_vm="jre"
- local -r java_version="${ARG_JAVA_VERSION}+${ARG_JAVA_UPDATE}"
- local -r url_java="https://download.bell-sw.com/java/${java_version}/bellsoft-${java_vm}${java_version}-${ARG_JAVA_OS}-${ARG_JAVA_ARCH}-full.${ARCHIVE_EXT}"
-
- local -r file_java="${java_vm}-${java_version}-${ARG_JAVA_OS}-${ARG_JAVA_ARCH}.${ARCHIVE_EXT}"
- local -r path_java="/tmp/${file_java}"
-
- # File must have contents.
- if [ ! -s ${path_java} ]; then
- $log "Download ${url_java} to ${path_java}"
- wget -q "${url_java}" -O "${path_java}"
- fi
-
- $log "Unpack ${path_java}"
- $ARCHIVE_APP "${path_java}"
-
- local -r dir_java="${java_vm}-${ARG_JAVA_VERSION}-full"
-
- $log "Rename ${dir_java} to ${ARG_JAVA_DIR}"
- mv "${dir_java}" "${ARG_JAVA_DIR}"
-}
-
-# ---------------------------------------------------------------------------
-# Create Linux-specific launch script.
-# ---------------------------------------------------------------------------
-utile_create_launch_script_linux() {
- $log "Create Linux launch script"
-
- cat > "${FILE_DIST_EXEC}" << __EOT
-#!/usr/bin/env bash
-
-readonly SCRIPT_SRC="\$(dirname "\${BASH_SOURCE[\${#BASH_SOURCE[@]} - 1]}")"
-
-"\${SCRIPT_SRC}/${ARG_JAVA_DIR}/bin/java" -jar "\${SCRIPT_SRC}/${FILE_APP_JAR}" "\$@" 2>&1 >/dev/null &
-__EOT
-
- chmod +x "${FILE_DIST_EXEC}"
-}
-
-# ---------------------------------------------------------------------------
-# Create Windows-specific launch script.
-# ---------------------------------------------------------------------------
-utile_create_launch_script_windows() {
- $log "Create Windows launch script"
-
- cat > "${FILE_DIST_EXEC}" << __EOT
-@echo off
-
-set SCRIPT_DIR=%~dp0
-"%SCRIPT_DIR%\\${ARG_JAVA_DIR}\\bin\\java" -jar "%SCRIPT_DIR%\\${APP_NAME}.jar" %*
-__EOT
-
- # Convert Unix end of line characters (\n) to Windows format (\r\n).
- # This avoids any potential line conversion issues with the repository.
- sed -i 's/$/\r/' "${FILE_DIST_EXEC}"
-}
-
-# ---------------------------------------------------------------------------
-# Copy application überjar.
-# ---------------------------------------------------------------------------
-utile_copy_archive() {
- $log "Create copy of ${FILE_APP_JAR}"
- cp "${ARG_PATH_DIST_JAR}" "${FILE_APP_JAR}"
-}
-
-# ---------------------------------------------------------------------------
-# Create platform-specific launcher binary.
-# ---------------------------------------------------------------------------
-utile_create_launcher() {
- local -r FILE_APP_NAME="${APP_NAME}.${APP_EXTENSION}"
- $log "Create ${FILE_APP_NAME}"
-
- # Warp-packer does not seem to overwrite the file.
- rm -f "${FILE_APP_NAME}"
-
- # Download uses amd64, but warp-packer differs.
- if [ "${ARG_JAVA_ARCH}" = "amd64" ]; then
- ARG_JAVA_ARCH="x64"
- fi
-
- warp-packer \
- --arch "${ARG_JAVA_OS}-${ARG_JAVA_ARCH}" \
- --input_dir "${ARG_DIR_DIST}" \
- --exec "${FILE_DIST_EXEC}" \
- --output "${FILE_APP_NAME}" > /dev/null
-
- chmod +x "${FILE_APP_NAME}"
-}
-
-argument() {
- local consume=2
-
- case "$1" in
- -a|--arch)
- ARG_JAVA_ARCH="$2"
- ;;
- -o|--os)
- ARG_JAVA_OS="$2"
- ;;
- -u|--update)
- ARG_JAVA_UPDATE="$2"
- ;;
- -v|--version)
- ARG_JAVA_VERSION="$2"
- ;;
- esac
-
- return ${consume}
-}
-
-do_configure_target=utile_configure_target
-do_build=utile_build
-do_clean=utile_clean
-do_extract_java=utile_extract_java
-do_create_launch_script=utile_create_launch_script_linux
-do_copy_archive=utile_copy_archive
-do_create_launcher=utile_create_launcher
-
-main "$@"
-
installer.sh
+#!/usr/bin/env bash
+
+# ---------------------------------------------------------------------------
+# This script cross-compiles application launchers for different platforms.
+#
+# The application binaries are self-contained launchers that do not need
+# to be installed.
+# ---------------------------------------------------------------------------
+
+source $HOME/bin/build-template
+
+readonly APP_NAME=$(find "${SCRIPT_DIR}/src" -type f -name "settings.properties" -exec cat {} \; | grep "application.title=" | cut -d'=' -f2)
+readonly FILE_APP_JAR="${APP_NAME}.jar"
+
+ARG_JAVA_OS="linux"
+ARG_JAVA_ARCH="amd64"
+ARG_JAVA_VERSION="15.0.2"
+ARG_JAVA_UPDATE="10"
+ARG_JAVA_DIR="java"
+
+ARG_DIR_DIST="dist"
+
+FILE_DIST_EXEC="run.sh"
+
+ARG_PATH_DIST_JAR="${SCRIPT_DIR}/build/libs/${FILE_APP_JAR}"
+
+DEPENDENCIES=(
+ "gradle,https://gradle.org"
+ "warp-packer,https://github.com/dgiagio/warp"
+ "tar,https://www.gnu.org/software/tar"
+ "unzip,http://infozip.sourceforge.net"
+)
+
+ARGUMENTS+=(
+ "a,arch,Target operating system architecture (amd64)"
+ "o,os,Target operating system (linux, windows, mac)"
+ "u,update,Java update version number (${ARG_JAVA_UPDATE})"
+ "v,version,Full Java version (${ARG_JAVA_VERSION})"
+)
+
+ARCHIVE_EXT="tar.gz"
+ARCHIVE_APP="tar xf"
+APP_EXTENSION="bin"
+
+# ---------------------------------------------------------------------------
+# Generates
+# ---------------------------------------------------------------------------
+execute() {
+ $do_configure_target
+ $do_build
+ $do_clean
+
+ pushd "${ARG_DIR_DIST}" > /dev/null 2>&1
+
+ $do_extract_java
+ $do_create_launch_script
+ $do_copy_archive
+
+ popd > /dev/null 2>&1
+
+ $do_create_launcher
+
+ return 1
+}
+
+# ---------------------------------------------------------------------------
+# Configure platform-specific commands and file names.
+# ---------------------------------------------------------------------------
+utile_configure_target() {
+ if [ "${ARG_JAVA_OS}" = "windows" ]; then
+ ARCHIVE_EXT="zip"
+ ARCHIVE_APP="unzip -qq"
+ FILE_DIST_EXEC="run.bat"
+ APP_EXTENSION="exe"
+ do_create_launch_script=utile_create_launch_script_windows
+ fi
+}
+
+# ---------------------------------------------------------------------------
+# Build platform-specific überjar.
+# ---------------------------------------------------------------------------
+utile_build() {
+ $log "Delete ${ARG_PATH_DIST_JAR}"
+ rm -f "${ARG_PATH_DIST_JAR}"
+
+ $log "Build application for ${ARG_JAVA_OS}"
+ gradle clean jar -PtargetOs="${ARG_JAVA_OS}"
+}
+
+# ---------------------------------------------------------------------------
+# Purges the existing distribution directory to recreate the launcher.
+# This refreshes the JRE from the downloaded archive.
+# ---------------------------------------------------------------------------
+utile_clean() {
+ $log "Recreate ${ARG_DIR_DIST}"
+ rm -rf "${ARG_DIR_DIST}"
+ mkdir -p "${ARG_DIR_DIST}"
+}
+
+# ---------------------------------------------------------------------------
+# Extract platform-specific Java Runtime Environment. This will download
+# and cache the required Java Runtime Environment for the target platform.
+# On subsequent runs, the cached version is used, instead of issuing another
+# download.
+# ---------------------------------------------------------------------------
+utile_extract_java() {
+ $log "Extract Java"
+ local -r java_vm="jre"
+ local -r java_version="${ARG_JAVA_VERSION}+${ARG_JAVA_UPDATE}"
+ local -r url_java="https://download.bell-sw.com/java/${java_version}/bellsoft-${java_vm}${java_version}-${ARG_JAVA_OS}-${ARG_JAVA_ARCH}-full.${ARCHIVE_EXT}"
+
+ local -r file_java="${java_vm}-${java_version}-${ARG_JAVA_OS}-${ARG_JAVA_ARCH}.${ARCHIVE_EXT}"
+ local -r path_java="/tmp/${file_java}"
+
+ # File must have contents.
+ if [ ! -s ${path_java} ]; then
+ $log "Download ${url_java} to ${path_java}"
+ wget -q "${url_java}" -O "${path_java}"
+ fi
+
+ $log "Unpack ${path_java}"
+ $ARCHIVE_APP "${path_java}"
+
+ local -r dir_java="${java_vm}-${ARG_JAVA_VERSION}-full"
+
+ $log "Rename ${dir_java} to ${ARG_JAVA_DIR}"
+ mv "${dir_java}" "${ARG_JAVA_DIR}"
+}
+
+# ---------------------------------------------------------------------------
+# Create Linux-specific launch script.
+# ---------------------------------------------------------------------------
+utile_create_launch_script_linux() {
+ $log "Create Linux launch script"
+
+ cat > "${FILE_DIST_EXEC}" << __EOT
+#!/usr/bin/env bash
+
+readonly SCRIPT_SRC="\$(dirname "\${BASH_SOURCE[\${#BASH_SOURCE[@]} - 1]}")"
+
+"\${SCRIPT_SRC}/${ARG_JAVA_DIR}/bin/java" -jar "\${SCRIPT_SRC}/${FILE_APP_JAR}" "\$@" 2>&1 >/dev/null &
+__EOT
+
+ chmod +x "${FILE_DIST_EXEC}"
+}
+
+# ---------------------------------------------------------------------------
+# Create Windows-specific launch script.
+# ---------------------------------------------------------------------------
+utile_create_launch_script_windows() {
+ $log "Create Windows launch script"
+
+ cat > "${FILE_DIST_EXEC}" << __EOT
+@echo off
+
+set SCRIPT_DIR=%~dp0
+"%SCRIPT_DIR%\\${ARG_JAVA_DIR}\\bin\\java" -jar "%SCRIPT_DIR%\\${APP_NAME}.jar" %*
+__EOT
+
+ # Convert Unix end of line characters (\n) to Windows format (\r\n).
+ # This avoids any potential line conversion issues with the repository.
+ sed -i 's/$/\r/' "${FILE_DIST_EXEC}"
+}
+
+# ---------------------------------------------------------------------------
+# Copy application überjar.
+# ---------------------------------------------------------------------------
+utile_copy_archive() {
+ $log "Create copy of ${FILE_APP_JAR}"
+ cp "${ARG_PATH_DIST_JAR}" "${FILE_APP_JAR}"
+}
+
+# ---------------------------------------------------------------------------
+# Create platform-specific launcher binary.
+# ---------------------------------------------------------------------------
+utile_create_launcher() {
+ local -r FILE_APP_NAME="${APP_NAME}.${APP_EXTENSION}"
+ $log "Create ${FILE_APP_NAME}"
+
+ # Warp-packer does not seem to overwrite the file.
+ rm -f "${FILE_APP_NAME}"
+
+ # Download uses amd64, but warp-packer differs.
+ if [ "${ARG_JAVA_ARCH}" = "amd64" ]; then
+ ARG_JAVA_ARCH="x64"
+ fi
+
+ warp-packer \
+ --arch "${ARG_JAVA_OS}-${ARG_JAVA_ARCH}" \
+ --input_dir "${ARG_DIR_DIST}" \
+ --exec "${FILE_DIST_EXEC}" \
+ --output "${FILE_APP_NAME}" > /dev/null
+
+ chmod +x "${FILE_APP_NAME}"
+}
+
+argument() {
+ local consume=2
+
+ case "$1" in
+ -a|--arch)
+ ARG_JAVA_ARCH="$2"
+ ;;
+ -o|--os)
+ ARG_JAVA_OS="$2"
+ ;;
+ -u|--update)
+ ARG_JAVA_UPDATE="$2"
+ ;;
+ -v|--version)
+ ARG_JAVA_VERSION="$2"
+ ;;
+ esac
+
+ return ${consume}
+}
+
+do_configure_target=utile_configure_target
+do_build=utile_build
+do_clean=utile_clean
+do_extract_java=utile_extract_java
+do_create_launch_script=utile_create_launch_script_linux
+do_copy_archive=utile_copy_archive
+do_create_launcher=utile_create_launcher
+
+main "$@"
+
release
-#!/usr/bin/env bash
-
-# ---------------------------------------------------------------------------
-# This script builds Windows, Linux, and Java archive binaries for a
-# release.
-# ---------------------------------------------------------------------------
-
-source $HOME/bin/build-template
-
-readonly FILE_PROPERTIES="${SCRIPT_DIR}/src/main/resources/bootstrap.properties"
-readonly BIN_INSTALLER="${SCRIPT_DIR}/installer"
-
-DEPENDENCIES=(
- "gradle,https://gradle.org"
- "${FILE_PROPERTIES},File containing application name"
-)
-
-execute() {
- $log "Build Windows installer binary"
- ${BIN_INSTALLER} -o windows
-
- $log "Build Linux installer binary"
- ${BIN_INSTALLER} -o linux
-
- $log "Build Java archive"
- gradle clean jar
- mv "build/libs/${application_title}.jar" .
-}
-
-preprocess() {
- while IFS='=' read -r key value; do
- if [[ "${key}" = "" || "${key}" = "#"* ]]; then
- continue
- fi
-
- key=$(echo $key | tr '.' '_')
- eval ${key}=\${value}
- done < "${FILE_PROPERTIES}"
-
- application_title="${application_title,,}"
-
- return 1
-}
-
-main "$@"
-
release.sh
+#!/usr/bin/env bash
+
+# ---------------------------------------------------------------------------
+# This script builds Windows, Linux, and Java archive binaries for a
+# release.
+# ---------------------------------------------------------------------------
+
+source $HOME/bin/build-template
+
+readonly FILE_PROPERTIES="${SCRIPT_DIR}/src/main/resources/bootstrap.properties"
+readonly BIN_INSTALLER="${SCRIPT_DIR}/installer.sh"
+
+DEPENDENCIES=(
+ "gradle,https://gradle.org"
+ "${FILE_PROPERTIES},File containing application name"
+)
+
+execute() {
+ $log "Build Windows installer binary"
+ ${BIN_INSTALLER} -o windows
+
+ $log "Build Linux installer binary"
+ ${BIN_INSTALLER} -o linux
+
+ $log "Build Java archive"
+ gradle clean jar
+ mv "build/libs/${application_title}.jar" .
+}
+
+preprocess() {
+ while IFS='=' read -r key value; do
+ if [[ "${key}" = "" || "${key}" = "#"* ]]; then
+ continue
+ fi
+
+ key=$(echo $key | tr '.' '_')
+ eval ${key}=\${value}
+ done < "${FILE_PROPERTIES}"
+
+ application_title="${application_title,,}"
+
+ return 1
+}
+
+main "$@"
+
scripts/bash-template
+#!/usr/bin/env bash
+
+# -----------------------------------------------------------------------------
+# Copyright 2020 Dave Jarvis
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+# -----------------------------------------------------------------------------
+
+set -o errexit
+set -o nounset
+
+readonly SCRIPT_SRC="$(dirname "${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}")"
+readonly SCRIPT_DIR="$(cd "${SCRIPT_SRC}" >/dev/null 2>&1 && pwd)"
+readonly SCRIPT_NAME=$(basename "$0")
+
+# -----------------------------------------------------------------------------
+# The main entry point is responsible for parsing command-line arguments,
+# changing to the appropriate directory, and running all commands requested
+# by the user.
+#
+# $@ - Command-line arguments
+# -----------------------------------------------------------------------------
+main() {
+ arguments "$@"
+
+ $usage && terminate 3
+ requirements && terminate 4
+ traps && terminate 5
+
+ directory && terminate 6
+ preprocess && terminate 7
+ execute && terminate 8
+ postprocess && terminate 9
+
+ terminate 0
+}
+
+# -----------------------------------------------------------------------------
+# Perform all commands that the script requires.
+#
+# @return 0 - Indicate to terminate the script with non-zero exit level
+# @return 1 - All tasks completed successfully (default)
+# -----------------------------------------------------------------------------
+execute() {
+ return 1
+}
+
+# -----------------------------------------------------------------------------
+# Changes to the script's working directory, provided it exists.
+#
+# @return 0 - Change directory failed
+# @return 1 - Change directory succeeded
+# -----------------------------------------------------------------------------
+directory() {
+ $log "Change directory"
+ local result=1
+
+ # Track whether change directory failed.
+ cd "${SCRIPT_DIR}" > /dev/null 2>&1 || result=0
+
+ return "${result}"
+}
+
+# -----------------------------------------------------------------------------
+# Perform any initialization required prior to executing tasks.
+#
+# @return 0 - Preprocessing failed
+# @return 1 - Preprocessing succeeded
+# -----------------------------------------------------------------------------
+preprocess() {
+ $log "Preprocess"
+
+ return 1
+}
+
+# -----------------------------------------------------------------------------
+# Perform any clean up required prior to executing tasks.
+#
+# @return 0 - Postprocessing failed
+# @return 1 - Postprocessing succeeded
+# -----------------------------------------------------------------------------
+postprocess() {
+ $log "Postprocess"
+
+ return 1
+}
+
+# -----------------------------------------------------------------------------
+# Check that all required commands are available.
+#
+# @return 0 - At least one command is missing
+# @return 1 - All commands are available
+# -----------------------------------------------------------------------------
+requirements() {
+ $log "Verify requirements"
+ local -r expected_count=${#DEPENDENCIES[@]}
+ local total_count=0
+
+ # Verify that each command exists.
+ for dependency in "${DEPENDENCIES[@]}"; do
+ # Extract the command name [0] and URL [1].
+ IFS=',' read -ra dependent <<< "${dependency}"
+
+ required "${dependent[0]}" "${dependent[1]}"
+ total_count=$(( total_count + $? ))
+ done
+
+ unset IFS
+
+ # Total dependencies found must match the expected number.
+ # Integer-only division rounds down.
+ return $(( total_count / expected_count ))
+}
+
+# -----------------------------------------------------------------------------
+# Called before terminating the script.
+# -----------------------------------------------------------------------------
+cleanup() {
+ $log "Cleanup"
+}
+
+# -----------------------------------------------------------------------------
+# Terminates the program immediately.
+# -----------------------------------------------------------------------------
+trap_control_c() {
+ $log "Interrupted"
+ cleanup
+ error "⯃"
+ terminate 1
+}
+
+# -----------------------------------------------------------------------------
+# Configure signal traps.
+#
+# @return 1 - Signal traps are set.
+# -----------------------------------------------------------------------------
+traps() {
+ # Suppress echoing ^C if pressed.
+ stty -echoctl
+ trap trap_control_c INT
+
+ return 1
+}
+
+# -----------------------------------------------------------------------------
+# Check for a required command.
+#
+# $1 - Command or file to check for existence
+# $2 - Command's website (e.g., download for binaries and source code)
+#
+# @return 0 - Command is missing
+# @return 1 - Command exists
+# -----------------------------------------------------------------------------
+required() {
+ local result=0
+
+ test -f "$1" || \
+ command -v "$1" > /dev/null 2>&1 && result=1 || \
+ warning "Missing: $1 ($2)"
+
+ return ${result}
+}
+
+# -----------------------------------------------------------------------------
+# Show acceptable command-line arguments.
+#
+# @return 0 - Indicate script may not continue
+# -----------------------------------------------------------------------------
+utile_usage() {
+ printf "Usage: %s [OPTIONS...]\n\n" "${SCRIPT_NAME}" >&2
+
+ # Number of spaces to pad after the longest long argument.
+ local -r PADDING=2
+
+ # Determine the longest long argument to adjust spacing.
+ local -r LEN=$(printf '%s\n' "${ARGUMENTS[@]}" | \
+ awk -F"," '{print length($2)+'${PADDING}'}' | sort -n | tail -1)
+
+ local duplicates
+
+ for argument in "${ARGUMENTS[@]}"; do
+ # Extract the short [0] and long [1] arguments and description [2].
+ arg=("$(echo ${argument} | cut -d ',' -f1)" \
+ "$(echo ${argument} | cut -d ',' -f2)" \
+ "$(echo ${argument} | cut -d ',' -f3-)")
+
+ duplicates+=("${arg[0]}")
+
+ printf " -%s, --%-${LEN}s%s\n" "${arg[0]}" "${arg[1]}" "${arg[2]}" >&2
+ done
+
+ # Sort the arguments to make sure no duplicates exist.
+ duplicates=$(echo "${duplicates[@]}" | tr ' ' '\n' | sort | uniq -c -d)
+
+ # Warn the developer that there's a duplicate command-line option.
+ if [ -n "${duplicates}" ]; then
+ # Trim all the whitespaces
+ duplicates=$(echo "${duplicates}" | xargs echo -n)
+ error "Duplicate command-line argument exists: ${duplicates}"
+ fi
+
+ return 0
+}
+
+# -----------------------------------------------------------------------------
+# Write coloured text to standard output.
+#
+# $1 - Text to write
+# $2 - Text's colour
+# -----------------------------------------------------------------------------
+coloured_text() {
+ printf "%b%s%b\n" "$2" "$1" "${COLOUR_OFF}"
+}
+
+# -----------------------------------------------------------------------------
+# Write a warning message to standard output.
+#
+# $1 - Text to write
+# -----------------------------------------------------------------------------
+warning() {
+ coloured_text "$1" "${COLOUR_WARNING}"
+}
+
+# -----------------------------------------------------------------------------
+# Write an error message to standard output.
+#
+# $1 - Text to write
+# -----------------------------------------------------------------------------
+error() {
+ coloured_text "$1" "${COLOUR_ERROR}"
+}
+
+# -----------------------------------------------------------------------------
+# Write a timestamp and message to standard output.
+#
+# $1 - Text to write
+# -----------------------------------------------------------------------------
+utile_log() {
+ printf "[%s] " "$(date +%H:%M:%S.%4N)"
+ coloured_text "$1" "${COLOUR_LOGGING}"
+}
+
+# -----------------------------------------------------------------------------
+# Perform no operations.
+#
+# return 1 - Success
+# -----------------------------------------------------------------------------
+noop() {
+ return 1
+}
+
+# -----------------------------------------------------------------------------
+# Exit the program with a given exit code.
+#
+# $1 - Exit code
+# -----------------------------------------------------------------------------
+terminate() {
+ exit "$1"
+}
+
+# -----------------------------------------------------------------------------
+# Set global variables from command-line arguments.
+# -----------------------------------------------------------------------------
+arguments() {
+ while [ "$#" -gt "0" ]; do
+ local consume=1
+
+ case "$1" in
+ -V|--verbose)
+ log=utile_log
+ ;;
+ -h|-\?|--help)
+ usage=utile_usage
+ ;;
+ *)
+ set +e
+ argument "$@"
+ consume=$?
+ set -e
+ ;;
+ esac
+
+ shift ${consume}
+ done
+}
+
+# -----------------------------------------------------------------------------
+# Parses a single command-line argument. This must return a value greater
+# than or equal to 1, otherwise parsing the command-line arguments will
+# loop indefinitely.
+#
+# @return The number of arguments to consume (1 by default).
+# -----------------------------------------------------------------------------
+argument() {
+ return 1
+}
+
+# ANSI colour escape sequences.
+readonly COLOUR_BLUE='\033[1;34m'
+readonly COLOUR_PINK='\033[1;35m'
+readonly COLOUR_DKGRAY='\033[30m'
+readonly COLOUR_DKRED='\033[31m'
+readonly COLOUR_LTRED='\033[1;31m'
+readonly COLOUR_YELLOW='\033[1;33m'
+readonly COLOUR_OFF='\033[0m'
+
+# Colour definitions used by script.
+COLOUR_LOGGING=${COLOUR_BLUE}
+COLOUR_WARNING=${COLOUR_YELLOW}
+COLOUR_ERROR=${COLOUR_LTRED}
+
+# Define required commands to check when script starts.
+DEPENDENCIES=(
+ "awk,https://www.gnu.org/software/gawk/manual/gawk.html"
+ "cut,https://www.gnu.org/software/coreutils"
+)
+
+# Define help for command-line arguments.
+ARGUMENTS=(
+ "V,verbose,Log messages while processing"
+ "h,help,Show this help message then exit"
+)
+
+# These functions may be set to utile delegates while parsing arguments.
+usage=noop
+log=noop
+
scripts/font-names.sh
+#!/usr/bin/env bash
+
+# Outputs font names for all font files.
+
+find src/main/resources/fonts -type f \( -name "*otf" -o -name "*ttf" \) -exec \
+ fc-scan --format "%{foundry}: %{family}\n" {} \; | uniq | sort
+
Delta 624 lines added, 624 lines removed