1: #!/usr/bin/env bash
2:
3: #
4: # $Id: fmd-pkg-dpkg,v 1.3 2025/04/07 00:45:52 snw Exp $
5: # Creates a Debian package for a specific FreeM version
6: #
7: #
8: # Author: Serena Willis <snw@coherent-logic.com>
9: # Copyright (C) 2025 Coherent Logic Development LLC
10: #
11: #
12: # This file is part of FreeM.
13: #
14: # FreeM is free software: you can redistribute it and/or modify
15: # it under the terms of the GNU Affero Public License as published by
16: # the Free Software Foundation, either version 3 of the License, or
17: # (at your option) any later version.
18: #
19: # FreeM is distributed in the hope that it will be useful,
20: # but WITHOUT ANY WARRANTY; without even the implied warranty of
21: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22: # GNU Affero Public License for more details.
23: #
24: # You should have received a copy of the GNU Affero Public License
25: # along with FreeM. If not, see <https://www.gnu.org/licenses/>.
26: #
27: # $Log: fmd-pkg-dpkg,v $
28: # Revision 1.3 2025/04/07 00:45:52 snw
29: # Enhance fmd-pkg-dpkg to auto-generate the debian/changelog file from the FreeM ChangeLog
30: #
31: # Revision 1.2 2025/04/06 05:01:21 snw
32: # Initial working implementation of fmd package for dpkg
33: #
34: # Revision 1.1 2025/04/06 03:38:05 snw
35: # Prepare for adding packaging functionality to fmd
36: #
37: #
38: # SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
39: # SPDX-License-Identifier: AGPL-3.0-or-later
40: #
41:
42: PGM=$(basename $0)
43: SCRIPT_DIR=$(dirname "$0")
44:
45: source "${SCRIPT_DIR}/_fmd_common.bash"
46:
47: if [[ $# != 1 ]]
48: then
49: echo "${PGM}: must run from fmd package"
50: exit 1
51: fi
52:
53: FMD=$1
54: FREEM_VERSION="${_fmd_freem_version}"
55: FREEM_VERSION_MOD=$(echo "${FREEM_VERSION}" | sed 's/-/./g')
56: export DEBEMAIL="${_fmd_email}"
57: export DEBFULLNAME="${_fmd_fullname}"
58:
59: echo -n "${PGM}: getting debian package release for ${_fmd_freem_version}... "
60: FDPKG_VERSION=$(_fmd_next_dpkg)
61: echo "[${FDPKG_VERSION}]"
62: echo "${PGM}: package version is ${FREEM_VERSION}-${FDPKG_VERSION}"
63:
64: TMPDIR="/tmp/fmd-pkg-dpkg"
65: rm -rf "${TMPDIR}"
66: mkdir -p "${TMPDIR}"
67:
68: LOGFILE="${TMPDIR}/pkgbuild.log"
69: echo "${PGM}: logging to ${LOGFILE}"
70: INFILE="freem-${FREEM_VERSION}.tar.gz"
71: OUTFILE="${TMPDIR}/freem_${FREEM_VERSION_MOD}.orig.tar.gz"
72: TARDIR="${TMPDIR}/freem-${FREEM_VERSION_MOD}"
73:
74: if [[ -f "${INFILE}" ]]
75: then
76: echo "${PGM}: removing ${INFILE}"
77: rm -f "${INFILE}"
78: fi
79:
80: echo -n "${PGM}: running 'make dist' to prepare source tarball..."
81: make dist &>> "${LOGFILE}"
82: if [[ $? != 0 ]]
83: then
84: echo "[FAIL]"
85: exit 1
86: else
87: echo "[OK]"
88: fi
89:
90: echo "${PGM}: moving ${INFILE} to ${OUTFILE}..."
91: mv "${INFILE}" "${OUTFILE}"
92:
93: echo "${PGM}: extracting ${OUTFILE} to ${TARDIR}..."
94: tar zxf "${OUTFILE}" -C "${TMPDIR}"
95: if [[ "${FREEM_VERSION}" != "${FREEM_VERSION_MOD}" ]]
96: then
97: mv "${TMPDIR}/freem-${FREEM_VERSION}" "${TMPDIR}/freem-${FREEM_VERSION_MOD}"
98: fi
99:
100: echo "${PGM}: generating Debian changelog..."
101: TMP_CHLOG=$(mktemp)
102: ${FMD} changelog --minimal > "${TMP_CHLOG}"
103:
104: pushd scripts &> /dev/null
105: rm debian/changelog
106: dch --create -v "${FREEM_VERSION_MOD}-${FDPKG_VERSION}" -u low --package freem --empty &>> "${LOGFILE}"
107:
108: while read LINE
109: do
110: dch --append "${LINE}" &>> "${LOGFILE}"
111: done < "${TMP_CHLOG}"
112:
113: rm -f "${TMP_CHLOG}"
114:
115: dch --release "Release the package" &>> "${LOGFILE}"
116:
117: popd &> /dev/null
118:
119: echo -n "${PGM}: copying Debian packaging control info to ${TARDIR}... "
120: cp -r scripts/debian "${TARDIR}/"
121: if [[ $? == 0 ]]
122: then
123: echo "[OK]"
124: else
125: echo "[FAIL]"
126: exit 1
127: fi
128:
129: sed -i "s/FREEM_VERSION/${FREEM_VERSION}-${FDPKG_VERSION}/g" "${TARDIR}/debian/control"
130:
131: echo -n "${PGM}: building the packages (this may take awhile)..."
132: cd "${TARDIR}"
133: export DEB_BUILD_MAINT_OPTIONS=hardening=-fortify,-format,-stackprotector,-stackprotectorstrong
134: debuild -us -uc &>> "${LOGFILE}"
135: if [[ $? == 0 ]]
136: then
137: echo "[OK]"
138: else
139: echo "[FAIL]"
140: exit 1
141: fi
142:
143: cd - &> /dev/null
144: mv ${TMPDIR}/*.deb .
145:
146: DPKG_BUILT=$(ls -1 *.deb)
147:
148: BLDLST=""
149: for PKGFILE in ${DPKG_BUILT}
150: do
151: if [[ "${BLDLST}" == "" ]]
152: then
153: BLDLST="${PKGFILE}"
154: else
155: BLDLST="${BLDLST} ${PKGFILE}"
156: fi
157: done
158:
159: echo "${PGM}: built ${BLDLST}"
160:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>