|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (C) 2025 David King <dave@daveking.com> |
| 4 | +# |
| 5 | +# This program is free software; you can redistribute it and/or |
| 6 | +# modify it under the terms of the GNU General Public License, |
| 7 | +# version 2, as published by the Free Software Foundation. |
| 8 | +# |
| 9 | +# This program is distributed in the hope that it will be useful, |
| 10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +# GNU General Public License for more details. |
| 13 | +# |
| 14 | +# You should have received a copy of the GNU General Public License, |
| 15 | +# version 2, along with this program; if not, see |
| 16 | +# <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>. |
| 17 | +################################################################################# |
| 18 | +# |
| 19 | +# This script builds the RPM package for lighterowl's fork of the transgui |
| 20 | +# (Transmission Remote GUI) application - https://github.com/lighterowl/transgui |
| 21 | +# - in a podman container that it creates. |
| 22 | +# |
| 23 | +# The build requires development versions of fpc (the Free Pascal Compiler) and |
| 24 | +# its Lazarus IDE. This script compiles and installs these in the container |
| 25 | +# before building the transgui package. |
| 26 | +# |
| 27 | +# The output of this script ia an installation RPM file for transgui, located |
| 28 | +# in the $RPM_OUTPUT_DIR subdirectory. |
| 29 | +# |
| 30 | +################################################################################# |
| 31 | + |
| 32 | +# This URL points to my github.com fork of lighterowl's fork of transgui, where |
| 33 | +# I have posted a few additional assets that are used to build my transgui package |
| 34 | +FORK_URL="https://raw.githubusercontent.com/dlk3/transgui/refs/heads/copr/build/fedora" |
| 35 | + |
| 36 | +CONTAINER_NAME="transgui-builder" |
| 37 | +BASE_IMAGE="fedora:41" |
| 38 | +RPM_OUTPUT_DIR=${HOME}/rpmbuild |
| 39 | + |
| 40 | +# Terminate script immediately if/when an error occurs |
| 41 | +set -e |
| 42 | + |
| 43 | +# Date/time format for console messages |
| 44 | +DATEFMT="+%Y-%m-%d %H:%M:%S" |
| 45 | + |
| 46 | +# If the "-t" option is passed on the command line, the script will |
| 47 | +# build the podman container and open it to a shell prompt, without |
| 48 | +# doing the transgui build. |
| 49 | +TESTING="no" |
| 50 | +while getopts ":bth" OPT; do |
| 51 | + case "$OPT" in |
| 52 | + t) |
| 53 | + TESTING="YES" |
| 54 | + ;; |
| 55 | + h) |
| 56 | + echo "usage: $0 [-h] [-t]" |
| 57 | + echo |
| 58 | + echo " Where:" |
| 59 | + echo " -h Show this help text" |
| 60 | + echo " -t Start the build container with a bash prompt for testing" |
| 61 | + exit |
| 62 | + ;; |
| 63 | + *) |
| 64 | + echo "usage: $0 [-h] [-t]" |
| 65 | + exit 1 |
| 66 | + esac |
| 67 | +done |
| 68 | +shift $((OPTIND-1)) |
| 69 | + |
| 70 | +# If we are not running inside the podman container, build the container and run the rpmbuild in it |
| 71 | +if [ "$container" != "oci" ]; then |
| 72 | + |
| 73 | + echo "$(date "$DATEFMT"): Building the $CONTAINER_NAME image" |
| 74 | + |
| 75 | + # Create the Dockerfile that will be used to build the container |
| 76 | + cat >/tmp/Dockerfile << __Dockerfile__ |
| 77 | +FROM ${BASE_IMAGE} |
| 78 | +RUN dnf -y upgrade |
| 79 | +RUN dnf -y group install development-tools |
| 80 | +RUN dnf -y install rpmdevtools fpc glibc-devel qt5pas-devel libX11-devel gtk2-devel |
| 81 | +RUN rpmdev-setuptree |
| 82 | +__Dockerfile__ |
| 83 | + |
| 84 | + # Build the container image |
| 85 | + /usr/bin/podman build --tag=$CONTAINER_NAME /tmp |
| 86 | + rm /tmp/Dockerfile |
| 87 | + |
| 88 | + if [ "$TESTING" == "YES" ]; then |
| 89 | + # Start the container with a bash prompt for testing |
| 90 | + /usr/bin/podman run --name=$CONTAINER_NAME -it --rm --env "TARGET_DIR=${RPM_OUTPUT_DIR}" --volume="$HOME":"$HOME" "localhost/$CONTAINER_NAME" /bin/bash |
| 91 | + exit |
| 92 | + else |
| 93 | + # Run this script inside the container to build the transgui RPM files |
| 94 | + echo "$(date "$DATEFMT"): Starting the $CONTAINER_NAME container" |
| 95 | + /usr/bin/podman run --name=$CONTAINER_NAME -it --rm --env "TARGET_DIR=${RPM_OUTPUT_DIR}" --volume="$HOME":"$HOME" "localhost/$CONTAINER_NAME" "$(realpath "$0")" |
| 96 | + echo "$(date "$DATEFMT"): Stopping the $CONTAINER_NAME container" |
| 97 | + fi |
| 98 | + |
| 99 | +# When we are run inside the container, do the build |
| 100 | +else |
| 101 | + # If there are any errors while this script runs in the container, drop us |
| 102 | + # into a shell so that we can poke around before the container is destroyed |
| 103 | + function on_error() |
| 104 | + { |
| 105 | + echo |
| 106 | + echo "There has been an error in the $(basename "$0") script." |
| 107 | + echo "Please use this shell prompt to debug the problem." |
| 108 | + echo "When finished, use Ctrl-D to terminate the shell and remove the container." |
| 109 | + echo |
| 110 | + /bin/sh |
| 111 | + exit 1 |
| 112 | + } |
| 113 | + trap on_error ERR |
| 114 | + |
| 115 | + # Code stolen from https://github.com/lighterowl/transgui-sdk/blob/main/sdk_build.sh |
| 116 | + # to download and install the development versions of the Free Pascal Compiler and |
| 117 | + # Lazarus IDE |
| 118 | + SDK_DIR=${HOME}/.transgui_sdk |
| 119 | + FPC_INSTALLDIR="${SDK_DIR}/fpc-3.2.4-rc1" |
| 120 | + FPC_BASEPATH="${FPC_INSTALLDIR}/lib/fpc/3.2.4" |
| 121 | + LAZ_INSTALLDIR="${SDK_DIR}/lazarus-4.0.0" |
| 122 | + |
| 123 | + mkdir -p ${SDK_DIR} |
| 124 | + cd ${SDK_DIR} |
| 125 | + |
| 126 | + FPC324_RC1_COMMIT='56baf314b5ebf4e5a44fe3e214914fa2e1b34adb' |
| 127 | + curl -L -o fpc-src.tar.bz2 "https://gitlab.com/freepascal.org/fpc/source/-/archive/${FPC324_RC1_COMMIT}/source-${FPC324_RC1_COMMIT}.tar.bz2" |
| 128 | + tar xf fpc-src.tar.bz2 |
| 129 | + mv "source-${FPC324_RC1_COMMIT}" fpc-src |
| 130 | + cd fpc-src |
| 131 | + |
| 132 | + make all |
| 133 | + mkdir -p "${FPC_INSTALLDIR}" |
| 134 | + make PREFIX=$FPC_INSTALLDIR install |
| 135 | + dnf remove -y fpc |
| 136 | + |
| 137 | + export PATH=${FPC_INSTALLDIR}/bin:${FPC_BASEPATH}:$PATH |
| 138 | + fpcmkcfg -d basepath=${FPC_BASEPATH} -o ${HOME}/.fpc.cfg |
| 139 | + echo "fpc version = $(fpc -iW)" |
| 140 | + |
| 141 | + cd "$SDK_DIR" |
| 142 | + LAZARUS_COMMIT='cadda6230398688d6106fe37fb0673a9a2bf0cf3' |
| 143 | + curl -L -o lazarus-src.tar.bz2 "https://gitlab.com/dkk089/lazarus/-/archive/${LAZARUS_COMMIT}/lazarus-${LAZARUS_COMMIT}.tar.bz2" |
| 144 | + tar xf lazarus-src.tar.bz2 |
| 145 | + mv "lazarus-${LAZARUS_COMMIT}" lazarus |
| 146 | + cd lazarus |
| 147 | + make bigide LCL_PLATFORM=qt5 |
| 148 | + mkdir -p "${LAZ_INSTALLDIR}" |
| 149 | + make install INSTALL_PREFIX=$LAZ_INSTALLDIR |
| 150 | + |
| 151 | + export PATH=${LAZ_INSTALLDIR}/lib64/lazarus:${LAZ_INSTALLDIR}/bin:$PATH |
| 152 | + echo "lazbuild version = $(lazbuild -v)" |
| 153 | + |
| 154 | + cd "$SDK_DIR" |
| 155 | + rm *.tar.bz2 |
| 156 | + ## End of code theft |
| 157 | + |
| 158 | + # Create the Lazarus config file |
| 159 | + mkdir /etc/lazarus |
| 160 | + sed "s#__LAZARUSDIR__#${LAZ_INSTALLDIR}/share/lazarus#;s#__FPCSRCDIR__#${FPC_INSTALLDIR}/lib64/fpc/3.2.4#" \ |
| 161 | + ${LAZ_INSTALLDIR}/share/lazarus/tools/install/linux/environmentoptions.xml \ |
| 162 | + > /etc/lazarus/environmentoptions.xml |
| 163 | + |
| 164 | + # Fetch the SPEC file from my fork of lighterowl's transgui repo |
| 165 | + curl -L -o ${HOME}/rpmbuild/SPECS/transgui.spec "${FORK_URL}/transgui.spec" |
| 166 | + |
| 167 | + # Comment out the fpc and lazarus package BuildRequires in the SPEC file |
| 168 | + sed -i 's/\(^BuildRequires:.*fpc.*\)/# \1/' ${HOME}/rpmbuild/SPECS/transgui.spec |
| 169 | + sed -i 's/\(^BuildRequires:.*lazarus.*\)/# \1/' ${HOME}/rpmbuild/SPECS/transgui.spec |
| 170 | + # Make sure the rest of the BuildRequires get installed |
| 171 | + dnf -y install $(awk '/^BuildRequires:/ {printf "%s ",$2}' ${HOME}/rpmbuild/SPECS/transgui.spec) |
| 172 | + |
| 173 | + # Fetch lighterowl's transgui source |
| 174 | + TRANSGUI_VERSION=$(awk '/^Version:/ {print $2}' ${HOME}/rpmbuild/SPECS/transgui.spec) |
| 175 | + mkdir ${HOME}/src |
| 176 | + cd ${HOME}/src |
| 177 | + git clone --depth 1 --branch v${TRANSGUI_VERSION} --recurse-submodules https://github.com/lighterowl/transgui.git transgui-${TRANSGUI_VERSION} |
| 178 | + |
| 179 | + # Fetch the transgui.desktop file and transgui.png icon from my fork of |
| 180 | + # lighterowl's transgui repo |
| 181 | + curl -L -o transgui-${TRANSGUI_VERSION}/transgui.desktop "${FORK_URL}/transgui.desktop" |
| 182 | + curl -L -o transgui-${TRANSGUI_VERSION}/transgui.png "${FORK_URL}/transgui.png" |
| 183 | + |
| 184 | + # Create the source tar.gz |
| 185 | + tar czf ${HOME}/rpmbuild/SOURCES/transgui-${TRANSGUI_VERSION}.tar.gz transgui-${TRANSGUI_VERSION} |
| 186 | + |
| 187 | + # Build the package file |
| 188 | + echo "$(date "$DATEFMT"): Starting rpmbuild" |
| 189 | + rpmbuild -bb ${HOME}/rpmbuild/SPECS/transgui.spec |
| 190 | + echo "$(date "$DATEFMT"): rpmbuild complete" |
| 191 | + |
| 192 | + # Copy the package file to the target directory |
| 193 | + echo "$(date "$DATEFMT"): Copying the RPM to ${TARGET_DIR}" |
| 194 | + mkdir -p ${TARGET_DIR}/RPMS |
| 195 | + cp -rv /root/rpmbuild/RPMS/* ${TARGET_DIR}/RPMS/ |
| 196 | +fi |
0 commit comments